Re: Update on tables when the row doesn't change

From: Sebastian Böck <sebastianboeck(at)freenet(dot)de>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jaime Casanova <systemguards(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Update on tables when the row doesn't change
Date: 2005-05-25 09:35:40
Message-ID: 429446EC.9020704@freenet.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout wrote:
> Well, I havn't run the rule so I don't know exactly whether it is
> relevent, but simply put, RULEs are like *macro substitution*. In
> macros, if you specify an expression (like a view) as an argument, it
> is placed as a whole each place the argument is used.

Yes I understood it the same way.
That makes absolutly sense in situations where you have different
rules on the same target (view or table).

> UPDATEs for different tables cannot be merged into a single query so
> you get four queries and it's not clear how you could avoid any work.
>
> I guess each subquery may be optimised individually, though I don't
> know if it really helps. Perhaps you could show us the resulting query
> plans and how you think they could be improved.

There are a lot of geometric operations involved (all done via
postgis) that make the view slow. I don't want to change the view
itself now, only want to get rid of all the unnecessary evaluations of
the view.

So I tried to collapse the rules into on rule as shown in the example
below:

> On Wed, May 25, 2005 at 10:40:38AM +0200, Sebastian Böck wrote:
>
>>CREATE OR REPLACE RULE upd AS ON UPDATE TO view_test
>> DO INSTEAD (
>> UPDATE test SET test = NEW.test WHERE id = OLD.id;
>> UPDATE join1 SET text1 = NEW.text1 WHERE id = OLD.id;
>> UPDATE join2 SET text2 = NEW.text2 WHERE id = OLD.id;
>> UPDATE join3 SET text3 = NEW.text3 WHERE id = OLD.id;
>> );

I hoped that the view gets only evaluated once, because it is only one
rule, but thats not true :(

Thanks for all so far, I'll come back when tuning the obove mentioned
queries.

Sebastian

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dawid Kuroczko 2005-05-25 10:37:57 Re: Update on tables when the row doesn't change
Previous Message Dweck Nir 2005-05-25 09:19:48 Re: postmaster fails to start