From d517d7ab69933f6d2db24d5fa1270e5e099f752a Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Sun, 8 Oct 2023 14:05:41 +0800 Subject: [PATCH] [Fix](point query) Not allow subquery for point query optimization (#25085) --- .../org/apache/doris/analysis/SelectStmt.java | 4 ++ .../suites/point_query_p0/test_update.groovy | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 regression-test/suites/point_query_p0/test_update.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 797237dba5..f19e513f8e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -2622,6 +2622,10 @@ public class SelectStmt extends QueryStmt { if (tbl.getTable().getType() != Table.TableType.OLAP) { return false; } + // ensure no sub query + if (!analyzer.isRootAnalyzer()) { + return false; + } OlapTable olapTable = (OlapTable) tbl.getTable(); Preconditions.checkNotNull(eqPredicates); eqPredicates = getExpectedBinaryPredicates(eqPredicates, whereClause, TExprOpcode.EQ); diff --git a/regression-test/suites/point_query_p0/test_update.groovy b/regression-test/suites/point_query_p0/test_update.groovy new file mode 100644 index 0000000000..32e4fce823 --- /dev/null +++ b/regression-test/suites/point_query_p0/test_update.groovy @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_update", "p0") { + sql """ + create table if not exists test ( + workspace_id int not null comment "Workspace id", + user_id varchar(64) comment "External user id", + tenant_id int not null comment "Tenant id", + created_at datetime not null default current_timestamp(0) comment "Created at", + updated_at datetime comment "Updated at" + ) + engine=olap + unique key (workspace_id, user_id) + distributed by hash(workspace_id, user_id) + properties ( + "replication_num" = "1", + "enable_unique_key_merge_on_write" = "true", + "light_schema_change" = "true", + "store_row_column" = "true" + ); + """ + sql """insert into test (workspace_id, user_id, tenant_id) values (1, 'asdfadfa', 1);""" + sql """update test set tenant_id = 5 where workspace_id = 1 and user_id = 'asdfadfa';""" +} \ No newline at end of file