diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/InsertAnalyzer.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/InsertAnalyzer.java index 080e385093842..e97903241d3e5 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/InsertAnalyzer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/InsertAnalyzer.java @@ -130,7 +130,8 @@ public static void analyzeWithDeferredLock(InsertStmt insertStmt, ConnectContext } else if (insertStmt.isStaticKeyPartitionInsert()) { checkStaticKeyPartitionInsert(insertStmt, table, targetPartitionNames); } else { - if ((insertStmt.isOverwrite() && session.getSessionVariable().isDynamicOverwrite())) { + if ((insertStmt.isOverwrite() && session.getSessionVariable().isDynamicOverwrite()) + && olapTable.supportedAutomaticPartition()) { insertStmt.setIsDynamicOverwrite(true); } else { for (Partition partition : olapTable.getPartitions()) { diff --git a/test/sql/test_dynamic_overwrite/R/test_overwrite b/test/sql/test_dynamic_overwrite/R/test_overwrite index c2f40b411f22c..4eca859007ccb 100644 --- a/test/sql/test_dynamic_overwrite/R/test_overwrite +++ b/test/sql/test_dynamic_overwrite/R/test_overwrite @@ -10,6 +10,10 @@ show variables like '%dynamic_overwrite%'; -- result: dynamic_overwrite true -- !result + + + + -- name: test_dynamic_overwrite create table t(k int, v int) partition by (k); -- result: @@ -44,4 +48,78 @@ select * from t; 4 1 2 2 3 2 +-- !result + + + +-- name: test_dynamic_overwrite_on_other_table +create table t(k int) partition by range(k) +( + PARTITION p1 VALUES LESS THAN ("1"), + PARTITION p2 VALUES LESS THAN ("2") +); +-- result: +-- !result +insert into t values(0); +-- result: +-- !result +insert into t values(1); +-- result: +-- !result +select * from t; +-- result: +0 +1 +-- !result +insert overwrite t values(1); +-- result: +-- !result +select * from t; +-- result: +1 +-- !result +set dynamic_overwrite=true; +-- result: +-- !result +insert overwrite t values(0); +-- result: +-- !result +select * from t; +-- result: +0 +-- !result +create table t1(k int) +PARTITION BY LIST (k) ( + PARTITION p1 VALUES IN ("1"), + PARTITION p2 VALUES IN ("0") +); +-- result: +-- !result +insert into t1 values(0); +-- result: +-- !result +insert into t1 values(1); +-- result: +-- !result +select * from t1; +-- result: +1 +0 +-- !result +insert overwrite t1 values(1); +-- result: +-- !result +select * from t1; +-- result: +1 +-- !result +set dynamic_overwrite=true; +-- result: +-- !result +insert overwrite t1 values(0); +-- result: +-- !result +select * from t1; +-- result: +0 -- !result \ No newline at end of file diff --git a/test/sql/test_dynamic_overwrite/T/test_overwrite b/test/sql/test_dynamic_overwrite/T/test_overwrite index 443eb553e8a8a..0f6c35661dd1f 100644 --- a/test/sql/test_dynamic_overwrite/T/test_overwrite +++ b/test/sql/test_dynamic_overwrite/T/test_overwrite @@ -13,3 +13,39 @@ select * from t; set dynamic_overwrite=true; insert overwrite t values(4,1),(3,2); select * from t; + +-- name: test_dynamic_overwrite_on_other_table +create table t(k int) partition by range(k) +( + PARTITION p1 VALUES LESS THAN ("1"), + PARTITION p2 VALUES LESS THAN ("2") +); + +insert into t values(0); +insert into t values(1); +select * from t; + +insert overwrite t values(1); +select * from t; + +set dynamic_overwrite=true; +insert overwrite t values(0); +select * from t; + + +create table t1(k int) +PARTITION BY LIST (k) ( + PARTITION p1 VALUES IN ("1"), + PARTITION p2 VALUES IN ("0") +); + +insert into t1 values(0); +insert into t1 values(1); +select * from t1; + +insert overwrite t1 values(1); +select * from t1; + +set dynamic_overwrite=true; +insert overwrite t1 values(0); +select * from t1;