diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index d6ccce76cf..679316183c 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -685,6 +685,13 @@ int ObTableScanOp::prepare_pushdown_limit_param() need_final_limit_ = true; tsc_rtdef_.scan_rtdef_.limit_param_.offset_ = 0; tsc_rtdef_.scan_rtdef_.limit_param_.limit_ = -1; + + if (nullptr != MY_CTDEF.lookup_ctdef_) { + OB_ASSERT(nullptr != tsc_rtdef_.lookup_rtdef_); + tsc_rtdef_.lookup_rtdef_->limit_param_.offset_ = 0; + tsc_rtdef_.lookup_rtdef_->limit_param_.limit_ = -1; + } + } else if (tsc_rtdef_.has_lookup_limit() || das_ref_.get_das_task_cnt() > 1) { //for index back, need to final limit output rows in TableScan operator, //please see me for the reason: https://work.aone.alibaba-inc.com/issue/43232745 diff --git a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/subplan_filter.result b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/subplan_filter.result index d8c18b9ff9..e90d5eb6d5 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/subplan_filter.result +++ b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/subplan_filter.result @@ -2456,3 +2456,73 @@ select c1,c1 in (select c1 from t2 where t2.c1>=t1.c1) and c1 in (select c1 fro | 26 | 1 | 1 | 1 | | 28 | NULL | NULL | 0 | +----+------+------+------+ + +explain_protocol: 0 +drop table if exists t1; +drop table if exists t3; + +create table t1 (c1 int primary key, c2 int, c3 int, c4 int) ; +create table t3 (c1 int primary key, c2 int, c3 int, c4 int, index(c3)) ; + +insert into t1 (c1, c2, c3, c4) values (1, 1, 1, 1); +insert into t1 (c1, c2, c3, c4) values (2, 2, 2, 2); +insert into t1 (c1, c2, c3, c4) values (12,9, 3, 3); +insert into t1 (c1, c2, c3, c4) values (4, 3, 4, 4); +insert into t1 (c1, c2, c3, c4) values (3, 3, 5, 5); +insert into t1 (c1, c2, c3, c4) values (9, 10,6, 6); +insert into t1 (c1, c2, c3, c4) values (7, 4, 7, 7); +insert into t1 (c1, c2, c3, c4) values (6, 7, 8, 8); + +insert into t1 (c1, c2, c3, c4) values (18, 1,9, 9); +insert into t1 (c1, c2, c3, c4) values (19, 2,10,10); +insert into t1 (c1, c2, c3, c4) values (20, 3,11,11); +insert into t1 (c1, c2, c3, c4) values (21, 5,12,12); +insert into t1 (c1, c2, c3, c4) values (22, 7,13,13); +insert into t1 (c1, c2, c3, c4) values (23, 7,14,14); +insert into t1 (c1, c2, c3, c4) values (24, 7,15,15); +insert into t1 (c1, c2, c3, c4) values (25, 7,16,16); +insert into t1 (c1, c2, c3, c4) values (26, 9,17,17); +insert into t1 (c1, c2, c3, c4) values (28, 3,18,18); + +insert into t3 (c1, c2, c3, c4) values (1, 1, 1, 1); +insert into t3 (c1, c2, c3, c4) values (2, 2, 2, 2); +insert into t3 (c1, c2, c3, c4) values (12,9, 3, 3); +insert into t3 (c1, c2, c3, c4) values (4, 3, 4, 4); +insert into t3 (c1, c2, c3, c4) values (3, 3, 5, 5); +insert into t3 (c1, c2, c3, c4) values (9, 10,6, 6); +insert into t3 (c1, c2, c3, c4) values (7, 4, 7, 7); +insert into t3 (c1, c2, c3, c4) values (6, 7, 8, 8); + +insert into t3 (c1, c2, c3, c4) values (18, 1,9, 9); +insert into t3 (c1, c2, c3, c4) values (19, 2,10,10); +insert into t3 (c1, c2, c3, c4) values (20, 3,11,11); +insert into t3 (c1, c2, c3, c4) values (21, 5,12,12); +insert into t3 (c1, c2, c3, c4) values (22, 7,13,13); +insert into t3 (c1, c2, c3, c4) values (23, 7,14,14); +insert into t3 (c1, c2, c3, c4) values (24, 7,15,15); +insert into t3 (c1, c2, c3, c4) values (25, 7,16,16); +insert into t3 (c1, c2, c3, c4) values (26, 9,17,17); +insert into t3 (c1, c2, c3, c4) values (28, 3,18,18); + +select /*+ no_rewrite*/ * from t1 where exists (select /*+no_unnest */ 1 from t3 where t1.c1 > t3.c3 and t3.c4 < 100 limit 1) ; ++----+------+------+------+ +| c1 | c2 | c3 | c4 | ++----+------+------+------+ +| 2 | 2 | 2 | 2 | +| 3 | 3 | 5 | 5 | +| 4 | 3 | 4 | 4 | +| 6 | 7 | 8 | 8 | +| 7 | 4 | 7 | 7 | +| 9 | 10 | 6 | 6 | +| 12 | 9 | 3 | 3 | +| 18 | 1 | 9 | 9 | +| 19 | 2 | 10 | 10 | +| 20 | 3 | 11 | 11 | +| 21 | 5 | 12 | 12 | +| 22 | 7 | 13 | 13 | +| 23 | 7 | 14 | 14 | +| 24 | 7 | 15 | 15 | +| 25 | 7 | 16 | 16 | +| 26 | 9 | 17 | 17 | +| 28 | 3 | 18 | 18 | ++----+------+------+------+ diff --git a/tools/deploy/mysql_test/test_suite/static_engine/t/subplan_filter.test b/tools/deploy/mysql_test/test_suite/static_engine/t/subplan_filter.test index e7aadcbfdf..3c4a8bcd0b 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/t/subplan_filter.test +++ b/tools/deploy/mysql_test/test_suite/static_engine/t/subplan_filter.test @@ -290,3 +290,56 @@ select c1,c1 in (select c1 from t2 where t2.c1>=t1.c1) and c1 in (select c1 fro select c1,c1 in (select c1 from t2 where t2.c1>=t1.c1) and c1 in (select c1 from t2 where t2.c1 <= t1.c1) or c1 + (select c1 from t2 where t2.c1 = t1.c1) as x, c1+(select c1 from t2 where t2.c1 = t1.c1) > 30 or c1 in (select c2 from t2 where t2.c1 <= t1.c1) as y,c1+(select c2 from t2 where t1.c1=t2.c1) > 10 and c1 in (select c1 from t2 where t1.c1>= t2.c1) as z from t1; + +--explain_protocol 0 +--disable_warnings +drop table if exists t1; +drop table if exists t3; +--enable_warnings + + + +create table t1 (c1 int primary key, c2 int, c3 int, c4 int) ; +create table t3 (c1 int primary key, c2 int, c3 int, c4 int, index(c3)) ; + +insert into t1 (c1, c2, c3, c4) values (1, 1, 1, 1); +insert into t1 (c1, c2, c3, c4) values (2, 2, 2, 2); +insert into t1 (c1, c2, c3, c4) values (12,9, 3, 3); +insert into t1 (c1, c2, c3, c4) values (4, 3, 4, 4); +insert into t1 (c1, c2, c3, c4) values (3, 3, 5, 5); +insert into t1 (c1, c2, c3, c4) values (9, 10,6, 6); +insert into t1 (c1, c2, c3, c4) values (7, 4, 7, 7); +insert into t1 (c1, c2, c3, c4) values (6, 7, 8, 8); + +insert into t1 (c1, c2, c3, c4) values (18, 1,9, 9); +insert into t1 (c1, c2, c3, c4) values (19, 2,10,10); +insert into t1 (c1, c2, c3, c4) values (20, 3,11,11); +insert into t1 (c1, c2, c3, c4) values (21, 5,12,12); +insert into t1 (c1, c2, c3, c4) values (22, 7,13,13); +insert into t1 (c1, c2, c3, c4) values (23, 7,14,14); +insert into t1 (c1, c2, c3, c4) values (24, 7,15,15); +insert into t1 (c1, c2, c3, c4) values (25, 7,16,16); +insert into t1 (c1, c2, c3, c4) values (26, 9,17,17); +insert into t1 (c1, c2, c3, c4) values (28, 3,18,18); + +insert into t3 (c1, c2, c3, c4) values (1, 1, 1, 1); +insert into t3 (c1, c2, c3, c4) values (2, 2, 2, 2); +insert into t3 (c1, c2, c3, c4) values (12,9, 3, 3); +insert into t3 (c1, c2, c3, c4) values (4, 3, 4, 4); +insert into t3 (c1, c2, c3, c4) values (3, 3, 5, 5); +insert into t3 (c1, c2, c3, c4) values (9, 10,6, 6); +insert into t3 (c1, c2, c3, c4) values (7, 4, 7, 7); +insert into t3 (c1, c2, c3, c4) values (6, 7, 8, 8); + +insert into t3 (c1, c2, c3, c4) values (18, 1,9, 9); +insert into t3 (c1, c2, c3, c4) values (19, 2,10,10); +insert into t3 (c1, c2, c3, c4) values (20, 3,11,11); +insert into t3 (c1, c2, c3, c4) values (21, 5,12,12); +insert into t3 (c1, c2, c3, c4) values (22, 7,13,13); +insert into t3 (c1, c2, c3, c4) values (23, 7,14,14); +insert into t3 (c1, c2, c3, c4) values (24, 7,15,15); +insert into t3 (c1, c2, c3, c4) values (25, 7,16,16); +insert into t3 (c1, c2, c3, c4) values (26, 9,17,17); +insert into t3 (c1, c2, c3, c4) values (28, 3,18,18); + +select /*+ no_rewrite*/ * from t1 where exists (select /*+no_unnest */ 1 from t3 where t1.c1 > t3.c3 and t3.c4 < 100 limit 1) ;