From f3d1ca1b3426684680e30d7929eeb071b9704f29 Mon Sep 17 00:00:00 2001 From: lijiachen Date: Thu, 19 Dec 2024 10:56:32 +0800 Subject: [PATCH] fix partly pushdown cond or/and --- .../suite/ctc/r/ctc_cond_pushdown.result | 127 +++++++++++++++++- .../ctc/r/ctc_cond_pushdown_explain.result | 67 ++++++++- mysql-test/suite/ctc/t/ctc_cond_pushdown.test | 23 ++-- .../ctc/t/ctc_cond_pushdown_explain.test | 23 ++-- storage/ctc/ctc_util.cc | 2 +- 5 files changed, 223 insertions(+), 19 deletions(-) diff --git a/mysql-test/suite/ctc/r/ctc_cond_pushdown.result b/mysql-test/suite/ctc/r/ctc_cond_pushdown.result index 7cf7ded..ccc5617 100644 --- a/mysql-test/suite/ctc/r/ctc_cond_pushdown.result +++ b/mysql-test/suite/ctc/r/ctc_cond_pushdown.result @@ -1812,6 +1812,26 @@ a b 2 1 select * from t16 where a = NULL; a b +select * from t16 where a is true; +a b +1 2 +2 1 +1 NULL +select * from t16 where a is NOT true; +a b +NULL NULL +NULL 1 +select * from t16 where a like 1; +a b +1 2 +1 NULL +select * from t16 where a not like 1; +a b +2 1 +select * from t16 where a like NULL; +a b +select * from t16 where a NOT like NULL; +a b select * from t16 where a + b > 1; a b 1 2 @@ -1866,28 +1886,133 @@ select * from t16 where a + (-2) >= 0; a b 2 1 create table t17 (a int, b int GENERATED ALWAYS AS (a + 1)); -insert into t17(a) values (NULL),(1),(2); +insert into t17(a) values (NULL),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); select * from t17 where a > 1; a b 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 select * from t17 where b > 1; a b 1 2 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 select * from t17 where (a > 1) AND (b > 1); a b 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 select * from t17 where (a > 1) OR (b > 1); a b 1 2 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 select * from t17 where ((a > 1) AND (b > 1)) = 1; a b 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 select * from t17 where ((a > 1) OR (b > 1)) = 1; a b 1 2 2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 +select * from t17 where (a < 5) AND (a > 1) AND (b > 1); +a b +2 3 +3 4 +4 5 +select * from t17 where (a < 5) AND (a > 1) OR (b > 1); +a b +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 +select * from t17 where (a < 5) AND ((a > 1) OR (b > 1)); +a b +1 2 +2 3 +3 4 +4 5 +select * from t17 where (a < 2) OR (a > 8) OR (b > 1); +a b +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 +select * from t17 where (a < 2) OR (a > 8) AND (b > 1); +a b +1 2 +9 10 +10 11 +select * from t17 where ((a < 2) OR (a > 8)) AND (b > 1); +a b +1 2 +9 10 +10 11 +select * from t17 where (a < 2) OR ((a > 8) OR (b > 1)); +a b +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 +10 11 CREATE TABLE t18(c1 int, c2 int, key(c1,c2)); INSERT INTO t18 VALUES (94,94),(64,64),(69,69),(97,97); select * from t18; diff --git a/mysql-test/suite/ctc/r/ctc_cond_pushdown_explain.result b/mysql-test/suite/ctc/r/ctc_cond_pushdown_explain.result index b329421..182a8a1 100644 --- a/mysql-test/suite/ctc/r/ctc_cond_pushdown_explain.result +++ b/mysql-test/suite/ctc/r/ctc_cond_pushdown_explain.result @@ -1139,6 +1139,36 @@ id select_type table partitions type possible_keys key key_len ref rows filtered 1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using pushed condition (`test`.`t16`.`a` = NULL) Warnings: Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where (`test`.`t16`.`a` = NULL) +explain select * from t16 where a is true; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where ((0 <> `test`.`t16`.`a`) is true) +explain select * from t16 where a is NOT true; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where ((0 <> `test`.`t16`.`a`) is not true) +explain select * from t16 where a like 1; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 33.33 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where (`test`.`t16`.`a` like 1) +explain select * from t16 where a not like 1; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 66.67 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where (not((`test`.`t16`.`a` like 1))) +explain select * from t16 where a like NULL; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 33.33 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where (`test`.`t16`.`a` like NULL) +explain select * from t16 where a NOT like NULL; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 66.67 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where (not((`test`.`t16`.`a` like NULL))) explain select * from t16 where a + b > 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t16 NULL ALL NULL NULL NULL NULL 3 100.00 Using where; Using pushed condition ((`test`.`t16`.`a` + `test`.`t16`.`b`) > 1) @@ -1217,7 +1247,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered Warnings: Note 1003 /* select#1 */ select `test`.`t16`.`a` AS `a`,`test`.`t16`.`b` AS `b` from `test`.`t16` where ((`test`.`t16`.`a` + (-(2))) >= 0) create table t17 (a int, b int GENERATED ALWAYS AS (a + 1)); -insert into t17(a) values (NULL),(1),(2); +insert into t17(a) values (NULL),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); explain select * from t17 where a > 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using pushed condition (`test`.`t17`.`a` > 1) @@ -1248,6 +1278,41 @@ id select_type table partitions type possible_keys key key_len ref rows filtered 1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where (((`test`.`t17`.`a` > 1) or (`test`.`t17`.`b` > 1)) = 1) +explain select * from t17 where (a < 5) AND (a > 1) AND (b > 1); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using pushed condition ((`test`.`t17`.`a` < 5) and (`test`.`t17`.`a` > 1)) +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where ((`test`.`t17`.`a` < 5) and (`test`.`t17`.`a` > 1) and (`test`.`t17`.`b` > 1)) +explain select * from t17 where (a < 5) AND (a > 1) OR (b > 1); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 40.74 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where (((`test`.`t17`.`a` < 5) and (`test`.`t17`.`a` > 1)) or (`test`.`t17`.`b` > 1)) +explain select * from t17 where (a < 5) AND ((a > 1) OR (b > 1)); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using pushed condition (`test`.`t17`.`a` < 5) +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where ((`test`.`t17`.`a` < 5) and ((`test`.`t17`.`a` > 1) or (`test`.`t17`.`b` > 1))) +explain select * from t17 where (a < 2) OR (a > 8) OR (b > 1); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 70.37 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where ((`test`.`t17`.`a` < 2) or (`test`.`t17`.`a` > 8) or (`test`.`t17`.`b` > 1)) +explain select * from t17 where (a < 2) OR (a > 8) AND (b > 1); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 40.74 Using where; Using pushed condition ((`test`.`t17`.`a` < 2) or (`test`.`t17`.`a` > 8)) +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where ((`test`.`t17`.`a` < 2) or ((`test`.`t17`.`a` > 8) and (`test`.`t17`.`b` > 1))) +explain select * from t17 where ((a < 2) OR (a > 8)) AND (b > 1); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using pushed condition ((`test`.`t17`.`a` < 2) or (`test`.`t17`.`a` > 8)) +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where (((`test`.`t17`.`a` < 2) or (`test`.`t17`.`a` > 8)) and (`test`.`t17`.`b` > 1)) +explain select * from t17 where (a < 2) OR ((a > 8) OR (b > 1)); +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t17 NULL ALL NULL NULL NULL NULL 3 70.37 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t17`.`a` AS `a`,`test`.`t17`.`b` AS `b` from `test`.`t17` where ((`test`.`t17`.`a` < 2) or (`test`.`t17`.`a` > 8) or (`test`.`t17`.`b` > 1)) CREATE TABLE t18(c1 int, c2 int, key(c1,c2)); INSERT INTO t18 VALUES (94,94),(64,64),(69,69),(97,97); explain select * from t18; diff --git a/mysql-test/suite/ctc/t/ctc_cond_pushdown.test b/mysql-test/suite/ctc/t/ctc_cond_pushdown.test index 3daf59f..f4c93f1 100644 --- a/mysql-test/suite/ctc/t/ctc_cond_pushdown.test +++ b/mysql-test/suite/ctc/t/ctc_cond_pushdown.test @@ -551,15 +551,15 @@ select * from t16 where a = 2; select * from t16 where a = NULL; ## unsupported IS / IS NOT -#select * from t16 where a is true; -#select * from t16 where a is NOT true; +select * from t16 where a is true; +select * from t16 where a is NOT true; ## unsupported LIKE / NOT -#select * from t16 where a like 1; -#select * from t16 where a not like 1; -#select * from t16 where a like NULL; -#select * from t16 where a NOT like NULL; +select * from t16 where a like 1; +select * from t16 where a not like 1; +select * from t16 where a like NULL; +select * from t16 where a NOT like NULL; select * from t16 where a + b > 1; select * from t16 where 1 < a; @@ -582,13 +582,20 @@ select * from t16 where a <=> NULL = 1; select * from t16 where a + (-2) >= 0; create table t17 (a int, b int GENERATED ALWAYS AS (a + 1)); -insert into t17(a) values (NULL),(1),(2); +insert into t17(a) values (NULL),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); select * from t17 where a > 1; select * from t17 where b > 1; select * from t17 where (a > 1) AND (b > 1); select * from t17 where (a > 1) OR (b > 1); select * from t17 where ((a > 1) AND (b > 1)) = 1; select * from t17 where ((a > 1) OR (b > 1)) = 1; +select * from t17 where (a < 5) AND (a > 1) AND (b > 1); +select * from t17 where (a < 5) AND (a > 1) OR (b > 1); +select * from t17 where (a < 5) AND ((a > 1) OR (b > 1)); +select * from t17 where (a < 2) OR (a > 8) OR (b > 1); +select * from t17 where (a < 2) OR (a > 8) AND (b > 1); +select * from t17 where ((a < 2) OR (a > 8)) AND (b > 1); +select * from t17 where (a < 2) OR ((a > 8) OR (b > 1)); CREATE TABLE t18(c1 int, c2 int, key(c1,c2)); INSERT INTO t18 VALUES (94,94),(64,64),(69,69),(97,97); @@ -632,4 +639,4 @@ execute stmt1 using @arg2; set @arg3 = 'a'; execute stmt1 using @arg3; -drop table tb_cache; \ No newline at end of file +drop table tb_cache; diff --git a/mysql-test/suite/ctc/t/ctc_cond_pushdown_explain.test b/mysql-test/suite/ctc/t/ctc_cond_pushdown_explain.test index d82b265..429a448 100644 --- a/mysql-test/suite/ctc/t/ctc_cond_pushdown_explain.test +++ b/mysql-test/suite/ctc/t/ctc_cond_pushdown_explain.test @@ -341,15 +341,15 @@ explain select * from t16 where a = 2; explain select * from t16 where a = NULL; ## unsupported IS / IS NOT -#explain select * from t16 where a is true; -#explain select * from t16 where a is NOT true; +explain select * from t16 where a is true; +explain select * from t16 where a is NOT true; ## unsupported LIKE / NOT -#explain select * from t16 where a like 1; -#explain select * from t16 where a not like 1; -#explain select * from t16 where a like NULL; -#explain select * from t16 where a NOT like NULL; +explain select * from t16 where a like 1; +explain select * from t16 where a not like 1; +explain select * from t16 where a like NULL; +explain select * from t16 where a NOT like NULL; explain select * from t16 where a + b > 1; explain select * from t16 where 1 < a; @@ -372,13 +372,20 @@ explain select * from t16 where a <=> NULL = 1; explain select * from t16 where a + (-2) >= 0; create table t17 (a int, b int GENERATED ALWAYS AS (a + 1)); -insert into t17(a) values (NULL),(1),(2); +insert into t17(a) values (NULL),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); explain select * from t17 where a > 1; explain select * from t17 where b > 1; explain select * from t17 where (a > 1) AND (b > 1); explain select * from t17 where (a > 1) OR (b > 1); explain select * from t17 where ((a > 1) AND (b > 1)) = 1; explain select * from t17 where ((a > 1) OR (b > 1)) = 1; +explain select * from t17 where (a < 5) AND (a > 1) AND (b > 1); +explain select * from t17 where (a < 5) AND (a > 1) OR (b > 1); +explain select * from t17 where (a < 5) AND ((a > 1) OR (b > 1)); +explain select * from t17 where (a < 2) OR (a > 8) OR (b > 1); +explain select * from t17 where (a < 2) OR (a > 8) AND (b > 1); +explain select * from t17 where ((a < 2) OR (a > 8)) AND (b > 1); +explain select * from t17 where (a < 2) OR ((a > 8) OR (b > 1)); CREATE TABLE t18(c1 int, c2 int, key(c1,c2)); INSERT INTO t18 VALUES (94,94),(64,64),(69,69),(97,97); @@ -408,4 +415,4 @@ execute stmt1 using @arg2; set @arg3 = 'a'; execute stmt1 using @arg3; -drop table tb_cache; \ No newline at end of file +drop table tb_cache; diff --git a/storage/ctc/ctc_util.cc b/storage/ctc/ctc_util.cc index 6736836..a3c2c4b 100644 --- a/storage/ctc/ctc_util.cc +++ b/storage/ctc/ctc_util.cc @@ -1120,7 +1120,7 @@ void cond_push_boolean_term(Item *term, Item *&pushed_cond, Item *&remainder_con while ((operand = li++)) { Item *pushed = nullptr, *remainder = nullptr; cond_push_term(operand, pushed, remainder, cond->functype()); - if (remainder != nullptr && !is_and_condition) { + if (pushed == nullptr && !is_and_condition) { remain_all_cond_item(cond, pushed_cond, remainder_cond); return; } -- Gitee