diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
index fdbf72462d52b9..bc0f14020d61ca 100644
--- a/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
+++ b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
@@ -79,6 +79,7 @@ DELETE FROM table_name
++ table_alias: alias of table
+ USING additional_tables: If you need to refer to additional tables in the WHERE clause to help identify the rows to be removed, then specify those table names in the USING clause. You can also use the USING clause to specify subqueries that identify the rows to be removed.
diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
index 49019ae62d7476..24d52aeaab9335 100644
--- a/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
+++ b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
@@ -37,7 +37,7 @@ This statement is used to update the data. The UPDATE statement currently only s
#### Syntax
```sql
-UPDATE target_table
+UPDATE target_table [table_alias]
SET assignment_list
WHERE condition
@@ -54,7 +54,7 @@ value:
```sql
-UPDATE target_table
+UPDATE target_table [table_alias]
SET assignment_list
[ FROM additional_tables]
WHERE condition
@@ -72,6 +72,7 @@ UPDATE target_table
++ table_alias: alias of table
+ FROM additional_tables: Specifies one or more tables to use for selecting rows to update or for setting new values. Note that if you want use target table here, you should give it a alias explicitly.
diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
index 7c1198d31a42e3..56017fa228cf12 100644
--- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
+++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/DELETE.md
@@ -41,7 +41,7 @@ DELETE
语法一:该语法只能指定过滤谓词
```SQL
-DELETE FROM table_name [PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
+DELETE FROM table_name [table_alias] [PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
WHERE
column_name op { value | value_list } [ AND column_name op { value | value_list } ...];
```
@@ -51,7 +51,7 @@ column_name op { value | value_list } [ AND column_name op { value | value_list
语法二:该语法只能在UNIQUE KEY模型表上使用
```sql
-DELETE FROM table_name
+DELETE FROM table_name [table_alias]
[PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
[USING additional_tables]
WHERE condition
@@ -79,6 +79,7 @@ DELETE FROM table_name
++ table_alias: 表的别名
+ USING additional_tables: 如果需要在WHERE语句中使用其他的表来帮助识别需要删除的行,则可以在USING中指定这些表或者查询。
diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
index 5fb4f0939e797e..9bcbfa868b665e 100644
--- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
+++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Manipulation/UPDATE.md
@@ -37,7 +37,7 @@ UPDATE
#### Syntax
```sql
-UPDATE target_table
+UPDATE target_table [table_alias]
SET assignment_list
WHERE condition
@@ -54,7 +54,7 @@ value:
```sql
-UPDATE target_table
+UPDATE target_table [table_alias]
SET assignment_list
[ FROM additional_tables]
WHERE condition
@@ -72,12 +72,11 @@ UPDATE target_table
-UPDATE_FROM
++ table_alias: 表的别名
++ FROM additional_tables: 指定一个或多个表,用于选中更新的行,或者获取更新的值。注意,如需要在此列表中再次使用目标表,需要为其显式指定别名。
-+ FROM additional_tables: 指定一个或多个表,用于选中更新的行,或者获取更新的值。注意,如需要在此列表中再次使用目标表,需要为其显式指定别名。
-
#### Note
当前 UPDATE 语句仅支持在 UNIQUE KEY 模型上的行更新。
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup
index 0e63eb24084ea2..03f4b2cec6443c 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -4187,9 +4187,9 @@ cancel_param ::=
// Delete stmt
delete_stmt ::=
- KW_DELETE KW_FROM table_name:table opt_partition_names:partitionNames opt_using_clause:fromClause where_clause:wherePredicate
+ KW_DELETE KW_FROM table_name:table opt_table_alias:alias opt_partition_names:partitionNames opt_using_clause:fromClause where_clause:wherePredicate
{:
- RESULT = new DeleteStmt(table, partitionNames, fromClause, wherePredicate);
+ RESULT = new DeleteStmt(new TableRef(table, alias), partitionNames, fromClause, wherePredicate);
:}
;
@@ -4475,9 +4475,9 @@ insert_source ::=
// update stmt
update_stmt ::=
- KW_UPDATE table_name:tbl set_clause:setClause opt_from_clause:fromClause where_clause:whereClause
+ KW_UPDATE table_name:tbl opt_table_alias:alias set_clause:setClause opt_from_clause:fromClause where_clause:whereClause
{:
- RESULT = new UpdateStmt(tbl, setClause, fromClause, whereClause);
+ RESULT = new UpdateStmt(new TableRef(tbl, alias), setClause, fromClause, whereClause);
:}
;
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 a36495251c82a3..52422f3a420573 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
@@ -19,11 +19,11 @@
import org.apache.doris.analysis.CompoundPredicate.Operator;
import org.apache.doris.catalog.Column;
-import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.ErrorCode;
@@ -36,14 +36,15 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.LinkedList;
import java.util.List;
public class DeleteStmt extends DdlStmt {
- private final TableName tableName;
+
+ private TableRef targetTableRef;
+ private TableName tableName;
private final PartitionNames partitionNames;
private final FromClause fromClause;
private final Expr wherePredicate;
@@ -51,16 +52,18 @@ public class DeleteStmt extends DdlStmt {
private final List deleteConditions = new LinkedList<>();
private InsertStmt insertStmt;
- private Table targetTable;
+ private TableIf targetTable;
private final List selectListItems = Lists.newArrayList();
private final List cols = Lists.newArrayList();
public DeleteStmt(TableName tableName, PartitionNames partitionNames, Expr wherePredicate) {
- this(tableName, partitionNames, null, wherePredicate);
+ this(new TableRef(tableName, null), partitionNames, null, wherePredicate);
}
- public DeleteStmt(TableName tableName, PartitionNames partitionNames, FromClause fromClause, Expr wherePredicate) {
- this.tableName = tableName;
+ public DeleteStmt(TableRef targetTableRef, PartitionNames partitionNames,
+ FromClause fromClause, Expr wherePredicate) {
+ this.targetTableRef = targetTableRef;
+ this.tableName = targetTableRef.getName();
this.partitionNames = partitionNames;
this.fromClause = fromClause;
this.wherePredicate = wherePredicate;
@@ -122,7 +125,7 @@ private void constructInsertStmt() throws AnalysisException {
if (!column.isVisible() && column.getName().equalsIgnoreCase(Column.DELETE_SIGN)) {
expr = new BoolLiteral(true);
} else if (column.isKey() || !column.isVisible() || (!column.isAllowNull() && !column.hasDefaultValue())) {
- expr = new SlotRef(tableName, column.getName());
+ expr = new SlotRef(targetTableRef.getAliasAsName(), column.getName());
} else {
continue;
}
@@ -131,12 +134,11 @@ private void constructInsertStmt() throws AnalysisException {
}
FromClause fromUsedInInsert;
- TableRef tableRef = new TableRef(tableName, null, partitionNames);
if (fromClause == null) {
- fromUsedInInsert = new FromClause(Lists.newArrayList(tableRef));
+ fromUsedInInsert = new FromClause(Lists.newArrayList(targetTableRef));
} else {
fromUsedInInsert = fromClause.clone();
- fromUsedInInsert.getTableRefs().add(0, tableRef);
+ fromUsedInInsert.getTableRefs().add(0, targetTableRef);
}
SelectStmt selectStmt = new SelectStmt(
// select list
@@ -163,12 +165,14 @@ private void constructInsertStmt() throws AnalysisException {
null);
}
- private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
+ private void analyzeTargetTable(Analyzer analyzer) throws UserException {
// step1: analyze table name and origin table alias
if (tableName == null) {
throw new AnalysisException("Table is not set");
}
- tableName.analyze(analyzer);
+ targetTableRef = analyzer.resolveTableRef(targetTableRef);
+ targetTableRef.analyze(analyzer);
+ tableName = targetTableRef.getName();
// disallow external catalog
Util.prohibitExternalCatalog(tableName.getCtl(), this.getClass().getSimpleName());
// check load privilege, select privilege will check when analyze insert stmt
@@ -180,24 +184,11 @@ private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
}
// step2: resolve table name with catalog, only unique olap table could be updated with using
- String dbName = tableName.getDb();
- String targetTableName = tableName.getTbl();
- Preconditions.checkNotNull(dbName);
- Preconditions.checkNotNull(targetTableName);
- Database database = Env.getCurrentInternalCatalog().getDbOrAnalysisException(dbName);
- targetTable = database.getTableOrAnalysisException(tableName.getTbl());
+ targetTable = targetTableRef.getTable();
if (fromClause != null && (targetTable.getType() != Table.TableType.OLAP
|| ((OlapTable) targetTable).getKeysType() != KeysType.UNIQUE_KEYS)) {
throw new AnalysisException("Only unique table could use delete with using.");
}
-
- // step3: register table to ensure we could analyze column name on the left side of set exprs.
- targetTable.readLock();
- try {
- analyzer.registerOlapTable(targetTable, tableName, null);
- } finally {
- targetTable.readUnlock();
- }
}
@VisibleForTesting
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/UpdateStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/UpdateStmt.java
index 7251a7e76d9c24..d34e192ddb9d37 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/UpdateStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/UpdateStmt.java
@@ -18,11 +18,11 @@
package org.apache.doris.analysis;
import org.apache.doris.catalog.Column;
-import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
@@ -32,7 +32,6 @@
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
@@ -59,21 +58,22 @@
*/
public class UpdateStmt extends DdlStmt {
- private final TableName tableName;
+ private TableRef targetTableRef;
+ private TableName tableName;
private final List setExprs;
private final Expr whereExpr;
private final FromClause fromClause;
private InsertStmt insertStmt;
- private Table targetTable;
+ private TableIf targetTable;
List selectListItems = Lists.newArrayList();
List cols = Lists.newArrayList();
- public UpdateStmt(TableName tableName, List setExprs, FromClause fromClause, Expr whereExpr) {
- this.tableName = tableName;
+ public UpdateStmt(TableRef targetTableRef, List setExprs, FromClause fromClause, Expr whereExpr) {
+ this.targetTableRef = targetTableRef;
+ this.tableName = targetTableRef.getName();
this.setExprs = setExprs;
this.fromClause = fromClause;
this.whereExpr = whereExpr;
-
}
public InsertStmt getInsertStmt() {
@@ -96,12 +96,11 @@ public void analyze(Analyzer analyzer) throws UserException {
private void constructInsertStmt() {
// not use origin from clause, because we need to mod it, and this action will affect toSql().
FromClause fromUsedInInsert;
- TableRef tableRef = new TableRef(tableName, null);
if (fromClause == null) {
- fromUsedInInsert = new FromClause(Lists.newArrayList(tableRef));
+ fromUsedInInsert = new FromClause(Lists.newArrayList(targetTableRef));
} else {
fromUsedInInsert = fromClause.clone();
- fromUsedInInsert.getTableRefs().add(0, tableRef);
+ fromUsedInInsert.getTableRefs().add(0, targetTableRef);
}
SelectStmt selectStmt = new SelectStmt(
// select list
@@ -128,9 +127,11 @@ private void constructInsertStmt() {
null);
}
- private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
+ private void analyzeTargetTable(Analyzer analyzer) throws UserException {
// step1: analyze table name and origin table alias
- tableName.analyze(analyzer);
+ targetTableRef = analyzer.resolveTableRef(targetTableRef);
+ targetTableRef.analyze(analyzer);
+ tableName = targetTableRef.getName();
// disallow external catalog
Util.prohibitExternalCatalog(tableName.getCtl(), this.getClass().getSimpleName());
// check load privilege, select privilege will check when analyze insert stmt
@@ -140,23 +141,11 @@ private void analyzeTargetTable(Analyzer analyzer) throws AnalysisException {
}
// step2: resolve table name with catalog, only unique olap table could be updated
- String dbName = tableName.getDb();
- String targetTableName = tableName.getTbl();
- Preconditions.checkNotNull(dbName);
- Preconditions.checkNotNull(targetTableName);
- Database database = Env.getCurrentInternalCatalog().getDbOrAnalysisException(dbName);
- targetTable = database.getTableOrAnalysisException(tableName.getTbl());
+ targetTable = targetTableRef.getTable();
if (targetTable.getType() != Table.TableType.OLAP
|| ((OlapTable) targetTable).getKeysType() != KeysType.UNIQUE_KEYS) {
throw new AnalysisException("Only unique table could be updated.");
}
- // register table to ensure we could analyze column name on the left side of set exprs.
- targetTable.readLock();
- try {
- analyzer.registerOlapTable(targetTable, tableName, null);
- } finally {
- targetTable.readUnlock();
- }
}
private void analyzeSetExprs(Analyzer analyzer) throws AnalysisException {
@@ -198,7 +187,7 @@ private void analyzeSetExprs(Analyzer analyzer) throws AnalysisException {
// step3: generate select list and insert column name list in insert stmt
for (Column column : targetTable.getColumns()) {
- Expr expr = new SlotRef(tableName, column.getName());
+ Expr expr = new SlotRef(targetTableRef.getAliasAsName(), column.getName());
for (BinaryPredicate setExpr : setExprs) {
Expr lhs = setExpr.getChild(0);
if (((SlotRef) lhs).getColumn().equals(column)) {
@@ -213,7 +202,7 @@ private void analyzeSetExprs(Analyzer analyzer) throws AnalysisException {
@Override
public String toSql() {
StringBuilder sb = new StringBuilder("UPDATE ");
- sb.append(tableName.toSql()).append("\n");
+ sb.append(targetTableRef.toSql()).append("\n");
sb.append(" ").append("SET ");
for (Expr setExpr : setExprs) {
sb.append(setExpr.toSql()).append(", ");
diff --git a/fe/fe-core/src/test/java/org/apache/doris/load/DeleteHandlerTest.java b/fe/fe-core/src/test/java/org/apache/doris/load/DeleteHandlerTest.java
index 41b4506c69d17d..f6fac6fb435a5d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/load/DeleteHandlerTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/load/DeleteHandlerTest.java
@@ -231,17 +231,12 @@ public void testUnQuorumTimeout() throws DdlException, QueryStateException {
minTimes = 0;
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
deleteHandler.process(deleteStmt);
Assert.fail();
}
@Test
- public void testQuorumTimeout() throws DdlException, QueryStateException {
+ public void testQuorumTimeout() throws DdlException {
BinaryPredicate binaryPredicate = new BinaryPredicate(BinaryPredicate.Operator.GT, new SlotRef(null, "k1"),
new IntLiteral(3));
@@ -270,11 +265,6 @@ public TransactionState getTransactionState(long transactionId) {
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
try {
deleteHandler.process(deleteStmt);
} catch (QueryStateException e) {
@@ -290,7 +280,7 @@ public TransactionState getTransactionState(long transactionId) {
}
@Test
- public void testNormalTimeout() throws DdlException, QueryStateException {
+ public void testNormalTimeout() throws DdlException {
BinaryPredicate binaryPredicate = new BinaryPredicate(BinaryPredicate.Operator.GT, new SlotRef(null, "k1"),
new IntLiteral(3));
@@ -320,12 +310,6 @@ public TransactionState getTransactionState(long transactionId) {
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
-
try {
deleteHandler.process(deleteStmt);
} catch (QueryStateException e) {
@@ -384,11 +368,6 @@ public Collection getTabletDeleteInfo() {
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
try {
deleteHandler.process(deleteStmt);
} catch (DdlException e) {
@@ -445,11 +424,6 @@ public Collection getTabletDeleteInfo() {
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
try {
deleteHandler.process(deleteStmt);
} catch (QueryStateException e) {
@@ -497,11 +471,6 @@ public Collection getTabletDeleteInfo() {
}
};
- try {
- deleteStmt.analyze(analyzer);
- } catch (UserException e) {
- Assert.fail();
- }
try {
deleteHandler.process(deleteStmt);
} catch (QueryStateException e) {
diff --git a/regression-test/data/delete_p0/test_delete_using.out b/regression-test/data/delete_p0/test_delete_using.out
index 34c9f2e8bb1413..815bd76056f2f1 100644
--- a/regression-test/data/delete_p0/test_delete_using.out
+++ b/regression-test/data/delete_p0/test_delete_using.out
@@ -3,3 +3,6 @@
2 2 2 2.0 2000-01-02
3 3 3 3.0 2000-01-03
+-- !complex_delete_alias --
+3 3 3 3.0 2000-01-03
+
diff --git a/regression-test/data/update/test_update_unique.out b/regression-test/data/update/test_update_unique.out
index 3d8737af02aae8..051bd679aba09f 100644
--- a/regression-test/data/update/test_update_unique.out
+++ b/regression-test/data/update/test_update_unique.out
@@ -18,3 +18,8 @@ date_value DATE Yes false \N REPLACE
2 2 2 2.0 2000-01-02
3 3 3 3.0 2000-01-03
+-- !complex_update_by_alias --
+1 10 1 1000.0 2000-01-01
+2 20 2 2000.0 2000-01-02
+3 3 3 3.0 2000-01-03
+
diff --git a/regression-test/suites/delete_p0/test_delete_using.groovy b/regression-test/suites/delete_p0/test_delete_using.groovy
index 505c18cf15333e..4e4fe659157e7f 100644
--- a/regression-test/suites/delete_p0/test_delete_using.groovy
+++ b/regression-test/suites/delete_p0/test_delete_using.groovy
@@ -19,10 +19,12 @@ suite("test_delete_using") {
def tbName1 = "test_delete_unique_1"
def tbName2 = "test_delete_unique_2"
def tbName3 = "test_delete_unique_3"
+ def tbName4 = "test_delete_unique_4"
sql "DROP TABLE IF EXISTS ${tbName1}"
sql "DROP TABLE IF EXISTS ${tbName2}"
sql "DROP TABLE IF EXISTS ${tbName3}"
+ sql "DROP TABLE IF EXISTS ${tbName4}"
// test complex update syntax
sql """
@@ -34,6 +36,9 @@ suite("test_delete_using") {
sql """
create table ${tbName3} (id int) distributed by hash (id) properties('replication_num'='1');
"""
+ sql """
+ create table ${tbName4} (id int) distributed by hash (id) properties('replication_num'='1');
+ """
sql """
insert into ${tbName1} values(1, 1, '1', 1.0, '2000-01-01'),(2, 2, '2', 2.0, '2000-01-02'),(3, 3, '3', 3.0, '2000-01-03');
"""
@@ -43,6 +48,9 @@ suite("test_delete_using") {
sql """
insert into ${tbName3} values(1), (4), (5);
"""
+ sql """
+ insert into ${tbName4} values(2), (4), (5);
+ """
sql """
DELETE FROM ${tbName1} USING ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id where ${tbName1}.id = ${tbName2}.id;
@@ -52,7 +60,16 @@ suite("test_delete_using") {
select * from ${tbName1} order by id;
"""
+ sql """
+ DELETE FROM ${tbName1} t1a USING ${tbName2} inner join ${tbName4} on ${tbName2}.id = ${tbName4}.id where t1a.id = ${tbName2}.id;
+ """
+
+ qt_complex_delete_alias """
+ select * from ${tbName1} order by id;
+ """
+
sql "DROP TABLE IF EXISTS ${tbName1}"
sql "DROP TABLE IF EXISTS ${tbName2}"
sql "DROP TABLE IF EXISTS ${tbName3}"
+ sql "DROP TABLE IF EXISTS ${tbName4}"
}
\ No newline at end of file
diff --git a/regression-test/suites/update/test_update_unique.groovy b/regression-test/suites/update/test_update_unique.groovy
index 6acff99f399136..15ccd6c90da9e7 100644
--- a/regression-test/suites/update/test_update_unique.groovy
+++ b/regression-test/suites/update/test_update_unique.groovy
@@ -19,6 +19,7 @@ suite("test_update_unique", "p0") {
def tbName1 = "test_update_unique_1"
def tbName2 = "test_update_unique_2"
def tbName3 = "test_update_unique_3"
+ def tbName4 = "test_update_unique_4"
sql "DROP TABLE IF EXISTS ${tbName1}"
sql """
CREATE TABLE IF NOT EXISTS ${tbName1} (
@@ -44,6 +45,7 @@ suite("test_update_unique", "p0") {
sql "DROP TABLE IF EXISTS ${tbName1}"
sql "DROP TABLE IF EXISTS ${tbName2}"
sql "DROP TABLE IF EXISTS ${tbName3}"
+ sql "DROP TABLE IF EXISTS ${tbName4}"
// test complex update syntax
sql """
@@ -55,6 +57,9 @@ suite("test_update_unique", "p0") {
sql """
create table ${tbName3} (id int) distributed by hash (id) properties('replication_num'='1');
"""
+ sql """
+ create table ${tbName4} (id int) distributed by hash (id) properties('replication_num'='1');
+ """
sql """
insert into ${tbName1} values(1, 1, '1', 1.0, '2000-01-01'),(2, 2, '2', 2.0, '2000-01-02'),(3, 3, '3', 3.0, '2000-01-03');
"""
@@ -64,6 +69,9 @@ suite("test_update_unique", "p0") {
sql """
insert into ${tbName3} values(1), (4), (5);
"""
+ sql """
+ insert into ${tbName4} values(2), (4), (5);
+ """
sql """
update ${tbName1} set ${tbName1}.c1 = ${tbName2}.c1, ${tbName1}.c3 = ${tbName2}.c3 * 100 from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id where ${tbName1}.id = ${tbName2}.id;
@@ -73,7 +81,16 @@ suite("test_update_unique", "p0") {
select * from ${tbName1} order by id;
"""
+ sql """
+ update ${tbName1} t1a set t1a.c1 = ${tbName2}.c1, t1a.c3 = ${tbName2}.c3 * 100 from ${tbName2} inner join ${tbName4} on ${tbName2}.id = ${tbName4}.id where t1a.id = ${tbName2}.id;
+ """
+
+ qt_complex_update_by_alias """
+ select * from ${tbName1} order by id;
+ """
+
sql "DROP TABLE IF EXISTS ${tbName1}"
sql "DROP TABLE IF EXISTS ${tbName2}"
sql "DROP TABLE IF EXISTS ${tbName3}"
+ sql "DROP TABLE IF EXISTS ${tbName4}"
}