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

Re: ALTER TABLE ... NOREWRITE option

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER TABLE ... NOREWRITE option
Date: 2012-12-07 16:41:03
Message-ID: CA+TgmoYOGgGORejBteDccbwuhFBZm3Q_JQDQEcRK_ZqhPPH7mg@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Thu, Dec 6, 2012 at 3:34 PM, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr> wrote:
> I think we need to be solving that problem when we implement new firing
> points for event trigger. The 'table_rewrite' event needs to fire at a
> time when the code can cope with it. That's the main difficulty in
> adding events in that system, asserting their code location safety.

Agreed.

> They need to fire before catalogs are modified, or after, not in
> between, I agree with that. I don't see other ways of implementing that
> than carefully placing the call to user code in the backend's code.

Also agreed.

> The log insert needs to happen either before or after the rewrite, in
> terms of catalog state. I don't see any magic bullet here.

And again agreed.

I think in this case we need to work out before actually doing
anything whether a rewrite will occur, and then remember that
decision.  If the decision is yes, then we call the trigger.  After
calling the trigger, we need to revalidate that it hasn't invalidated
any critical assumptions upon which we're relying for the sanity of
the system (e.g. the table hasn't been altered or dropped).  Assuming
all is well, we then proceed to do the actual operation, basing the
decision as to whether or not to rewrite on the remembered state.

I think ALTER TABLE actually has a lot of this machinery already in
the form of a distinction between "prep" and "exec".  However, there
are some cases where the prep work has been folded into the execute
phase (or maybe visca versa).  So there may be some code cleanup that
is needed there, or we may need to move some things from the exec
phase to the prep phase to make it all work out.  I think it's totally
doable, but it's not going to be a 50-line patch.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2012-12-07 16:46:51
Subject: Re: pg_upgrade problem with invalid indexes
Previous:From: Simon RiggsDate: 2012-12-07 16:16:14
Subject: Re: Commits 8de72b and 5457a1 (COPY FREEZE)

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