diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java index 8ecd417691..23c58ba42f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSink.java @@ -48,7 +48,7 @@ public class UnboundTableSink extends UnboundLogicalSin private final List hints; private final boolean temporaryPartition; private final List partitions; - private final boolean isPartialUpdate; + private boolean isPartialUpdate; private final DMLCommandType dmlCommandType; private final boolean autoDetectPartition; @@ -114,6 +114,10 @@ public class UnboundTableSink extends UnboundLogicalSin return isPartialUpdate; } + public void setPartialUpdate(boolean isPartialUpdate) { + this.isPartialUpdate = isPartialUpdate; + } + @Override public Plan withChildren(List children) { Preconditions.checkArgument(children.size() == 1, "UnboundOlapTableSink only accepts one child"); 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 f0e7fab736..ad974e9e7b 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 @@ -247,21 +247,25 @@ public class InsertUtils { && ((UnboundTableSink) unboundLogicalSink).isPartialUpdate()) { // check the necessary conditions for partial updates OlapTable olapTable = (OlapTable) table; + if (!olapTable.getEnableUniqueKeyMergeOnWrite()) { - throw new AnalysisException("Partial update is only allowed on " - + "unique table with merge-on-write enabled."); - } - if (unboundLogicalSink.getDMLCommandType() == DMLCommandType.INSERT) { - if (unboundLogicalSink.getColNames().isEmpty()) { - throw new AnalysisException("You must explicitly specify the columns to be updated when " - + "updating partial columns using the INSERT statement."); - } - for (Column col : olapTable.getFullSchema()) { - Optional insertCol = unboundLogicalSink.getColNames().stream() - .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); - if (col.isKey() && !insertCol.isPresent()) { - throw new AnalysisException("Partial update should include all key columns, missing: " - + col.getName()); + // when enable_unique_key_partial_update = true, + // only unique table with MOW insert with target columns can consider be a partial update, + // and unique table without MOW, insert will be like a normal insert. + ((UnboundTableSink) unboundLogicalSink).setPartialUpdate(false); + } else { + if (unboundLogicalSink.getDMLCommandType() == DMLCommandType.INSERT) { + if (unboundLogicalSink.getColNames().isEmpty()) { + throw new AnalysisException("You must explicitly specify the columns to be updated when " + + "updating partial columns using the INSERT statement."); + } + for (Column col : olapTable.getFullSchema()) { + Optional insertCol = unboundLogicalSink.getColNames().stream() + .filter(c -> c.equalsIgnoreCase(col.getName())).findFirst(); + if (col.isKey() && !insertCol.isPresent()) { + throw new AnalysisException("Partial update should include all key columns, missing: " + + col.getName()); + } } } } diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy index 18b7ffe6fc..f5b7a937bc 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt.groovy @@ -52,7 +52,7 @@ suite("test_partial_update_native_insert_stmt", "p0") { qt_1 """ select * from ${tableName} order by id; """ test { sql """insert into ${tableName} values(2,400),(1,200),(4,400)""" - exception "You must explicitly specify the columns to be updated when updating partial columns using the INSERT statement" + exception "Column count doesn't match value count" } sql "set enable_unique_key_partial_update=false;" sql "sync;" diff --git a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy index 99158b66cd..975f62a685 100644 --- a/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy +++ b/regression-test/suites/unique_with_mow_p0/partial_update/test_partial_update_native_insert_stmt_complex.groovy @@ -89,7 +89,7 @@ suite("test_partial_update_native_insert_stmt_complex", "p0") { sql """insert into ${tbName1} select ${tbName2}.id, ${tbName2}.c1, ${tbName2}.c3 * 100 from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """ - exception "You must explicitly specify the columns to be updated when updating partial columns using the INSERT statement" + exception "Column count doesn't match value count" } sql "truncate table ${tbName1};" sql "truncate table ${tbName2};"