Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEv8c-0003eo-OD for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Oct 2018 11:46:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEv8Z-0004rh-1O for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Oct 2018 11:46:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEv8Y-0004rT-Mk for pgsql-bugs@lists.postgresql.org; Tue, 23 Oct 2018 11:46:14 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gEv8O-0006CN-GM for pgsql-bugs@lists.postgresql.org; Tue, 23 Oct 2018 11:46:12 +0000 Received: by mail-qk1-x742.google.com with SMTP id p6-v6so567718qkg.1 for ; Tue, 23 Oct 2018 04:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=mLsCq4QnU6r88NN/JqxXMaw5bH7w29oHmNJnyP5bPx8=; b=IH8AIVYKUdFfseW1FZopKe2pCkfyd3oJ5uqZMtv6CXi9vi8EiWWVbyD6a6MzvbNXyO ULowZVHu40zUve7FAbeLh1S8RjeHwQpw0k6V37IpbxWeS0Kbt1t6L1F65xmLJHhBcvsW wz/T9FSbKlC+I9IMnhPGtnP5OGtgbXJgMI7cxkLJocvRSg7noh7NFArwEuWiKrTuJn+q mNAkJ8tF5PU5ZfSqTMgTpG54Kgl0LUwYxT5tcyteem4sj2Cj/HJpFzOW7EgUa/LrTLsb ImEYuaw8ck7Lj1zbFLwltbomDELhpU1df+AP20drq9ie00FRE4gYg1mae/z+xHN2Cx1j 9gqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=mLsCq4QnU6r88NN/JqxXMaw5bH7w29oHmNJnyP5bPx8=; b=Nwb9hzVqIxdnc5OJUaqJmuwJQ6mLbJCgnvGY/nakAxDFgcI0Pf6DaHztTniQkdzoEE eYZxB12oklv+Rfc0VQK1t1t4gNtMn75r8YymzRVlHNOYNsVw17UVnOOQdXnGx/BO0QOz q89eBjzm7BrseWiIYzs/16MsTqVnYhTyq9SIvL4T6nKcXmYPN6A/+AuXqKyxue7zcPHY AVpPqlzYMDh8TWu3pTAliBvuz0taKBGAyJ46CMMKDWyezBBFcrZcgEdouVjw0GUl8OeO GnX+pM7u6xYOvjm8FBAC1aTSMGXgpNC2OJm+k2zqP41JZJpDdQ79wxavyM8v3FR6hp1l V7NQ== X-Gm-Message-State: AGRZ1gKbDe7V0pUK5zA7kDyrDARFwHbhmMGkteewTcngLUihtYhhTK47 yCb60+8ngQiRjsmNBhbcWcvU X-Google-Smtp-Source: AJdET5esp+zICSQBe/wpAHlwrXrBo94ES6ejQy+kGk1tHamH2jMTpwLoATEsLH0/4lj+7+kXSXSCJw== X-Received: by 2002:a37:8e04:: with SMTP id q4-v6mr8522976qkd.314.1540295163390; Tue, 23 Oct 2018 04:46:03 -0700 (PDT) Received: from [192.168.10.146] ([98.122.175.38]) by smtp.gmail.com with ESMTPSA id u128-v6sm552116qkc.14.2018.10.23.04.46.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 04:46:02 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: BUG #15448: server process (PID 22656) was terminated by exception 0xC0000005 To: Amit Langote , tillmann73@yahoo.de, pgsql-bugs@lists.postgresql.org, PostgreSQL-development References: <15448-068ca37e168742d6@postgresql.org> <9cb4aa1c-12ba-59c3-fd75-545fa90fb92f@lab.ntt.co.jp> Message-ID: Date: Tue, 23 Oct 2018 07:46:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <9cb4aa1c-12ba-59c3-fd75-545fa90fb92f@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------309DD35021F9BBCD6DAA6441" Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------309DD35021F9BBCD6DAA6441 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------309DD35021F9BBCD6DAA6441 Content-Type: text/x-patch; name="fast_default_expand_tuple_fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fast_default_expand_tuple_fix.patch" 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); --------------309DD35021F9BBCD6DAA6441--