This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 6ddc45b3fd9 branch-2.1: [opt](auto-inc) Allow to miss auto-increment column and other value columns in partial update #44528 (#45073) 6ddc45b3fd9 is described below commit 6ddc45b3fd90e4187570698ea00fb2652e25d111 Author: bobhan1 <bao...@selectdb.com> AuthorDate: Fri Dec 6 22:40:44 2024 +0800 branch-2.1: [opt](auto-inc) Allow to miss auto-increment column and other value columns in partial update #44528 (#45073) pick https://github.com/apache/doris/pull/44528 --- .../apache/doris/analysis/NativeInsertStmt.java | 8 +++++ .../trees/plans/commands/insert/InsertUtils.java | 10 ++++++ .../test_partial_update_auto_inc.out | 16 +++++++++ .../test_partial_update_auto_inc.groovy | 41 ++++++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java index 13f3c3bfac4..61b563b2e00 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java @@ -1359,6 +1359,7 @@ public class NativeInsertStmt extends InsertStmt { return; } boolean hasMissingColExceptAutoIncKey = false; + boolean hasMissingAutoIncKey = false; for (Column col : olapTable.getFullSchema()) { boolean exists = false; for (Column insertCol : targetColumns) { @@ -1378,10 +1379,17 @@ public class NativeInsertStmt extends InsertStmt { if (!(col.isKey() && col.isAutoInc()) && col.isVisible()) { hasMissingColExceptAutoIncKey = true; } + if (col.isKey() && col.isAutoInc()) { + hasMissingAutoIncKey = true; + } } } if (!hasMissingColExceptAutoIncKey) { return; + } 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 + return; } isPartialUpdate = true; 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 dc1fefdbff4..d478192f1b4 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 @@ -284,6 +284,7 @@ public class InsertUtils { ((UnboundTableSink<? extends Plan>) unboundLogicalSink).setPartialUpdate(false); } else { boolean hasMissingColExceptAutoIncKey = false; + boolean hasMissingAutoIncKey = false; for (Column col : olapTable.getFullSchema()) { Optional<String> insertCol = unboundLogicalSink.getColNames().stream() .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); @@ -294,9 +295,18 @@ public class InsertUtils { if (!(col.isAutoInc() && col.isKey()) && !insertCol.isPresent() && col.isVisible()) { hasMissingColExceptAutoIncKey = true; } + if (col.isAutoInc() && col.isKey() && !insertCol.isPresent()) { + hasMissingAutoIncKey = true; + } } if (!hasMissingColExceptAutoIncKey) { ((UnboundTableSink<? extends Plan>) 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<? extends Plan>) 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 d157f501a8b..845eb413689 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,6 +35,14 @@ doris9 3 888 888 30 4 40 40 40 +-- !sql -- +test1 15 +test2 29 +test3 49 + +-- !sql -- +3 + -- !select_1 -- doris1 doris2 @@ -71,3 +79,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 ec46939b2f5..13d6fd26906 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 @@ -113,6 +113,47 @@ suite("test_partial_update_auto_inc") { } 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, + `c2` 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 "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_inc4(c1,c2) values(1,1),(2,2),(3,3)" + exception "Partial update should include all key columns, missing: k2" + } + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org