pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: r.zharkov@postgrespro.ru
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15727: PANIC: cannot abort transaction 295144144, it was already committed
Date: Mon, 8 Apr 2019 17:18:48 +0900
Message-ID: <223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp> (raw)
In-Reply-To: <af5e2f12-ccb0-04b4-2bea-6255dcce3c79@lab.ntt.co.jp>
References: <20190403122027.GA17929@alvherre.pgsql>
	<994bff111c549f45041cd1dc7473548e@postgrespro.ru>
	<19321.1554567786@sss.pgh.pa.us>
	<af5e2f12-ccb0-04b4-2bea-6255dcce3c79@lab.ntt.co.jp>

On 2019/04/08 16:21, Amit Langote wrote:
> 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.

The patch I attached in the previous email doesn't apply as-is to
back-branches due to rebasing.  I've attached another patch here, which
applies to both PG 11 and 10 branches.

Thanks,
Amit
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 572506e7c2..bec5b34455 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -3152,15 +3152,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 49b3fb3446..0095a5fcdf 100644
--- a/src/test/isolation/expected/eval-plan-qual.out
+++ b/src/test/isolation/expected/eval-plan-qual.out
@@ -283,3 +283,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;
+ <waiting ...>
+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 367922de75..ebe5bee4a5 100644
--- a/src/test/isolation/specs/eval-plan-qual.spec
+++ b/src/test/isolation/specs/eval-plan-qual.spec
@@ -29,6 +29,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
@@ -37,6 +41,7 @@ teardown
  DROP TABLE accounts_ext;
  DROP TABLE p CASCADE;
  DROP TABLE table_a, table_b, jointest;
+ DROP TABLE parttbl;
 }
 
 session "s1"
@@ -110,6 +115,12 @@ step "selectjoinforupdate"	{
 	select * from jointest a join jointest b on a.id=b.id for update;
 }
 
+# test for EPQ on a partitioned result table
+
+step "simplepartupdate"	{
+	update parttbl set a = a;
+}
+
 
 session "s2"
 setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
@@ -146,6 +157,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 "c2"	{ COMMIT; }
+step "complexpartupdate"	{
+	with u as (update parttbl set a = a returning parttbl.*)
+	update parttbl set a = u.a from u;
+}
 
 session "s3"
 setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
@@ -191,3 +206,5 @@ permutation "updateforcip" "updateforcip3" "c1" "c2" "read_a"
 permutation "wrtwcte" "readwcte" "c1" "c2"
 permutation "wrjt" "selectjoinforupdate" "c2" "c1"
 permutation "wrtwcte" "multireadwcte" "c1" "c2"
+
+permutation "simplepartupdate" "complexpartupdate" "c1" "c2"

Attachments:

  [text/plain] pg11-10-bug-15677-fix-with-test_v2.patch (3.9K, ../223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp/2-pg11-10-bug-15677-fix-with-test_v2.patch)
  download | inline diff:
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 572506e7c2..bec5b34455 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -3152,15 +3152,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 49b3fb3446..0095a5fcdf 100644
--- a/src/test/isolation/expected/eval-plan-qual.out
+++ b/src/test/isolation/expected/eval-plan-qual.out
@@ -283,3 +283,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;
+ <waiting ...>
+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 367922de75..ebe5bee4a5 100644
--- a/src/test/isolation/specs/eval-plan-qual.spec
+++ b/src/test/isolation/specs/eval-plan-qual.spec
@@ -29,6 +29,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
@@ -37,6 +41,7 @@ teardown
  DROP TABLE accounts_ext;
  DROP TABLE p CASCADE;
  DROP TABLE table_a, table_b, jointest;
+ DROP TABLE parttbl;
 }
 
 session "s1"
@@ -110,6 +115,12 @@ step "selectjoinforupdate"	{
 	select * from jointest a join jointest b on a.id=b.id for update;
 }
 
+# test for EPQ on a partitioned result table
+
+step "simplepartupdate"	{
+	update parttbl set a = a;
+}
+
 
 session "s2"
 setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
@@ -146,6 +157,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 "c2"	{ COMMIT; }
+step "complexpartupdate"	{
+	with u as (update parttbl set a = a returning parttbl.*)
+	update parttbl set a = u.a from u;
+}
 
 session "s3"
 setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
@@ -191,3 +206,5 @@ permutation "updateforcip" "updateforcip3" "c1" "c2" "read_a"
 permutation "wrtwcte" "readwcte" "c1" "c2"
 permutation "wrjt" "selectjoinforupdate" "c2" "c1"
 permutation "wrtwcte" "multireadwcte" "c1" "c2"
+
+permutation "simplepartupdate" "complexpartupdate" "c1" "c2"

view thread (46+ messages)  latest in thread

Message-ID: <223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp>
Permalink:  ../223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: Langote_Amit_f8@lab.ntt.co.jp, tgl@sss.pgh.pa.us, r.zharkov@postgrespro.ru, alvherre@2ndquadrant.com, andres@anarazel.de, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15727: PANIC: cannot abort transaction 295144144, it was already committed
  In-Reply-To: <223f3fa6-3075-47fd-3caa-0d5e8dee1baa@lab.ntt.co.jp>

* 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