Unix Technical Forum

Table rewrites vs. pending AFTER triggers

This is a discussion on Table rewrites vs. pending AFTER triggers within the pgsql Hackers forums, part of the PostgreSQL category; --> Some thought about bug #3847 led me to the following test case: create table t1(f1 int); create or replace ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:39 PM
Tom Lane
 
Posts: n/a
Default Table rewrites vs. pending AFTER triggers

Some thought about bug #3847 led me to the following test case:

create table t1(f1 int);

create or replace function t1trig() returns trigger as $$
begin
raise notice 'f1 = %', new.f1;
return new;
end$$ language plpgsql;

create constraint trigger t1t after insert on t1
initially deferred for each row
execute procedure t1trig();

insert into t1 values('42');
insert into t1 values('43');
delete from t1;

begin;
insert into t1 values('44');
alter table t1 alter column f1 type text;
commit;

which fails at the COMMIT with
ERROR: failed to fetch new tuple for AFTER trigger

the reason being of course that the ALTER has rewritten the table and
put the f1=44 tuple at a different TID than what is recorded in the
pending-trigger-events list.

I don't think that this is exactly the problem that the bug reporter
is complaining of, since he wasn't using a DEFERRED trigger, but it
seems like a real hazard anyway.

We have already noted a related problem with respect to TRUNCATE,
and fixed it by forbidding TRUNCATE when there are any pending
trigger events on the target relation. (We only need to consider
local pending events, since locking will prevent this type of
problem between two different backends.)

I think that we need to put in a similar restriction for CLUSTER and
at least the table-rewriting forms of ALTER TABLE. Paranoia would
suggest forbidding *any* form of ALTER TABLE when there are pending
trigger events, but maybe that's unnecessarily strong.

Comments?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:39 PM
Simon Riggs
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

On Tue, 2008-01-01 at 16:09 -0500, Tom Lane wrote:

> Paranoia would
> suggest forbidding *any* form of ALTER TABLE when there are pending
> trigger events, but maybe that's unnecessarily strong.


That works for me. Such a combination makes no sense, so banning it is
the right thing to do.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:39 PM
Andrew Dunstan
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers



Simon Riggs wrote:
> On Tue, 2008-01-01 at 16:09 -0500, Tom Lane wrote:
>
>
>> Paranoia would
>> suggest forbidding *any* form of ALTER TABLE when there are pending
>> trigger events, but maybe that's unnecessarily strong.
>>

>
> That works for me. Such a combination makes no sense, so banning it is
> the right thing to do.
>
>


+1. Doesn't make much sense to me either.

cheers

andrew

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 10:39 PM
Gokulakannan Somasundaram
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

Is there why we allow DDLs inside a transaction and allow it to be rolled
back? If we commit the previous transaction, as soon as we encounter a DDL,
and commit the DDL too (without waiting for commit) will it be affecting
some use cases?

I actually mean to say that DDLs can be declared as self-committing. That
would get rid of these exceptions.

Am i missing something?

Thanks,
Gokul.

On Jan 3, 2008 12:02 AM, Andrew Dunstan <adunstan@postgresql.org> wrote:

>
>
> Simon Riggs wrote:
> > On Tue, 2008-01-01 at 16:09 -0500, Tom Lane wrote:
> >
> >
> >> Paranoia would
> >> suggest forbidding *any* form of ALTER TABLE when there are pending
> >> trigger events, but maybe that's unnecessarily strong.
> >>

> >
> > That works for me. Such a combination makes no sense, so banning it is
> > the right thing to do.
> >
> >

>
> +1. Doesn't make much sense to me either.
>
> cheers
>
> andrew
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 10:39 PM
Tom Lane
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

"Gokulakannan Somasundaram" <gokul007@gmail.com> writes:
> I actually mean to say that DDLs can be declared as self-committing.


Egad, an Oracle lover in our midst.

Most of us think that roll-back-able DDL is one of the best features of
Postgres, and certainly one of our best selling points vis-a-vis Oracle.
Don't expect us to give it up.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-15-2008, 10:39 PM
David Fetter
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

On Thu, Jan 03, 2008 at 01:08:47PM +0530, Gokulakannan Somasundaram wrote:
> On Jan 3, 2008 12:44 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > "Gokulakannan Somasundaram" <gokul007@gmail.com> writes:
> > > I actually mean to say that DDLs can be declared as
> > > self-committing.

> >
> > Egad, an Oracle lover in our midst.

>
> . True, its an impact of working more with Oracle. I made the
> suggestion here, because it might reduce some if conditions.
>
> > Most of us think that roll-back-able DDL is one of the best
> > features of Postgres, and certainly one of our best selling points
> > vis-a-vis Oracle. Don't expect us to give it up.

>
> Can you please explain, any specific use-case where DDLs are
> necessary within a transaction?


Let's imagine that you want to do a DDL change to a production
database. You've tested the change script on a test database, but you
want to be sure you get *exactly* from the place you were to the place
you want to be. With transactional DDL, you know absolutely for sure
that you've done either the whole change or none of it, i.e. not
half-way in between

Cheers,
David (a giant fan of transactional DDL)
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-15-2008, 10:39 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

On Thu, Jan 03, 2008 at 01:08:47PM +0530, Gokulakannan Somasundaram wrote:
> Can you please explain, any specific use-case where DDLs are necessary
> within a transaction?


I don't think they are ever necessary, they're just very very nice. For
example:

- You want a new column to appear populated on a table atomically. You
do a BEGIN; add column; update set column=foo; add foreign key; COMMIT
- Installation of external modules can be done atomically, so you don't
end up with half installed contrib modules.
- Principle of Least Surprise. Automatic commit for any reason seems
wrong.
- Temporarily disabling triggers/indexes/constraints, if the system
aborts/crashes, the triggers are reinstated automatically.
- Just general niceity of being able to test schema changes without
immediatly changing the system.

There are many more...

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHfLejIB7bNG8LQkwRAkDGAJ4ty2qu6EGbvTdF1ePyty ffXoMOgQCfXGBG
DAC7qb/pzQrf5fEyIkwvjvY=
=2O+I
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-15-2008, 10:39 PM
Gokulakannan Somasundaram
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

On Jan 3, 2008 3:53 PM, Martijn van Oosterhout <kleptog@svana.org> wrote:

> On Thu, Jan 03, 2008 at 01:08:47PM +0530, Gokulakannan Somasundaram wrote:
> > Can you please explain, any specific use-case where DDLs are necessary
> > within a transaction?

>
> I don't think they are ever necessary, they're just very very nice. For
> example:
>
> - You want a new column to appear populated on a table atomically. You
> do a BEGIN; add column; update set column=foo; add foreign key; COMMIT
> - Installation of external modules can be done atomically, so you don't
> end up with half installed contrib modules.
> - Principle of Least Surprise. Automatic commit for any reason seems
> wrong.
> - Temporarily disabling triggers/indexes/constraints, if the system
> aborts/crashes, the triggers are reinstated automatically.
> - Just general niceity of being able to test schema changes without
> immediatly changing the system.
>
> There are many more...


Thanks.. it looks like a good feature...

Gokul.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-15-2008, 10:39 PM
Albe Laurenz
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

Gokulakannan Somasundaram wrote:
> Can you please explain, any specific use-case where DDLs are
> necessary within a transaction?


SQL-Scripts that create database objects and should either
succeed or have no effect.

Yours,
Laurenz Albe

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-15-2008, 10:39 PM
Alvaro Herrera
 
Posts: n/a
Default Re: Table rewrites vs. pending AFTER triggers

Simon Riggs wrote:
> On Tue, 2008-01-01 at 16:09 -0500, Tom Lane wrote:
>
> > Paranoia would
> > suggest forbidding *any* form of ALTER TABLE when there are pending
> > trigger events, but maybe that's unnecessarily strong.

>
> That works for me. Such a combination makes no sense, so banning it is
> the right thing to do.


I disagree. This is an implementation limitation, so it makes sense to
try to restrict the user as least as possible.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com