Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDObg-0005zu-PJ for pgsql-bugs@arkaria.postgresql.org; Mon, 08 Apr 2019 07:22:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hDObf-0008QZ-25 for pgsql-bugs@arkaria.postgresql.org; Mon, 08 Apr 2019 07:22:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDObe-0008Hq-N5 for pgsql-bugs@lists.postgresql.org; Mon, 08 Apr 2019 07:22:14 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hDObb-0000cF-Jl for pgsql-bugs@lists.postgresql.org; Mon, 08 Apr 2019 07:22:14 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x387M3t4026466; Mon, 8 Apr 2019 16:22:03 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 52D76EA8095; Mon, 8 Apr 2019 16:22:03 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 47E6EEA805B; Mon, 8 Apr 2019 16:22:03 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 30BE5400576; Mon, 8 Apr 2019 16:22:03 +0900 (JST) Subject: Re: BUG #15727: PANIC: cannot abort transaction 295144144, it was already committed References: <20190403122027.GA17929@alvherre.pgsql> <994bff111c549f45041cd1dc7473548e@postgrespro.ru> <19321.1554567786@sss.pgh.pa.us> From: Amit Langote Message-ID: Date: Mon, 8 Apr 2019 16:21:47 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <19321.1554567786@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------D96B4C885EDAD9B05C4FBAB6" Content-Language: en-US X-CC-Mail-RelayStamp: 1 To: Tom Lane , r.zharkov@postgrespro.ru Cc: Alvaro Herrera , Andres Freund , pgsql-bugs@lists.postgresql.org X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D96B4C885EDAD9B05C4FBAB6 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 2019/04/07 1:23, Tom Lane wrote: > It seems that there may be some connection between this problem and > EPQ. I was working on committing Amit's fix for bug #15677, which > demonstrated that EPQ doesn't work for partitioned-table target rels. > It seemed like there really needed to be regression test coverage for > that, so I tried to convert his crasher example into an isolation test. > It does indeed crash without Amit's fix ... but with it, lookee what > I get: > > +error in steps c1 complexpartupdate: ERROR: unexpected table_lock_tuple status: 1 > > That seems fully reproducible in this test. I haven't looked into > exactly what's causing that, but now that we have a reproducible > example, somebody should. > > I'm not quite sure if I should commit this as-is or wait till the > other problem is fixed. A crash is probably worse than a bogus > error, but I don't like committing obviously-wrong "expected" output. > Thoughts? Thank you Tom for picking it up and adding the test which I should've done to begin with. Now that Andres has taken care of the other issues [1], maybe this one's good to go? The isolation test part needed to be rebased over Andres' commit, which I've done in the attached updated patch. Thanks, Amit [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=41f5e04ae --------------D96B4C885EDAD9B05C4FBAB6 Content-Type: text/plain; charset=UTF-8; name="bug-15677-fix-with-test_v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bug-15677-fix-with-test_v2.patch" diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 602a08e585..6a459af9a2 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -2799,15 +2799,24 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree) estate->es_output_cid = parentestate->es_output_cid; if (parentestate->es_num_result_relations > 0) { - int numResultRelations = parentestate->es_num_result_relations; + int numResultRels = parentestate->es_num_result_relations; + int numRootResultRels = parentestate->es_num_root_result_relations; ResultRelInfo *resultRelInfos; resultRelInfos = (ResultRelInfo *) - palloc(numResultRelations * sizeof(ResultRelInfo)); + palloc(numResultRels * sizeof(ResultRelInfo)); memcpy(resultRelInfos, parentestate->es_result_relations, - numResultRelations * sizeof(ResultRelInfo)); + numResultRels * sizeof(ResultRelInfo)); estate->es_result_relations = resultRelInfos; - estate->es_num_result_relations = numResultRelations; + estate->es_num_result_relations = numResultRels; + + /* Also transfer partitioned root result relations. */ + resultRelInfos = (ResultRelInfo *) + palloc(numRootResultRels * sizeof(ResultRelInfo)); + memcpy(resultRelInfos, parentestate->es_root_result_relations, + numRootResultRels * sizeof(ResultRelInfo)); + estate->es_root_result_relations = resultRelInfos; + estate->es_num_root_result_relations = numRootResultRels; } /* es_result_relation_info must NOT be copied */ /* es_trig_target_relations must NOT be copied */ diff --git a/src/test/isolation/expected/eval-plan-qual.out b/src/test/isolation/expected/eval-plan-qual.out index 0308f2d729..703f410068 100644 --- a/src/test/isolation/expected/eval-plan-qual.out +++ b/src/test/isolation/expected/eval-plan-qual.out @@ -629,3 +629,15 @@ step multireadwcte: <... completed> subid id 1 1 + +starting permutation: simplepartupdate complexpartupdate c1 c2 +step simplepartupdate: + update parttbl set a = a; + +step complexpartupdate: + with u as (update parttbl set a = a returning parttbl.*) + update parttbl set a = u.a from u; + +step c1: COMMIT; +step complexpartupdate: <... completed> +step c2: COMMIT; diff --git a/src/test/isolation/specs/eval-plan-qual.spec b/src/test/isolation/specs/eval-plan-qual.spec index 5a4d1c1705..4744f558b0 100644 --- a/src/test/isolation/specs/eval-plan-qual.spec +++ b/src/test/isolation/specs/eval-plan-qual.spec @@ -32,6 +32,10 @@ setup CREATE TABLE jointest AS SELECT generate_series(1,10) AS id, 0 AS data; CREATE INDEX ON jointest(id); + + CREATE TABLE parttbl (a int) PARTITION BY LIST (a); + CREATE TABLE parttbl1 PARTITION OF parttbl FOR VALUES IN (1); + INSERT INTO parttbl VALUES (1); } teardown @@ -41,6 +45,7 @@ teardown DROP TABLE accounts_ext; DROP TABLE p CASCADE; DROP TABLE table_a, table_b, jointest; + DROP TABLE parttbl; } session "s1" @@ -137,6 +142,12 @@ step "selectresultforupdate" { where jt.id = y for update of jt, ss1, ss2; } +# test for EPQ on a partitioned result table + +step "simplepartupdate" { + update parttbl set a = a; +} + session "s2" setup { BEGIN ISOLATION LEVEL READ COMMITTED; } @@ -174,6 +185,10 @@ step "updateforcip3" { } step "wrtwcte" { UPDATE table_a SET value = 'tableAValue2' WHERE id = 1; } step "wrjt" { UPDATE jointest SET data = 42 WHERE id = 7; } +step "complexpartupdate" { + with u as (update parttbl set a = a returning parttbl.*) + update parttbl set a = u.a from u; +} # Use writable CTEs to create self-updated rows, that then are # (updated|deleted). The *fail versions of the tests additionally @@ -261,3 +276,5 @@ permutation "wrtwcte" "readwcte" "c1" "c2" permutation "wrjt" "selectjoinforupdate" "c2" "c1" permutation "wrjt" "selectresultforupdate" "c2" "c1" permutation "wrtwcte" "multireadwcte" "c1" "c2" + +permutation "simplepartupdate" "complexpartupdate" "c1" "c2" --------------D96B4C885EDAD9B05C4FBAB6--