issue修复:ignore_hint在update时唯一约束检查错误问题处理

This commit is contained in:
teooooozhang
2022-09-01 21:02:59 +08:00
parent 053e438804
commit 491cbeebdb
4 changed files with 92 additions and 13 deletions

View File

@ -2141,10 +2141,13 @@ lreplace:
estate->es_plannedstmt->hasIgnore &&
!ExecCheckIndexConstraints(slot, estate, result_relation_desc, partition, &isgpi, bucketid,
&conflictInfo, &conflictPartOid, &conflictBucketid)) {
ereport(WARNING,
(errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
// check whether the conflicted info is the update tuple. If not, report warning and return.
if (!ItemPointerEquals(&conflictInfo.conflictTid, tupleid)) {
ereport(WARNING,
(errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
}
}
/*
@ -2434,9 +2437,14 @@ lreplace:
if (can_ignore &&
!ExecCheckIndexConstraints(slot, estate, fake_relation, partition, &isgpi, bucketid,
&conflictInfo, &conflictPartOid, &conflictBucketid)) {
ereport(WARNING, (errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
// check whether the conflicted info is the update tuple. If not, report warning and return.
bool is_same_pointer = ItemPointerEquals(&conflictInfo.conflictTid, tupleid);
if (!is_same_pointer || oldPartitionOid != conflictPartOid) {
ereport(WARNING,
(errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
}
}
if (result_relation_desc->rd_isblockchain) {
@ -2646,9 +2654,14 @@ lreplace:
if (can_ignore &&
!ExecCheckIndexConstraints(slot, estate, fake_insert_relation, insert_partition, &isgpi,
bucketid, &conflictInfo, &conflictPartOid, &conflictBucketid)) {
ereport(WARNING, (errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
// check whether the conflicted info is the update tuple. If not, report warning and return.
bool is_same_pointer = ItemPointerEquals(&conflictInfo.conflictTid, tupleid);
if (!is_same_pointer || oldPartitionOid != conflictPartOid) {
ereport(WARNING,
(errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(result_relation_desc))));
return NULL;
}
}
/* delete the old tuple */

View File

@ -372,9 +372,12 @@ lreplace:
if (m_c_local.m_estate->es_plannedstmt && m_c_local.m_estate->es_plannedstmt->hasIgnore &&
!ExecCheckIndexConstraints(m_local.m_reslot, m_c_local.m_estate, ledger_dest_rel, part, &isgpi, bucketid,
&conflictInfo, &conflictPartOid, &conflictBucketid)) {
ereport(WARNING, (errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(ledger_dest_rel))));
break;
// check whether the conflicted info is the update tuple. If not, report warning and return.
if (!ItemPointerEquals(&((HeapTuple)tup)->t_self, &conflictInfo.conflictTid)) {
ereport(WARNING, (errmsg("duplicate key value violates unique constraint in table \"%s\"",
RelationGetRelationName(ledger_dest_rel))));
break;
}
}
bool update_indexes = false;

View File

@ -365,6 +365,48 @@ select * from t_ignore;
2
(2 rows)
-- test for update table with primary key
drop table if exists t_pri_key_update;
NOTICE: table "t_pri_key_update" does not exist, skipping
create table t_pri_key_update(c1 int primary key, c2 int);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_pri_key_update_pkey" for table "t_pri_key_update"
insert into t_pri_key_update values(1, 101), (2, 201);
update /*+ ignore_error */ t_pri_key_update set c2 = 999 where c1 = 2;
select * from t_pri_key_update;
c1 | c2
----+-----
1 | 101
2 | 999
(2 rows)
drop table t_pri_key_update;
create table t_pri_key_update_partition (c1 int primary key, c2 int)
partition by list(c2)
(
partition p1 values (1),
partition p2 values (10),
partition p3 values (100),
partition p4 values (500)
);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_pri_key_update_partition_pkey" for table "t_pri_key_update_partition"
insert into t_pri_key_update_partition values (1, 1), (10, 10), (100, 100);
select * from t_pri_key_update_partition;
c1 | c2
-----+-----
100 | 100
10 | 10
1 | 1
(3 rows)
update /*+ ignore_error */ t_pri_key_update_partition set c2 = 500 where c1 = 10;
select * from t_pri_key_update_partition;
c1 | c2
-----+-----
10 | 500
100 | 100
1 | 1
(3 rows)
-- test for column orientation table: not supported
drop table if exists t_column_orien cascade;
NOTICE: table "t_column_orien" does not exist, skipping

View File

@ -177,6 +177,27 @@ insert into t_ignore values(2);
update /*+ ignore_error */ t_ignore set num = 1 where num = 2;
select * from t_ignore;
-- test for update table with primary key
drop table if exists t_pri_key_update;
create table t_pri_key_update(c1 int primary key, c2 int);
insert into t_pri_key_update values(1, 101), (2, 201);
update /*+ ignore_error */ t_pri_key_update set c2 = 999 where c1 = 2;
select * from t_pri_key_update;
drop table t_pri_key_update;
create table t_pri_key_update_partition (c1 int primary key, c2 int)
partition by list(c2)
(
partition p1 values (1),
partition p2 values (10),
partition p3 values (100),
partition p4 values (500)
);
insert into t_pri_key_update_partition values (1, 1), (10, 10), (100, 100);
select * from t_pri_key_update_partition;
update /*+ ignore_error */ t_pri_key_update_partition set c2 = 500 where c1 = 10;
select * from t_pri_key_update_partition;
-- test for column orientation table: not supported
drop table if exists t_column_orien cascade;
create table t_column_orien(c1 int primary key) with (orientation=column);