From f3d1ca1b3426684680e30d7929eeb071b9704f29 Mon Sep 17 00:00:00 2001 From: lijiachen Date: Thu, 19 Dec 2024 10:56:32 +0800 Subject: [PATCH 1/2] 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 From fca15fd184f62dea1f15fa6d5efe2027133d0133 Mon Sep 17 00:00:00 2001 From: qiuyang19960521 Date: Thu, 19 Dec 2024 13:14:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(compile):=20=E7=8B=AC=E7=AB=8B=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E7=AC=A6=E5=8F=B7=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- storage/ctc/CMakeLists.txt | 4 ++-- storage/ctc/ctc_srv.h | 8 -------- storage/ctc/ha_ctc.cc | 6 ------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/storage/ctc/CMakeLists.txt b/storage/ctc/CMakeLists.txt index 90289c4..6703afc 100644 --- a/storage/ctc/CMakeLists.txt +++ b/storage/ctc/CMakeLists.txt @@ -68,14 +68,14 @@ IF (WITH_CANTIAN) ${CTC_SOURCES} STORAGE_ENGINE MANDATORY - LINK_LIBRARIES libzecommon.so libzeclient.so libzeprotocol.so libprotobuf-c.a pcre2-8 ctc_proxy libcantian.so libmessage_queue.so + LINK_LIBRARIES libzecommon.so libzeclient.so libzeprotocol.so libprotobuf-c.a pcre2-8 ctc_proxy libcantian.so ) ELSEIF (NOT WITHOUT_CTC_STORAGE_ENGINE) MYSQL_ADD_PLUGIN(ctc ${CTC_SOURCES} STORAGE_ENGINE MODULE_ONLY - LINK_LIBRARIES libzecommon.so libzeclient.so libzeprotocol.so libprotobuf-c.a pcre2-8 ctc_proxy libcantian.so libmessage_queue.so + LINK_LIBRARIES libzecommon.so libzeclient.so libzeprotocol.so libprotobuf-c.a pcre2-8 ctc_proxy libcantian.so ) ENDIF () ELSE () diff --git a/storage/ctc/ctc_srv.h b/storage/ctc/ctc_srv.h index 6cd3b2e..9918bd9 100644 --- a/storage/ctc/ctc_srv.h +++ b/storage/ctc/ctc_srv.h @@ -233,10 +233,6 @@ typedef struct { int err_code; } ctc_invalidate_broadcast_request; -typedef struct { - int result; -} mysql_init_lib_request; - typedef struct { bool is_key_null; // 该列数据是否为null uint8_t *left_key; // 指向索引查询条件的左值 @@ -348,7 +344,6 @@ enum CTC_FUNC_TYPE { CTC_FUNC_TYPE_GET_MAX_SESSIONS, CTC_FUNC_LOCK_INSTANCE, CTC_FUNC_UNLOCK_INSTANCE, - CTC_FUNC_INIT_MYSQL_LIB, CTC_FUNC_CHECK_TABLE_EXIST, CTC_FUNC_SEARCH_METADATA_SWITCH, CTC_FUNC_QUERY_SHM_USAGE, @@ -615,9 +610,6 @@ typedef struct en_ctcpart_scan_range { int srv_wait_instance_startuped(void); int ctc_alloc_inst_id(uint32_t *inst_id); int ctc_release_inst_id(uint32_t inst_id); -#ifdef WITH_CANTIAN -int init_mysql_lib(void); -#endif int ctc_open_table(ctc_handler_t *tch, const char *table_name, const char *user_name); int ctc_close_table(ctc_handler_t *tch); diff --git a/storage/ctc/ha_ctc.cc b/storage/ctc/ha_ctc.cc index e0844d8..722771d 100644 --- a/storage/ctc/ha_ctc.cc +++ b/storage/ctc/ha_ctc.cc @@ -542,12 +542,6 @@ static int ctc_reg_instance() { CTC_START_TIMEOUT); sleep(1); } -#ifdef WITH_CANTIAN - ret = (ct_errno_t)init_mysql_lib(); - if (ret == CT_SUCCESS) { - ctc_log_system("[CTC_INIT]:ctc reg mysql proxy lib in cantian success"); - } -#endif return convert_ctc_error_code_to_mysql(ret); } -- Gitee