From 0fade919c727231daaf74e0f2ff068a44de960a0 Mon Sep 17 00:00:00 2001 From: chenjian2664 Date: Thu, 13 Apr 2023 10:54:47 +0800 Subject: [PATCH 1/3] Allow pushJoinIntoTableScan apply on merge target --- .../trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java index 541070c5ab92..f428fe180fb1 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java @@ -107,7 +107,7 @@ public Result apply(JoinNode joinNode, Captures captures, Context context) TableScanNode left = captures.get(LEFT_TABLE_SCAN); TableScanNode right = captures.get(RIGHT_TABLE_SCAN); - verify(!left.isUpdateTarget() && !right.isUpdateTarget(), "Unexpected Join over for-update table scan"); + verify(!right.isUpdateTarget(), "Unexpected Join over for-update table scan"); Expression effectiveFilter = getEffectiveFilter(joinNode); ConnectorExpressionTranslation translation = ConnectorExpressionTranslator.translateConjuncts( From 72eb4d43137377edfe91b3afc8f66d58fbea06ca Mon Sep 17 00:00:00 2001 From: chenjian2664 Date: Tue, 25 Apr 2023 11:42:00 +0800 Subject: [PATCH 2/3] Add test for delete with subquery --- .../src/main/java/io/trino/testing/BaseConnectorTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java index b94dbdba1b76..252a1be136f6 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java @@ -4163,6 +4163,14 @@ public void testDeleteWithSubquery() assertUpdate("DELETE FROM " + table.getName() + " WHERE EXISTS(SELECT 1)", "SELECT count(*) - 1 FROM orders"); } + try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete_correlated_exists_subquery", "AS SELECT * FROM nation")) { + // delete using correlated EXISTS subquery, that subquery without varchar predicate + assertUpdate(format("DELETE FROM %1$s WHERE EXISTS(SELECT regionkey FROM region WHERE regionkey = %1$s.regionkey)", table.getName()), 15); + assertQuery( + "SELECT * FROM " + table.getName(), + "SELECT * FROM nation WHERE regionkey NOT IN (SELECT regionkey FROM region)"); + } + try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete_correlated_exists_subquery", "AS SELECT * FROM nation")) { // delete using correlated EXISTS subquery assertUpdate(format("DELETE FROM %1$s WHERE EXISTS(SELECT regionkey FROM region WHERE regionkey = %1$s.regionkey AND name LIKE 'A%%')", table.getName()), 15); From cabadbdac334f2757910a955c9d635273ea0da3c Mon Sep 17 00:00:00 2001 From: chenjian2664 Date: Tue, 25 Apr 2023 11:43:50 +0800 Subject: [PATCH 3/3] Revert for catch error --- .../trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java index f428fe180fb1..541070c5ab92 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/PushJoinIntoTableScan.java @@ -107,7 +107,7 @@ public Result apply(JoinNode joinNode, Captures captures, Context context) TableScanNode left = captures.get(LEFT_TABLE_SCAN); TableScanNode right = captures.get(RIGHT_TABLE_SCAN); - verify(!right.isUpdateTarget(), "Unexpected Join over for-update table scan"); + verify(!left.isUpdateTarget() && !right.isUpdateTarget(), "Unexpected Join over for-update table scan"); Expression effectiveFilter = getEffectiveFilter(joinNode); ConnectorExpressionTranslation translation = ConnectorExpressionTranslator.translateConjuncts(