From a43efe374230cfbdbc823433e8920e48f06e71ca Mon Sep 17 00:00:00 2001 From: wangt1xiuyi <13547954130@163.com> Date: Mon, 22 Aug 2022 15:52:55 +0800 Subject: [PATCH] [CP] regexp use const pattern uncorrectly in non-static engine --- .../code_generator/ob_expr_generator_impl.cpp | 4 +++- .../test_suite/expr/r/mysql/func_regexp.result | 15 +++++++++++++++ .../test_suite/expr/t/func_regexp.test | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/sql/code_generator/ob_expr_generator_impl.cpp b/src/sql/code_generator/ob_expr_generator_impl.cpp index 7c001f6778..60dd4edb40 100644 --- a/src/sql/code_generator/ob_expr_generator_impl.cpp +++ b/src/sql/code_generator/ob_expr_generator_impl.cpp @@ -597,7 +597,9 @@ inline int ObExprGeneratorImpl::visit_regex_expr(ObOpRawExpr& expr, ObExprRegexp } else { // The value && pattern are const, it is calculated in pre_calculate regexp_op->set_value_is_const(value_expr->has_flag(IS_CONST) || value_expr->has_flag(IS_CONST_EXPR)); - regexp_op->set_pattern_is_const(pattern_expr->has_flag(IS_CONST) || pattern_expr->has_flag(IS_CONST_EXPR)); + if (!pattern_expr->has_flag(CNT_EXEC_PARAM)) { + regexp_op->set_pattern_is_const(pattern_expr->has_flag(IS_CONST) || pattern_expr->has_flag(IS_CONST_EXPR)); + } } } return ret; diff --git a/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result b/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result index 6d42d08aa7..0cc83e78e0 100644 --- a/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result +++ b/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result @@ -6287,3 +6287,18 @@ insert into t values (''); select c1 regexp 'ddd' from t; c1 regexp 'ddd' 0 +drop table if exists t1, t2; +create table t1(c1 int, c2 varchar(10)); +insert into t1 values(1, '1'); +create table t2(c1 int); +insert into t2 values(1), (2); +select t2.*, (select t1.c1 from t1 where t1.c2 REGEXP t2.c1 limit 1 ) from t2; +c1 (select t1.c1 from t1 where t1.c2 REGEXP t2.c1 limit 1 ) +1 1 +2 NULL +select t2.*, (select t1.c1 from t1 where t1.c2 REGEXP t2.c1+1-1 limit 1 ) from t2; +c1 (select t1.c1 from t1 where t1.c2 REGEXP t2.c1+1-1 limit 1 ) +1 1 +2 NULL +drop table t1; +drop table t2; diff --git a/tools/deploy/mysql_test/test_suite/expr/t/func_regexp.test b/tools/deploy/mysql_test/test_suite/expr/t/func_regexp.test index 8112398232..fa9506ad24 100644 --- a/tools/deploy/mysql_test/test_suite/expr/t/func_regexp.test +++ b/tools/deploy/mysql_test/test_suite/expr/t/func_regexp.test @@ -442,3 +442,20 @@ drop table if exists t; create table t (c1 char(20)); insert into t values (''); select c1 regexp 'ddd' from t; + +##bug:https://work.aone.alibaba-inc.com/issue/43976234 + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings + +create table t1(c1 int, c2 varchar(10)); +insert into t1 values(1, '1'); +create table t2(c1 int); +insert into t2 values(1), (2); + +select t2.*, (select t1.c1 from t1 where t1.c2 REGEXP t2.c1 limit 1 ) from t2; +select t2.*, (select t1.c1 from t1 where t1.c2 REGEXP t2.c1+1-1 limit 1 ) from t2; + +drop table t1; +drop table t2; \ No newline at end of file -- GitLab