Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V0FWW-0005ij-Lo for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Jul 2013 18:35:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V0FWW-0003Bb-0r for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Jul 2013 18:35:24 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V0FWV-0003BU-0d for pgsql-bugs@postgresql.org; Fri, 19 Jul 2013 18:35:23 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V0FWQ-0000nU-Ua for pgsql-bugs@postgresql.org; Fri, 19 Jul 2013 18:35:22 +0000 Received: from intern.anarazel.de (p5DDC417D.dip0.t-ipconnect.de [93.220.65.125]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 5A90A4F0001; Fri, 19 Jul 2013 20:35:17 +0200 (CEST) Date: Fri, 19 Jul 2013 20:35:16 +0200 From: Andres Freund To: Alvaro Herrera Cc: levertond@googlemail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #8273: Assertion failure in 9.3 beta2 with serializable and savepoints Message-ID: <20130719183516.GA13075@alap2.anarazel.de> References: <20130719174644.GE4130@eldon.alvh.no-ip.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20130719174644.GE4130@eldon.alvh.no-ip.org> X-Pg-Spam-Score: -0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2013-07-19 13:46:44 -0400, Alvaro Herrera wrote: > levertond@googlemail.com wrote: > > > START TRANSACTION ISOLATION LEVEL SERIALIZABLE; > > CREATE TABLE testing( > >   x INTEGER PRIMARY KEY > > ); > > INSERT INTO testing VALUES(1); > > SELECT * FROM testing WHERE x = 1 FOR UPDATE; > > SAVEPOINT test; > > UPDATE testing SET x = 2 WHERE x = 1; > > ROLLBACK TO test; > > UPDATE testing SET x = 3 WHERE x = 1; > > ROLLBACK; > > Thanks for the test case. This one-liner patch fixes it: > > diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c > index 55563ea..fa9c9d7 100644 > --- a/src/backend/utils/time/tqual.c > +++ b/src/backend/utils/time/tqual.c > @@ -1287,7 +1287,7 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin, > { > if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */ > return HEAPTUPLE_INSERT_IN_PROGRESS; > - if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) > + if (HeapTupleHeaderIsOnlyLocked(tuple)) > return HEAPTUPLE_INSERT_IN_PROGRESS; > /* inserted and then deleted by same xact */ > return HEAPTUPLE_DELETE_IN_PROGRESS; > > > That is, I was taking a shortcut here by checking only the infomask bits > about locking, and not resolving the MultiXact to see if the updater > (sub)transaction was aborted; but this was wrong, because a tuple which > was created here and updated by an aborted subxact needs to be seen as > in-progress insertion, not an in-progress delete. This causes trouble > to the predicate.c code because it tries to obtain the update XID for > the tuple, but since the update has aborted, that returned zero, causing > the assert failure. > Sadly, this has performance implications, because what previously was > just an in-place check of bit flags has now become a function call. Well, the impact imo primarily comes from actually resolving the multixact, not from the function call itself... But I don't think we need to overly worried. That path is only entered if xmin is in-progress, so that shouldn't have too big implications. If you're worried you could do a SetHintBits(HEAP_XMAX_INVALID) like it's done if xmin isn't in progress like it's done when xmin has committed. > Perhaps it'd be smart to optimize it a bit so that we first check the > flags, and only call the function if that fails. Sounds like a good idea to me. The duplicated amount of work by that should by fairly minimal. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs