On Mon, Sep 06, 2004 at 04:41:32PM +1000, Koju Iijima wrote:

Hi,

> template1=# BEGIN;
> BEGIN
> template1=# CREATE TABLE FOO ( a int unique);
> NOTICE:  CREATE TABLE / UNIQUE will create implicit index "foo_a_key" for table "foo"
> CREATE TABLE
> template1=# INSERT INTO FOO VALUES ( 0 );
> INSERT 17232 1
> template1=# INSERT INTO FOO VALUES ( 0 );
> ERROR:  duplicate key violates unique constraint "foo_a_key"
> FATAL:  block 1 of 1663/1/17230 is still referenced (private 1, global 1)

The problem is that there's a pin on an index page when the smgr tries
to drop its buffers.  This patch corrects this problem, by having
resowner cleanup before smgr.

It also passes regression tests.  Not sure if it's the correct solution
though, but it seems the natural thing to me.

Thanks for the report.  I wonder how we managed to miss this.

-- 
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Estoy de acuerdo contigo en que la verdad absoluta no existe...
El problema es que la mentira sí existe y tu estás mintiendo" (G. Lama)
Index: src/backend/access/transam/xact.c
===================================================================
RCS file: /home/alvherre/cvs/pgsql-server/src/backend/access/transam/xact.c,v
retrieving revision 1.185
diff -c -r1.185 xact.c
*** src/backend/access/transam/xact.c   30 Aug 2004 19:00:03 -0000      1.185
--- src/backend/access/transam/xact.c   6 Sep 2004 12:57:25 -0000
***************
*** 1481,1494 ****
         * ordering.
         */
  
-       smgrDoPendingDeletes(false);
-       smgrabort();
  
        CallXactCallbacks(XACT_EVENT_ABORT, InvalidTransactionId);
  
        ResourceOwnerRelease(TopTransactionResourceOwner,
                                                 RESOURCE_RELEASE_BEFORE_LOCKS,
                                                 false, true);
        AtEOXact_Inval(false);
        ResourceOwnerRelease(TopTransactionResourceOwner,
                                                 RESOURCE_RELEASE_LOCKS,
--- 1481,1494 ----
         * ordering.
         */
  
  
        CallXactCallbacks(XACT_EVENT_ABORT, InvalidTransactionId);
  
        ResourceOwnerRelease(TopTransactionResourceOwner,
                                                 RESOURCE_RELEASE_BEFORE_LOCKS,
                                                 false, true);
+       smgrDoPendingDeletes(false);
+       smgrabort();
        AtEOXact_Inval(false);
        ResourceOwnerRelease(TopTransactionResourceOwner,
                                                 RESOURCE_RELEASE_LOCKS,
Index: src/test/regress/expected/transactions.out
===================================================================
RCS file: /home/alvherre/cvs/pgsql-server/src/test/regress/expected/transactions.out,v
retrieving revision 1.8
diff -c -r1.8 transactions.out
*** src/test/regress/expected/transactions.out  12 Aug 2004 19:12:21 -0000      1.8
--- src/test/regress/expected/transactions.out  6 Sep 2004 13:08:27 -0000
***************
*** 374,379 ****
--- 374,387 ----
        FETCH 10 FROM c;
  ERROR:  portal "c" cannot be run
  COMMIT;
+ -- make sure dropping an index that's being scanned works
+ BEGIN;
+       CREATE TABLE koju (a INT UNIQUE);
+ NOTICE:  CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table 
"koju"
+       INSERT INTO koju VALUES (1);
+       INSERT INTO koju VALUES (1);
+ ERROR:  duplicate key violates unique constraint "koju_a_key"
+ ROLLBACK;
  DROP TABLE foo;
  DROP TABLE baz;
  DROP TABLE barbaz;
Index: src/test/regress/sql/transactions.sql
===================================================================
RCS file: /home/alvherre/cvs/pgsql-server/src/test/regress/sql/transactions.sql,v
retrieving revision 1.8
diff -c -r1.8 transactions.sql
*** src/test/regress/sql/transactions.sql       12 Aug 2004 19:12:21 -0000      1.8
--- src/test/regress/sql/transactions.sql       6 Sep 2004 13:05:30 -0000
***************
*** 231,236 ****
--- 231,243 ----
        FETCH 10 FROM c;
  COMMIT;
  
+ -- make sure dropping an index that's being scanned works
+ BEGIN;
+       CREATE TABLE koju (a INT UNIQUE);
+       INSERT INTO koju VALUES (1);
+       INSERT INTO koju VALUES (1);
+ ROLLBACK;
+ 
  DROP TABLE foo;
  DROP TABLE baz;
  DROP TABLE barbaz;
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to