Re: BUG #1644: control structeres perfomance in pgsql - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1644: control structeres perfomance in pgsql
Date
Msg-id 13896.1115174909@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #1644: control structeres perfomance in pgsql  (Klint Gore <kg@kgb.une.edu.au>)
List pgsql-bugs
Klint Gore <kg@kgb.une.edu.au> writes:
> On Wed, 04 May 2005 11:52:32 +1000, Neil Conway <neilc@samurai.com> wrote:
>> I don't understand. Can you explain what the problem is?

> I think they mean that it doesn't do short-circuit evaluation.

AFAICS the claimed example cannot exhibit any different behavior whether
it's short-circuit or not.  I have seen some related issues though, like

    IF tg_op = 'UPDATE' AND NEW.foo = 42 THEN ...

In a trigger that is also used for DELETE operations this will fail
--- not because the AND itself isn't short-circuit, but because plpgsql
has to pass down the parameters for the whole IF-expression before the
AND gets to run at all, and so it's forced to evaluate NEW.* which
fails in a DELETE trigger.

We could fix some variants of this problem by modifying plpgsql to
handle top-level AND and OR by itself (ie, split the above into two
separate SQL-expression evaluations with the AND being processed by
plpgsql itself).  However the added overhead of multiple executor
calls would be large, and it still wouldn't fix every such case.
Given that we don't promise AND/OR to always behave in short-circuit
fashion anyway, my reaction to the bug report is basically "tough beans,
this is SQL not C" ...

            regards, tom lane

pgsql-bugs by date:

Previous
From: Klint Gore
Date:
Subject: Re: BUG #1644: control structeres perfomance in pgsql
Next
From: Tom Lane
Date:
Subject: Re: BUG #1643: dbf2pg broken + quick fix