diff --git a/mysql-test/main/subselect_nulls.result b/mysql-test/main/subselect_nulls.result index 08982371269fcc8d3632030b03b2566a3b98518a..9d3b7b2cfd50840ac6c78d95154ebad7896b285e 100644 --- a/mysql-test/main/subselect_nulls.result +++ b/mysql-test/main/subselect_nulls.result @@ -1,5 +1,3 @@ -drop table if exists x1; -drop table if exists x2; set @tmp_subselect_nulls=@@optimizer_switch; set optimizer_switch='semijoin=off'; create table x1(k int primary key, d1 int, d2 int); @@ -115,9 +113,44 @@ k d1 d2 set optimizer_switch= @tmp_subselect_nulls; drop table x1; drop table x2; +# +# MDEV-7339 Server crashes in Item_func_trig_cond::val_int +# select (select 1, 2) in (select 3, 4); (select 1, 2) in (select 3, 4) 0 select (select NULL, NULL) in (select 3, 4); (select NULL, NULL) in (select 3, 4) NULL +# +# End of 5.5 tests +# +# +# MDEV-32555 wrong result with an index and a partially null-rejecting condition +# +create table t1 (a int primary key); +insert t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 ( +b int not null, +c int default null, +d int not null, +e int not null, +unique key (d,b,c) +); +insert t2 values (1,null,1,1),(1,null,2,2),(1,null,3,3),(1,null,4,4),(2,null,1,2),(3,null,1,3),(4,null,2,2),(4,null,1,4); +select ( +select sum(t2_.e) from t2 t2_ where t2_.b = a and t2_.c <=> t2.c and t2_.d = 1 +) x from t2 left join t1 on a = b; +x +1 +2 +3 +4 +1 +4 +1 +1 +drop table t1, t2; +# +# End of 10.10 tests +# diff --git a/mysql-test/main/subselect_nulls.test b/mysql-test/main/subselect_nulls.test index 3e7b2189ed54d63aee7aa92ea83aa4243dd699ea..68575eca9e73a7e05cc279a29f8455a6c61243c9 100644 --- a/mysql-test/main/subselect_nulls.test +++ b/mysql-test/main/subselect_nulls.test @@ -1,10 +1,3 @@ -# Initialize tables for the test - ---disable_warnings -drop table if exists x1; -drop table if exists x2; ---enable_warnings - set @tmp_subselect_nulls=@@optimizer_switch; set optimizer_switch='semijoin=off'; @@ -98,8 +91,39 @@ set optimizer_switch= @tmp_subselect_nulls; drop table x1; drop table x2; -# -# MDEV-7339 Server crashes in Item_func_trig_cond::val_int -# +--echo # +--echo # MDEV-7339 Server crashes in Item_func_trig_cond::val_int +--echo # select (select 1, 2) in (select 3, 4); select (select NULL, NULL) in (select 3, 4); + +--echo # +--echo # End of 5.5 tests +--echo # + +--echo # +--echo # MDEV-32555 wrong result with an index and a partially null-rejecting condition +--echo # + +create table t1 (a int primary key); +insert t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t2 ( + b int not null, + c int default null, + d int not null, + e int not null, + unique key (d,b,c) +); + +insert t2 values (1,null,1,1),(1,null,2,2),(1,null,3,3),(1,null,4,4),(2,null,1,2),(3,null,1,3),(4,null,2,2),(4,null,1,4); + +select ( + select sum(t2_.e) from t2 t2_ where t2_.b = a and t2_.c <=> t2.c and t2_.d = 1 +) x from t2 left join t1 on a = b; + +drop table t1, t2; + +--echo # +--echo # End of 10.10 tests +--echo # diff --git a/sql/sql_expression_cache.cc b/sql/sql_expression_cache.cc index 69d85f3343d46fad011815485a632e455cda1967..8681e08e014db31d4d5ff122ff2c540aa56330de 100644 --- a/sql/sql_expression_cache.cc +++ b/sql/sql_expression_cache.cc @@ -151,6 +151,7 @@ void Expression_cache_tmptable::init() } cache_table->s->keys= 1; ref.null_rejecting= 1; + ref.const_ref_part_map= 0; ref.disable_cache= FALSE; ref.has_record= 0; ref.use_count= 0; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4fadd2b433dec6899ec3fc5d1b1b58bf7c87a5b7..4b053d3d7420674e1d73cee7f83881a8aede0105 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -26078,12 +26078,15 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref) enum_check_fields org_count_cuted_fields= thd->count_cuted_fields; MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->write_set); bool result= 0; + key_part_map map= 1; thd->count_cuted_fields= CHECK_FIELD_IGNORE; - for (store_key **copy=ref->key_copy ; *copy ; copy++) + for (store_key **copy=ref->key_copy ; *copy ; copy++, map <<= 1) { + while (map & ref->const_ref_part_map) // skip const ref parts + map <<= 1; // no store_key objects for them if ((*copy)->copy(thd) & 1 || - (ref->null_rejecting && (*copy)->null_key)) + ((ref->null_rejecting & map) && (*copy)->null_key)) { result= 1; break;