pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: tillmann73@yahoo.de, pgsql-bugs@lists.postgresql.org, PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: BUG #15448: server process (PID 22656) was terminated by exception 0xC0000005
Date: Tue, 23 Oct 2018 07:46:01 -0400
Message-ID: <ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com> (raw)
In-Reply-To: <9cb4aa1c-12ba-59c3-fd75-545fa90fb92f@lab.ntt.co.jp>
References: <15448-068ca37e168742d6@postgresql.org>
	<9cb4aa1c-12ba-59c3-fd75-545fa90fb92f@lab.ntt.co.jp>



On 10/22/2018 10:00 PM, Amit Langote wrote:
>
> After observing the test case in the provided log, I managed to reproduce
> it with the following:
>
> create table foo (a int primary key, b int);
> create table bar (a int references foo on delete cascade, b int);
> insert into foo values (1, 1);
> insert into foo values (2, 2);
> alter table foo add c int;
> alter table foo drop c;
> delete from foo;
> server closed the connection unexpectedly
> 	This probably means the server terminated abnormally
> 	before or while processing the request.
> The connection to the server was lost. Attempting reset: Failed.
>
> Analyzing this crash, I located the bug down to GetTupleForTrigger(), but
> perhaps it's really in heap_expand_tuple() / expand_tuple(), where the
> value of trigger tuple's t_self is being switched from a valid one to an
> invalid value.
>
> In heaptuple.c: expand_tuple()
>
>
>          ItemPointerSetInvalid(&((*targetHeapTuple)->t_self));
>
>
> FWIW, attached patch fixes this for me.  Adding Andrew whose recent commit
> 7636e5c60f [1] seems to have introduced the heap_expan_tuple call in
> GetTupleForTrigger.  Maybe, he can better judge a fix for this.
>



Thanks. I think the line in expand_tuple is a thinko and we should 
change it, rather than change GetTupleForTrigger().

Here is a patch that does that and also adds your test case to the 
regression tests.

cheers

andrew

-- 
Andrew Dunstan                https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

fast_default_expand_tuple_fix.patch (text/x-patch, 2.2K) download diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 15444cf..28127b3 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -856,7 +856,7 @@ expand_tuple(HeapTuple *targetHeapTuple, = (HeapTupleHeader) ((char *) *targetHeapTuple + HEAPTUPLESIZE); (*targetHeapTuple)->t_len = len; (*targetHeapTuple)->t_tableOid = sourceTuple->t_tableOid; - ItemPointerSetInvalid(&((*targetHeapTuple)->t_self)); + (*targetHeapTuple)->t_self = sourceTuple->t_self; targetTHeader->t_infomask = sourceTHeader->t_infomask; targetTHeader->t_hoff = hoff; diff --git a/src/test/regress/expected/fast_default.out b/src/test/regress/expected/fast_default.out index 48bd360..0797e11 100644 --- a/src/test/regress/expected/fast_default.out +++ b/src/test/regress/expected/fast_default.out @@ -727,7 +727,17 @@ SELECT * FROM t; (1 row) DROP TABLE t; +-- make sure expanded tuple has correct self pointer +-- it will be required by the RI tigger doing the cascading delete +CREATE TABLE leader (a int PRIMARY KEY, b int); +CREATE TABLE follower (a int REFERENCES leader ON DELETE CASCADE, b int); +INSERT INTO leader VALUES (1, 1), (2, 2); +ALTER TABLE leader ADD c int; +ALTER TABLE leader DROP c; +DELETE FROM leader; -- cleanup +DROP TABLE follower; +DROP TABLE leader; DROP FUNCTION test_trigger(); DROP TABLE t1; DROP FUNCTION set(name); diff --git a/src/test/regress/sql/fast_default.sql b/src/test/regress/sql/fast_default.sql index 06205cb..eefcd49 100644 --- a/src/test/regress/sql/fast_default.sql +++ b/src/test/regress/sql/fast_default.sql @@ -471,7 +471,19 @@ UPDATE t SET y = 2; SELECT * FROM t; DROP TABLE t; +-- make sure expanded tuple has correct self pointer +-- it will be required by the RI tigger doing the cascading delete + +CREATE TABLE leader (a int PRIMARY KEY, b int); +CREATE TABLE follower (a int REFERENCES leader ON DELETE CASCADE, b int); +INSERT INTO leader VALUES (1, 1), (2, 2); +ALTER TABLE leader ADD c int; +ALTER TABLE leader DROP c; +DELETE FROM leader; + -- cleanup +DROP TABLE follower; +DROP TABLE leader; DROP FUNCTION test_trigger(); DROP TABLE t1; DROP FUNCTION set(name);

view thread (10+ messages)  latest in thread

Message-ID: <ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com>
Permalink:  ../ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com/
Also on:    postgresql.org/message-id/ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew.dunstan@2ndquadrant.com, Langote_Amit_f8@lab.ntt.co.jp, pgsql-hackers@postgresql.org
  Subject: Re: BUG #15448: server process (PID 22656) was terminated by exception 0xC0000005
  In-Reply-To: <ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com>
  References: <15448-068ca37e168742d6@postgresql.org> <9cb4aa1c-12ba-59c3-fd75-545fa90fb92f@lab.ntt.co.jp> <ad2162e6-38ef-76cb-0638-c90f8b00a0d6@2ndQuadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox