Skip site navigation (1) Skip section navigation (2)

Re: Bug #510: conditional rules sometimes work more than once

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kovacsz(at)pc10(dot)radnoti-szeged(dot)sulinet(dot)hu, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #510: conditional rules sometimes work more than once
Date: 2001-11-06 19:38:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
pgsql-bugs(at)postgresql(dot)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

In response to

pgsql-bugs by date

Next:From: Kovacs ZoltanDate: 2001-11-06 21:35:17
Subject: Re: Bug #510: conditional rules sometimes work more than
Previous:From: pgsql-bugsDate: 2001-11-06 14:18:17
Subject: Bug #510: conditional rules sometimes work more than once

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group