Re: Bug #510: conditional rules sometimes work more than once - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Bug #510: conditional rules sometimes work more than once
Date
Msg-id 17399.1005075535@sss.pgh.pa.us
Whole thread Raw
In response to Bug #510: conditional rules sometimes work more than once  (pgsql-bugs@postgresql.org)
List pgsql-bugs
pgsql-bugs@postgresql.org writes:
> Using 7.1.3, I've got a problem with conditional rules. This is the
> same problem which occured also in 7.1.1, but it seems to be
> indeterministic (sometimes works, sometimes not).

> My definitions are attached in defs.pgsql. It requires t1.out and
> t2.out (contents of two tables written out with COPY statements). I
> tried to load defs.pgsql into a clean database and the conditional
> rule worked well. But in my production database the same UPDATE causes
> a strange thing: the RULE calls the function as many times as many
> rows the view contains.

Well, yes.  The WHERE clause has to be tested at every row to see
whether it is true or not, doesn't it?  Seems like you are expecting
the system to magically know the result of the function without having
called it.

Probably a more useful answer is this: there isn't any guarantee about
the order in which functions in a query's WHERE-clause will be executed.
I suspect you are assuming that
    WHERE not szalllev_szamla_szamla_kapcs(new.szamla,new.tetelszam)
will be executed only after the constraints in your UPDATE'S WHERE
clause, but the planner just sees them all as a big heap of constraints,
and executes them in whatever order it thinks will be efficient.
If you are building a design in which such functions might have
side-effects, then you'd better reconsider your design.

            regards, tom lane

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #510: conditional rules sometimes work more than once
Next
From: Kovacs Zoltan
Date:
Subject: Re: Bug #510: conditional rules sometimes work more than