From 3faf0b51104d31ba29d723126c8c11ebf6af3fa4 Mon Sep 17 00:00:00 2001 From: Zhenghua Lyu Date: Thu, 6 Aug 2020 08:34:36 +0800 Subject: [PATCH] Print CTID when we detect data distribution wrong for UPDATE|DELETE. When update or delete statement errors out because of the CTID is not belong to the local segment, we should also print out the CTID of the tuple so that it will be much easier to locate the wrong- distributed data via: `select * from t where gp_segment_id = xxx and ctid='(aaa,bbb)'`. --- src/backend/executor/nodeModifyTable.c | 16 ++++++++++++---- .../expected/modify_table_data_corrupt.out | 4 ++-- .../modify_table_data_corrupt_optimizer.out | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 8eda2a6d9b..8a4cd9eb01 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -732,8 +732,12 @@ ExecDelete(ItemPointer tupleid, * utility mode) or there is bug in code, etc. */ if (segid != GpIdentity.segindex) - elog(ERROR, "distribution key of the tuple doesn't belong to " - "current segment (actually from seg%d)", segid); + elog(ERROR, + "distribution key of the tuple (%u, %u) doesn't belong to " + "current segment (actually from seg%d)", + BlockIdGetBlockNumber(&(tupleid->ip_blkid)), + tupleid->ip_posid, + segid); /* * get information on the (current) result relation @@ -1269,8 +1273,12 @@ ExecUpdate(ItemPointer tupleid, * utility mode) or there is bug in code, etc. */ if (segid != GpIdentity.segindex) - elog(ERROR, "distribution key of the tuple doesn't belong to " - "current segment (actually from seg%d)", segid); + elog(ERROR, + "distribution key of the tuple (%u, %u) doesn't belong to " + "current segment (actually from seg%d)", + BlockIdGetBlockNumber(&(tupleid->ip_blkid)), + tupleid->ip_posid, + segid); /* * get information on the (current) result relation diff --git a/src/test/isolation2/expected/modify_table_data_corrupt.out b/src/test/isolation2/expected/modify_table_data_corrupt.out index cfa939be82..adbb792cd9 100644 --- a/src/test/isolation2/expected/modify_table_data_corrupt.out +++ b/src/test/isolation2/expected/modify_table_data_corrupt.out @@ -81,7 +81,7 @@ explain (costs off) delete from tab1 using tab2, tab3 where tab1.a = tab2.a and begin; BEGIN delete from tab1 using tab2, tab3 where tab1.a = tab2.a and tab1.b = tab3.b; -ERROR: distribution key of the tuple doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:737) (seg1 127.0.1.1:7003 pid=56444) (nodeModifyTable.c:737) +ERROR: distribution key of the tuple (0, 1) doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:735) (seg1 127.0.1.1:7003 pid=89508) (nodeModifyTable.c:735) abort; ABORT @@ -108,7 +108,7 @@ explain (costs off) update tab1 set a = 999 from tab2, tab3 where tab1.a = tab2. begin; BEGIN update tab1 set a = 999 from tab2, tab3 where tab1.a = tab2.a and tab1.b = tab3.b; -ERROR: distribution key of the tuple doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:1284) (seg1 127.0.1.1:7003 pid=56444) (nodeModifyTable.c:1284) +ERROR: distribution key of the tuple (0, 1) doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:1276) (seg1 127.0.1.1:7003 pid=89508) (nodeModifyTable.c:1276) abort; ABORT diff --git a/src/test/isolation2/expected/modify_table_data_corrupt_optimizer.out b/src/test/isolation2/expected/modify_table_data_corrupt_optimizer.out index 1923f4b4c5..7ad2dc443a 100644 --- a/src/test/isolation2/expected/modify_table_data_corrupt_optimizer.out +++ b/src/test/isolation2/expected/modify_table_data_corrupt_optimizer.out @@ -137,7 +137,7 @@ explain (costs off) delete from tab1 using tab2, tab3 where tab1.a = tab2.a and begin; BEGIN delete from tab1 using tab2, tab3 where tab1.a = tab2.a and tab1.b = tab3.a; -ERROR: distribution key of the tuple doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:737) (seg1 127.0.1.1:7003 pid=57517) (nodeModifyTable.c:737) +ERROR: distribution key of the tuple (0, 1) doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:735) (seg1 127.0.1.1:7003 pid=89090) (nodeModifyTable.c:735) abort; ABORT @@ -166,7 +166,7 @@ explain (costs off) update tab1 set a = 999 from tab2, tab3 where tab1.a = tab2. begin; BEGIN update tab1 set a = 999 from tab2, tab3 where tab1.a = tab2.a and tab1.b = tab3.a; -ERROR: distribution key of the tuple doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:737) (seg1 127.0.1.1:7003 pid=47425) (nodeModifyTable.c:737) +ERROR: distribution key of the tuple (0, 1) doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:735) (seg1 127.0.1.1:7003 pid=89090) (nodeModifyTable.c:735) abort; ABORT @@ -190,7 +190,7 @@ explain (costs off) update tab1 set b = b + 1; begin; BEGIN update tab1 set b = b + 1; -ERROR: distribution key of the tuple doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:737) (seg1 127.0.1.1:7003 pid=47425) (nodeModifyTable.c:737) +ERROR: distribution key of the tuple (0, 1) doesn't belong to current segment (actually from seg0) (nodeModifyTable.c:735) (seg1 127.0.1.1:7003 pid=89090) (nodeModifyTable.c:735) abort; ABORT -- GitLab