From 6bfeace10b8e5efd7dcda89ddc287d693b844dec Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 19 Jul 2018 17:09:24 +0400 Subject: [PATCH] MDEV-15759 Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant --- mysql-test/main/type_bit.result | 18 ++++++++++++++++++ mysql-test/main/type_bit.test | 18 ++++++++++++++++++ mysql-test/main/type_int.result | 12 ++++++++++++ mysql-test/main/type_int.test | 11 +++++++++++ mysql-test/main/update.result | 4 ++-- sql/opt_range.cc | 5 +++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/type_bit.result b/mysql-test/main/type_bit.result index eeedc501dc4..12fe302a5be 100644 --- a/mysql-test/main/type_bit.result +++ b/mysql-test/main/type_bit.result @@ -849,3 +849,21 @@ DROP TABLE IF EXISTS t1; # # End of 10.2 tests # +# +# Start of 10.4 tests +# +# +# MDEV-15759 Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant +# +CREATE TABLE t1 (a BIT(7), KEY(a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +EXPLAIN SELECT * FROM t1 WHERE a=200; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +EXPLAIN SELECT * FROM t1 WHERE a<=>200; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +DROP TABLE t1; +# +# End of 10.4 tests +# diff --git a/mysql-test/main/type_bit.test b/mysql-test/main/type_bit.test index 04db1511833..c6d5a1f2f05 100644 --- a/mysql-test/main/type_bit.test +++ b/mysql-test/main/type_bit.test @@ -483,3 +483,21 @@ DROP TABLE IF EXISTS t1; --echo # End of 10.2 tests --echo # +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-15759 Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant +--echo # + +CREATE TABLE t1 (a BIT(7), KEY(a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +EXPLAIN SELECT * FROM t1 WHERE a=200; +EXPLAIN SELECT * FROM t1 WHERE a<=>200; +DROP TABLE t1; + + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/main/type_int.result b/mysql-test/main/type_int.result index 9fe045172f8..a3a702609c9 100644 --- a/mysql-test/main/type_int.result +++ b/mysql-test/main/type_int.result @@ -268,5 +268,17 @@ Warnings: Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1 DROP TABLE t1; # +# MDEV-15759 Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant +# +CREATE TABLE t1 (a TINYINT, KEY(a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +EXPLAIN SELECT * FROM t1 WHERE a=200; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +EXPLAIN SELECT * FROM t1 WHERE a<=>200; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +DROP TABLE t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_int.test b/mysql-test/main/type_int.test index b3fe250d1b8..8d56f94388c 100644 --- a/mysql-test/main/type_int.test +++ b/mysql-test/main/type_int.test @@ -196,6 +196,17 @@ EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE ?+a<=>1+a' USING 1; EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1+a<=>?+a' USING 1; DROP TABLE t1; +--echo # +--echo # MDEV-15759 Expect "Impossible WHERE" for indexed_int_column=out_of_range_int_constant +--echo # + +CREATE TABLE t1 (a TINYINT, KEY(a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +EXPLAIN SELECT * FROM t1 WHERE a=200; +EXPLAIN SELECT * FROM t1 WHERE a<=>200; +DROP TABLE t1; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/update.result b/mysql-test/main/update.result index 73ebb73e313..ccf2f4451ea 100644 --- a/mysql-test/main/update.result +++ b/mysql-test/main/update.result @@ -447,7 +447,7 @@ UPDATE t1 SET user_id=null WHERE request_id=9999999999999; show status like '%Handler_read%'; Variable_name Value Handler_read_first 0 -Handler_read_key 3 +Handler_read_key 2 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 @@ -459,7 +459,7 @@ UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999; show status like '%Handler_read%'; Variable_name Value Handler_read_first 0 -Handler_read_key 3 +Handler_read_key 2 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 diff --git a/sql/opt_range.cc b/sql/opt_range.cc index d49ee33aafc..fe494fc4b22 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -8114,6 +8114,11 @@ Item_bool_func::get_mm_leaf(RANGE_OPT_PARAM *param, */ else if (err == 1 && field->result_type() == INT_RESULT) { + if (type == EQ_FUNC || type == EQUAL_FUNC) // e.g. tinyint = 200 + { + tree= new (alloc) SEL_ARG_IMPOSSIBLE(field); + goto end; + } if (type == LT_FUNC && (value->val_int() > 0)) type= LE_FUNC; else if (type == GT_FUNC &&