Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-05-30 Thread Andrew - Supernews
On 2005-05-30, Neil Conway <[EMAIL PROTECTED]> wrote: > On Wed, 2005-03-23 at 10:04 -0500, Tom Lane wrote: >> I think last night's discussion makes it crystal-clear why I felt that >> this hasn't been sufficiently thought through. Please revert until the >> discussion comes to a conclusion. > > Ar

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-05-29 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > Are there any remaining objections to reapplying this patch? > The original commit message is here: > http://archives.postgresql.org/pgsql-committers/2005-03/msg00316.php > The archives of the -hackers thread are here: > http://archives.postgresql.org/pgsql

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-05-29 Thread Neil Conway
On Wed, 2005-03-23 at 10:04 -0500, Tom Lane wrote: > I think last night's discussion makes it crystal-clear why I felt that > this hasn't been sufficiently thought through. Please revert until the > discussion comes to a conclusion. Are there any remaining objections to reapplying this patch? Th

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-27 Thread Bruce Momjian
Alvaro Herrera wrote: > On Wed, Mar 23, 2005 at 10:42:01AM +0800, Christopher Kings-Lynne wrote: > > >>If you want to be my friend forever, then fix CLUSTER so that it uses > > >>sharerowexclusive as well :D > > > > > >I don't think it's as easy as that, because you have to move tuples > > >around

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Neil Conway
Tom Lane wrote: I agree that we aren't MVCC with respect to DDL operations (and for this purpose CLUSTER is DDL). Trying to become so would open a can of worms far larger than it's worth, though, IMHO. I think if we can come up with a reasonable way to handle all the consequences, it's worth doin

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Neil Conway
Tom Lane wrote: I think last night's discussion makes it crystal-clear why I felt that this hasn't been sufficiently thought through. Please revert until the discussion comes to a conclusion. I applied the patch because I don't think it is very closely related to the discussion. But if you'd pref

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > Tom Lane wrote: >> It isn't 100% MVCC, I agree. But it works because system catalog >> lookups are SnapshotNow, and so when another session comes and wants to >> look at the table it will see the committed new version of the pg_class >> row pointing at the

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > Tom Lane wrote: >> I don't think this has been adequately thought through at all ... but >> at least make it ExclusiveLock. What is the use-case for allowing >> SELECT FOR UPDATE in parallel with this? > Ok, patch applied -- I adjusted it to use Exclusive

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Greg Stark
Neil Conway <[EMAIL PROTECTED]> writes: > Tom Lane wrote: > > It isn't 100% MVCC, I agree. But it works because system catalog > > lookups are SnapshotNow, and so when another session comes and wants to > > look at the table it will see the committed new version of the pg_class > > row pointing a

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-23 Thread Zeugswetter Andreas DAZ SD
> > It would keep the old table around while building the new, then grab > > an exclusive lock to swap the two. > > Lock upgrading is right out. It would need a whole of new family of "intent" locks, with different rules. Andreas ---(end of broadcast)

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Tom Lane wrote: I don't think this has been adequately thought through at all ... but at least make it ExclusiveLock. What is the use-case for allowing SELECT FOR UPDATE in parallel with this? Ok, patch applied -- I adjusted it to use ExclusiveLock, and fleshed out some of the comments. -Neil In

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Tom Lane wrote: This is presuming that we abandon the notion that system catalog access use SnapshotNow. Which opens the question of what they should use instead ... to which "transaction snapshot" isn't the answer, because we have to be able to do system catalog accesses before we've set the snap

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Tom Lane wrote: It isn't 100% MVCC, I agree. But it works because system catalog lookups are SnapshotNow, and so when another session comes and wants to look at the table it will see the committed new version of the pg_class row pointing at the new relfilenode file. If by "works", you mean "provid

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > - if we make these changes, we will need some way to delete a > no-longer-visible relfilenode. This is presuming that we abandon the notion that system catalog access use SnapshotNow. Which opens the question of what they should use instead ... to which

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > How can we drop the file at commit, given that a serializable > transaction's snapshot should still be able to see old relfilenode's > content? It isn't 100% MVCC, I agree. But it works because system catalog lookups are SnapshotNow, and so when another

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Bruce Momjian
Neil Conway wrote: > Tom Lane wrote: > > Utterly wrong. When you commit you will physically drop the old table. > > If there is a SELECT running against the old table it will be quite > > unhappy after that. > > How can we drop the file at commit, given that a serializable > transaction's snapsh

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Tom Lane wrote: Utterly wrong. When you commit you will physically drop the old table. If there is a SELECT running against the old table it will be quite unhappy after that. How can we drop the file at commit, given that a serializable transaction's snapshot should still be able to see old relfi

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > Well, we will be holding an ExclusiveLock on the heap relation > regardless. We "replace" the heap table by swapping its relfilenode, so > ISTM we needn't hold an AccessExclusiveLock. Utterly wrong. When you commit you will physically drop the old table

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Neil Conway wrote: ... except that when we rebuild the relation's indexes, we acquire an AccessExclusiveLock on the index. This would introduce the risk of deadlock. It seems necessary to acquire an AccessExclusiveLock when rebuilding shared indexes, since we do the index build in-place, but I

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Christopher Kings-Lynne <[EMAIL PROTECTED]> writes: > It would keep the old table around while building the new, then grab > an exclusive lock to swap the two. Lock upgrading is right out. regards, tom lane ---(end of broadcast)-

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: > /* > ! * Grab an exclusive lock on the pk table, so that someone doesn't > ! * delete rows out from under us. (Although a lesser lock would do for > ! * that purpose, we'll need exclusive lock anyway to add triggers to > ! * the

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Tom Lane
Neil Conway <[EMAIL PROTECTED]> writes: >> AndrewSN pointed out on IRC that ALTER TABLE ... ADD FOREIGN KEY and >> CREATE TRIGGER both acquire AccessExclusiveLocks on the table they are >> adding triggers to (the PK table, in the case of ALTER TABLE). Is this >> necessary? I don't see why we can

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Bruce Momjian wrote: Certainly we need to upgrade to an exclusive table lock to replace the heap table. Well, we will be holding an ExclusiveLock on the heap relation regardless. We "replace" the heap table by swapping its relfilenode, so ISTM we needn't hold an AccessExclusiveLock. Do we want t

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Bruce Momjian
Neil Conway wrote: > So I think it should be possible to lock both the heap relation and the > index with ExclusiveLock, which would allow SELECTs on them. This would > apply to both the single relation and multiple relation variants of > CLUSTER (since we do each individual clustering in its ow

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Christopher Kings-Lynne
Huh, cluster already does that. It does and it doesn't. Something like the first thing it does is muck with the old table's filenode IIRC, meaning that immediately the old table will no longer work. Chris ---(end of broadcast)--- TIP 8: explain an

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Christopher Kings-Lynne wrote: If you want to be my friend forever, then fix CLUSTER so that it uses sharerowexclusive as well :D Hmm, this might be possible as well. During a CLUSTER, we currently - lock the heap relation with AccessExclusiveLock - lock the index we're clustering on with AccessEx

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Alvaro Herrera
On Wed, Mar 23, 2005 at 10:42:01AM +0800, Christopher Kings-Lynne wrote: > >>If you want to be my friend forever, then fix CLUSTER so that it uses > >>sharerowexclusive as well :D > > > >I don't think it's as easy as that, because you have to move tuples > >around in the cluster operation. Same s

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Christopher Kings-Lynne
If you want to be my friend forever, then fix CLUSTER so that it uses sharerowexclusive as well :D I don't think it's as easy as that, because you have to move tuples around in the cluster operation. Same sort of issue as vacuum full I would suggest. Cluster doesn't move rows... I didn't say it

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Russell Smith
On Wed, 23 Mar 2005 12:40 pm, Christopher Kings-Lynne wrote: > If you want to be my friend forever, then fix CLUSTER so that it uses > sharerowexclusive as well :D > I don't think it's as easy as that, because you have to move tuples around in the cluster operation. Same sort of issue as vacuum

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Christopher Kings-Lynne
If you want to be my friend forever, then fix CLUSTER so that it uses sharerowexclusive as well :D Chris Neil Conway wrote: Neil Conway wrote: AndrewSN pointed out on IRC that ALTER TABLE ... ADD FOREIGN KEY and CREATE TRIGGER both acquire AccessExclusiveLocks on the table they are adding trigg

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-22 Thread Neil Conway
Neil Conway wrote: AndrewSN pointed out on IRC that ALTER TABLE ... ADD FOREIGN KEY and CREATE TRIGGER both acquire AccessExclusiveLocks on the table they are adding triggers to (the PK table, in the case of ALTER TABLE). Is this necessary? I don't see why we can't allow SELECT queries on the ta

Re: [HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-21 Thread Neil Conway
Neil Conway wrote: AndrewSN pointed out on IRC that ALTER TABLE ... ADD FOREIGN KEY and CREATE TRIGGER both acquire AccessExclusiveLocks on the table they are adding triggers to (the PK table, in the case of ALTER TABLE). Is this necessary? I don't see why we can't allow SELECT queries on the ta

[HACKERS] locks in CREATE TRIGGER, ADD FK

2005-03-21 Thread Neil Conway
AndrewSN pointed out on IRC that ALTER TABLE ... ADD FOREIGN KEY and CREATE TRIGGER both acquire AccessExclusiveLocks on the table they are adding triggers to (the PK table, in the case of ALTER TABLE). Is this necessary? I don't see why we can't allow SELECT queries on the table to proceed whi