This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new a2977ec6506 [Fix](Planner) fix delete from using does not attach 
partition information (#39011)
a2977ec6506 is described below

commit a2977ec6506396d51229650c483f8afe95cc2e9b
Author: LiBinfeng <[email protected]>
AuthorDate: Thu Aug 8 21:36:51 2024 +0800

    [Fix](Planner) fix delete from using does not attach partition information 
(#39011)
    
    cherry-pick from master #39020
    
    Problem:
    when use delete from using clause and assign partition information, it
    would delete more data from other partition
    Solved:
    add partition information when transfer delete clause into insert into
    select clause
---
 .../java/org/apache/doris/analysis/DeleteStmt.java |  1 +
 .../data/delete_p0/test_delete_from_partition.out  |  7 +++++
 .../delete_p0/test_delete_from_partition.groovy    | 31 ++++++++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java
index f9ad5382d44..38d2fc82792 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java
@@ -169,6 +169,7 @@ public class DeleteStmt extends DdlStmt {
         }
 
         FromClause fromUsedInInsert;
+        targetTableRef.setPartitionNames(partitionNames);
         if (fromClause == null) {
             fromUsedInInsert = new 
FromClause(Lists.newArrayList(targetTableRef));
         } else {
diff --git a/regression-test/data/delete_p0/test_delete_from_partition.out 
b/regression-test/data/delete_p0/test_delete_from_partition.out
index 7ae95a3c8ae..348c813953d 100644
--- a/regression-test/data/delete_p0/test_delete_from_partition.out
+++ b/regression-test/data/delete_p0/test_delete_from_partition.out
@@ -94,3 +94,10 @@ i    i       9       9
 -- !sql --
 i      i       9       9
 
+-- !sql --
+1      2       test1
+2      2       test
+
+-- !sql --
+2      2       test
+
diff --git a/regression-test/suites/delete_p0/test_delete_from_partition.groovy 
b/regression-test/suites/delete_p0/test_delete_from_partition.groovy
index acf46dc4fbc..d3666c44002 100644
--- a/regression-test/suites/delete_p0/test_delete_from_partition.groovy
+++ b/regression-test/suites/delete_p0/test_delete_from_partition.groovy
@@ -65,4 +65,35 @@ suite("test_delete_from_partition") {
 
     sql """delete from ${tableName} where l1 < "i" and l2 < "h";"""
     qt_sql """select * from ${tableName} order by l1, l2"""
+
+    def testDeleteTableName = "test_delete_partition"
+    sql """DROP TABLE IF EXISTS ${testDeleteTableName} """
+    sql """create table ${testDeleteTableName}
+    (
+            k1 TINYINT not null,
+                    k2 INT NOT NULL DEFAULT "1" COMMENT "int column",
+    k3 VARCHAR(20)
+    )
+    UNIQUE KEY(`k1`, `k2`)
+    PARTITION BY LIST(`k1`)
+    (
+            PARTITION `p1` VALUES IN (1),
+    PARTITION `p2` VALUES IN (2)
+    )
+    DISTRIBUTED BY HASH(k1) BUCKETS 1
+    PROPERTIES ('replication_num' = '1');"""
+
+    sql """insert into ${testDeleteTableName} values (1, 2, "test1"), (2, 2, 
"test");"""
+
+    qt_sql """select * from ${testDeleteTableName} order by k1;"""
+
+    sql """delete from
+    ${testDeleteTableName} partition p1
+    using ${testDeleteTableName} partition (p1) as t1
+    left outer join ${testDeleteTableName} partitions (p1, p2) as t2 on t1.k2 
= t2.k2
+    where
+    ${testDeleteTableName}.k2 = t1.k2
+    and t2.k2 is not null;"""
+
+    qt_sql """select * from ${testDeleteTableName};"""
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to