Re: Reducing some DDL Locks to ShareLock - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: Reducing some DDL Locks to ShareLock
Date
Msg-id 1223360485.4747.69.camel@ebony.2ndQuadrant
Whole thread Raw
In response to Re: Reducing some DDL Locks to ShareLock  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Reducing some DDL Locks to ShareLock
Re: Reducing some DDL Locks to ShareLock
List pgsql-hackers
On Mon, 2008-10-06 at 18:57 -0400, Tom Lane wrote:
> Simon Riggs <simon@2ndQuadrant.com> writes:
> > It seems possible to change some DDL commands/subcommands to use a
> > ShareLock rather than an AccessExclusiveLock. Enclosed patch implements
> > this reduction for CREATE TRIGGER, CREATE RULE and ALTER TABLE.
> 
> What happens when two transactions try to do one of these things
> concurrently to the same table?

It should be very similar to CREATE INDEX. If they hold ShareLocks then
their locks do not conflict at relation level.

Updates of their pg_class entry should be handled non-transactionally,
just as they are with CREATE INDEX. This is the reason for the change
from reltriggers being an exact count to being a boolean, i.e. it is
actually now relhastriggers = true | false. Multiple updaters will then
change the value to the same thing.

It was an excellent question because that aspect isn't handled correctly
in the enclosed patch for subcommands, other than index-creating
constraints. 

My main focus is on these commands
* CREATE TRIGGER
* ALTER TABLE ..  ADD PRIMARY KEY
* ALTER TABLE ..  ADD FOREIGN KEY

because those are the most painful ones. We could make it work against
more, but we'd need to rewrite lots and lots of catalog update code.

So I'll make CreateTrigger() use index_update_stats() so we get the
atomic update correct.

-- Simon Riggs           www.2ndQuadrant.comPostgreSQL Training, Services and Support



pgsql-hackers by date:

Previous
From: Greg Smith
Date:
Subject: Re: Shouldn't pg_settings.enumvals be array of text?
Next
From: Heikki Linnakangas
Date:
Subject: Re: Transactions and temp tables