This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 9a8bcf2b1b878a8b0c996bf39b23b64a7bcff358 Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Tue Jan 23 13:59:04 2024 +0800 [fix](planner) row policy rewriter generate wrong plan on join table ref (#30233) --- .../org/apache/doris/analysis/StmtRewriter.java | 12 ++++++- .../suites/query_p0/test_row_policy.groovy | 42 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java index d80328683dd..1ac31c8fc63 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java @@ -1338,7 +1338,17 @@ public class StmtRewriter { null, null, LimitElement.NO_LIMIT); - selectStmt.fromClause.set(i, new InlineViewRef(tableRef.getAliasAsName().getTbl(), stmt)); + InlineViewRef inlineViewRef = new InlineViewRef(tableRef.getAliasAsName().getTbl(), stmt); + inlineViewRef.setJoinOp(tableRef.joinOp); + inlineViewRef.setLeftTblRef(tableRef.leftTblRef); + inlineViewRef.setOnClause(tableRef.onClause); + tableRef.joinOp = null; + tableRef.leftTblRef = null; + tableRef.onClause = null; + if (selectStmt.fromClause.size() > i + 1) { + selectStmt.fromClause.get(i + 1).setLeftTblRef(inlineViewRef); + } + selectStmt.fromClause.set(i, inlineViewRef); selectStmt.analyze(analyzer); reAnalyze = true; } diff --git a/regression-test/suites/query_p0/test_row_policy.groovy b/regression-test/suites/query_p0/test_row_policy.groovy new file mode 100644 index 00000000000..5866d89d96e --- /dev/null +++ b/regression-test/suites/query_p0/test_row_policy.groovy @@ -0,0 +1,42 @@ +// 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_row_policy") { + def dbName = context.config.getDbNameByFile(context.file) + def tableName = "t1" + def user = "test_row_policy" + def tokens = context.config.jdbcUrl.split('/') + def url=tokens[0] + "//" + tokens[2] + "/" + dbName + "?" + sql """DROP TABLE IF EXISTS ${tableName}""" + sql """CREATE TABLE ${tableName} (id INT) DISTRIBUTED BY HASH(id) PROPERTIES('replication_num'='1')""" + sql """DROP USER IF EXISTS ${user}""" + sql """CREATE USER ${user} IDENTIFIED BY '123456';""" + sql """GRANT SELECT_PRIV ON ${dbName} TO ${user}""" + sql """DROP ROW POLICY IF EXISTS policy_01 ON ${tableName} FOR ${user}""" + sql """CREATE ROW POLICY IF NOT EXISTS policy_01 ON ${tableName} AS restrictive TO ${user} USING(id=1)""" + + connect(user=user, password='123456', url=url) { + sql "set enable_nereids_planner = false" + sql "SELECT * FROM ${tableName} a JOIN ${tableName} b ON a.id = b.id" + } + + connect(user=user, password='123456', url=url) { + sql "set enable_nereids_planner = true" + sql "set enable_fallback_to_original_planner = false" + sql "SELECT * FROM ${tableName} a JOIN ${tableName} b ON a.id = b.id" + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org