bug w/ cursors and savepoints - Mailing list pgsql-hackers

From Neil Conway
Subject bug w/ cursors and savepoints
Date
Msg-id 1106625290.1780.101.camel@localhost.localdomain
Whole thread Raw
Responses Re: bug w/ cursors and savepoints
List pgsql-hackers
Someone at Fujitsu pointed out the following bug in 8.0:

begin;
savepoint x;
create table abc (a int);
insert into abc values (5);
declare foo cursor for select * from abc;
rollback to x;
fetch from foo; -- hits an Assert()
commit;

The stacktrace is:

#2  0x0826367b in ExceptionalCondition (conditionName=0x8316544
"!(((bool)((relation)->rd_refcnt == 0)))",   errorType=0x8316004 "FailedAssertion", fileName=0x8315f08
"/home/neilc/pgsql/src/backend/utils/cache/relcache.c", lineNumber=2118)   at
/home/neilc/pgsql/src/backend/utils/error/assert.c:51
#3  0x0825cec0 in AtEOSubXact_RelationCache (isCommit=0 '\0', mySubid=2,
parentSubid=1)   at /home/neilc/pgsql/src/backend/utils/cache/relcache.c:2118
#4  0x080ade30 in AbortSubTransaction ()
at /home/neilc/pgsql/src/backend/access/transam/xact.c:3407
#5  0x080ac404 in CommitTransactionCommand ()
at /home/neilc/pgsql/src/backend/access/transam/xact.c:1982
#6  0x081de4ba in finish_xact_command ()
at /home/neilc/pgsql/src/backend/tcop/postgres.c:1843
#7  0x081dd102 in exec_simple_query (query_string=0x83b6ad4 "rollback to
x;") at /home/neilc/pgsql/src/backend/tcop/postgres.c:950

So what's happening is that the cursor still holds a reference to the
newly-created table, so we can't just blow it away. I don't know the
subtransaction code too well, so I'm not sure of the right fix.
Comments?

-Neil




pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Shortcut for defining triggers
Next
From: "Jim C. Nasby"
Date:
Subject: Re: userlock changes for 8.1/8.2