From cf7c5f4980f6b609aaf0234a03f924a822f9a734 Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Fri, 22 Nov 2024 19:56:53 +0800 Subject: [PATCH 1/2] add reproduce case --- .../test_partial_update_auto_inc.groovy | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy index 1ec60fbb10e837..98047c1bd4ebac 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy @@ -103,6 +103,25 @@ suite("test_partial_update_auto_inc") { time 10000 } order_qt_select_6 "select * from test_primary_key_partial_update_auto_inc2" - sql """ DROP TABLE IF EXISTS test_primary_key_partial_update_auto_inc2 """ + + + sql """ DROP TABLE IF EXISTS test_primary_key_partial_update_auto_inc3 force; """ + sql """ create table test_primary_key_partial_update_auto_inc3 + ( + `id` bigint not null AUTO_INCREMENT, + `project_code` varchar(20) not null, + `period_num` int + ) unique KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS auto + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "enable_unique_key_merge_on_write" = "true" + ); """ + sql "set enable_unique_key_partial_update=true;" + sql "sync;" + test { + sql "insert into test_primary_key_partial_update_auto_inc3(project_code) values ('test1');" + exception "distributed column not found" + } } } From a3c9b80bdd1623114c1a1539d47866f5a6feeaa8 Mon Sep 17 00:00:00 2001 From: bobhan1 Date: Mon, 25 Nov 2024 11:38:00 +0800 Subject: [PATCH 2/2] fix and update case --- .../plans/commands/insert/InsertUtils.java | 10 +++++++ .../test_partial_update_auto_inc.out | 8 ++++++ .../test_partial_update_auto_inc.groovy | 27 ++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java index 6b301c16f73aa2..60e7e5bf805a64 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java @@ -297,6 +297,7 @@ public static Plan normalizePlan(Plan plan, TableIf table, Optional insertCol = unboundLogicalSink.getColNames().stream() .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); @@ -313,9 +314,18 @@ public static Plan normalizePlan(Plan plan, TableIf table, Optional) unboundLogicalSink).setPartialUpdate(false); + } else { + if (hasMissingAutoIncKey) { + // becuase of the uniqueness of genetaed value of auto-increment column, + // we convert this load to upsert when is misses auto-increment key column + ((UnboundTableSink) unboundLogicalSink).setPartialUpdate(false); + } } } } diff --git a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.out b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.out index 19b192c95facb9..b672eb10570508 100644 --- a/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.out +++ b/regression-test/data/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.out @@ -35,3 +35,11 @@ doris9 3 888 888 30 4 40 40 40 +-- !sql -- +test1 15 +test2 29 +test3 49 + +-- !sql -- +3 + diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy index 98047c1bd4ebac..d689deeb8afe02 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_auto_inc.groovy @@ -110,7 +110,8 @@ suite("test_partial_update_auto_inc") { ( `id` bigint not null AUTO_INCREMENT, `project_code` varchar(20) not null, - `period_num` int + `period_num` int, + `c2` int ) unique KEY(`id`) DISTRIBUTED BY HASH(`id`) BUCKETS auto PROPERTIES ( @@ -118,10 +119,30 @@ suite("test_partial_update_auto_inc") { "enable_unique_key_merge_on_write" = "true" ); """ sql "set enable_unique_key_partial_update=true;" + sql "set enable_insert_strict=false;" sql "sync;" + + sql "insert into test_primary_key_partial_update_auto_inc3(project_code,period_num) values ('test1',15),('test2',29),('test3',49);" + qt_sql "select project_code,period_num from test_primary_key_partial_update_auto_inc3 order by project_code,period_num;" + qt_sql "select count(distinct id) from test_primary_key_partial_update_auto_inc3;" + + + sql """ DROP TABLE IF EXISTS test_primary_key_partial_update_auto_inc4 """ + sql """ CREATE TABLE test_primary_key_partial_update_auto_inc4 ( + `k1` BIGINT NOT NULL AUTO_INCREMENT, + `k2` int, + `c1` int, + `c2` int, + `c3` int) + UNIQUE KEY(`k1`,`k2`) DISTRIBUTED BY HASH(`k1`,`k2`) BUCKETS 1 + PROPERTIES("replication_num" = "1", "enable_unique_key_merge_on_write" = "true"); """ + sql "set enable_unique_key_partial_update=true;" + sql "set enable_insert_strict=false;" + sql "sync;" + test { - sql "insert into test_primary_key_partial_update_auto_inc3(project_code) values ('test1');" - exception "distributed column not found" + sql "insert into test_primary_key_partial_update_auto_inc4(c1,c2) values(1,1),(2,2),(3,3)" + exception "Partial update should include all key columns, missing: k2" } } }