Skip to content

Commit 2ae7054

Browse files
author
Guilhem Bichot
committed
Bug#20729351 ASSERTION FAILED: ITEM_IN->LEFT_EXPR->ELEMENT_INDEX(0)->MAYBE_NULL
A recently added assertion fails. (SELECT NULL IN (NULL) FROM t1 WHERE a) =ANY(SELECT 1 FROM t2): =ANY is identical to IN and is processed with subquery materialization. The left argument is Item_cache wrapping "NULL=NULL"; that equality item has maybe_null=true but the wrapping Item_cache has maybe_null=false, which is inconsistent and causes the problem. Actually, Item_cache starts with null_value=true, so it looks logical to set maybe_null to true unconditionally. An alternative fix would be to: - assume that this initial null_value is never returned (i.e. we never cal val*() before having cached a value) - start with maybe_null=false - set maybe_null=example->maybe_null in setup() - but store() changes "example" and it's too late to change the item_cache's maybe_null at this point. So setting unconditionally looks like the safest choice. About result change in "Note": it is due to nullability.
1 parent 1ffd2ad commit 2ae7054

File tree

5 files changed

+83
-5
lines changed

5 files changed

+83
-5
lines changed

mysql-test/include/subquery_mat.inc

+15
Original file line numberDiff line numberDiff line change
@@ -1577,5 +1577,20 @@ eval $query;
15771577

15781578
DROP TABLE t1,t2;
15791579

1580+
--echo #
1581+
--echo # Bug#20729351 ASSERTION FAILED: ITEM_IN->LEFT_EXPR->ELEMENT_INDEX(0)->MAYBE_NULL
1582+
--echo #
1583+
1584+
CREATE TABLE t1 (a LONGBLOB) ENGINE=INNODB;
1585+
INSERT INTO t1 VALUES ('a'), ('a'), ('a');
1586+
CREATE TABLE t2 (a INT) ENGINE=INNODB;
1587+
INSERT INTO t2 VALUES(1), (1), (1), (1);
1588+
ANALYZE TABLE t1, t2;
1589+
SELECT
1590+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
1591+
ANY(SELECT 1 FROM t2)
1592+
FROM t1;
1593+
DROP TABLE t1, t2;
1594+
15801595
set @@optimizer_switch=@old_opt_switch;
15811596
SET sql_mode = default;

mysql-test/r/subquery_mat.result

+22-1
Original file line numberDiff line numberDiff line change
@@ -2159,11 +2159,32 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
21592159
3 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
21602160
2 SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
21612161
Warnings:
2162-
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where 1 having 1)))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
2162+
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where (<if>(outer_field_is_not_null, ((<cache>(<cache>(1)) = 1) or isnull(1)), true) and <if>(outer_field_is_not_null, ((<cache>(<cache>(2)) = 2) or isnull(2)), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(1)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(2)), true)))))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
21632163
SELECT (SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1) FROM t1;
21642164
(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)
21652165
NULL
21662166
DROP TABLE t1,t2;
2167+
#
2168+
# Bug#20729351 ASSERTION FAILED: ITEM_IN->LEFT_EXPR->ELEMENT_INDEX(0)->MAYBE_NULL
2169+
#
2170+
CREATE TABLE t1 (a LONGBLOB) ENGINE=INNODB;
2171+
INSERT INTO t1 VALUES ('a'), ('a'), ('a');
2172+
CREATE TABLE t2 (a INT) ENGINE=INNODB;
2173+
INSERT INTO t2 VALUES(1), (1), (1), (1);
2174+
ANALYZE TABLE t1, t2;
2175+
Table Op Msg_type Msg_text
2176+
test.t1 analyze status OK
2177+
test.t2 analyze status OK
2178+
SELECT
2179+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2180+
ANY(SELECT 1 FROM t2)
2181+
FROM t1;
2182+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2183+
ANY(SELECT 1 FROM t2)
2184+
NULL
2185+
NULL
2186+
NULL
2187+
DROP TABLE t1, t2;
21672188
set @@optimizer_switch=@old_opt_switch;
21682189
SET sql_mode = default;
21692190
set global innodb_large_prefix=default;

mysql-test/r/subquery_mat_all.result

+22-1
Original file line numberDiff line numberDiff line change
@@ -2160,11 +2160,32 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
21602160
3 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
21612161
2 SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
21622162
Warnings:
2163-
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where 1 having 1)))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
2163+
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where (<if>(outer_field_is_not_null, ((<cache>(<cache>(1)) = 1) or isnull(1)), true) and <if>(outer_field_is_not_null, ((<cache>(<cache>(2)) = 2) or isnull(2)), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(1)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(2)), true)))))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
21642164
SELECT (SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1) FROM t1;
21652165
(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)
21662166
NULL
21672167
DROP TABLE t1,t2;
2168+
#
2169+
# Bug#20729351 ASSERTION FAILED: ITEM_IN->LEFT_EXPR->ELEMENT_INDEX(0)->MAYBE_NULL
2170+
#
2171+
CREATE TABLE t1 (a LONGBLOB) ENGINE=INNODB;
2172+
INSERT INTO t1 VALUES ('a'), ('a'), ('a');
2173+
CREATE TABLE t2 (a INT) ENGINE=INNODB;
2174+
INSERT INTO t2 VALUES(1), (1), (1), (1);
2175+
ANALYZE TABLE t1, t2;
2176+
Table Op Msg_type Msg_text
2177+
test.t1 analyze status OK
2178+
test.t2 analyze status OK
2179+
SELECT
2180+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2181+
ANY(SELECT 1 FROM t2)
2182+
FROM t1;
2183+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2184+
ANY(SELECT 1 FROM t2)
2185+
NULL
2186+
NULL
2187+
NULL
2188+
DROP TABLE t1, t2;
21682189
set @@optimizer_switch=@old_opt_switch;
21692190
SET sql_mode = default;
21702191
set global innodb_large_prefix=default;

mysql-test/r/subquery_mat_none.result

+22-1
Original file line numberDiff line numberDiff line change
@@ -2051,11 +2051,32 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
20512051
3 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
20522052
2 SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
20532053
Warnings:
2054-
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where 1 having 1)))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
2054+
Note 1003 /* select#1 */ select (not(<in_optimizer>((/* select#2 */ select 1,2 from `test`.`t2`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where (<if>(outer_field_is_not_null, ((<cache>(<cache>(1)) = 1) or isnull(1)), true) and <if>(outer_field_is_not_null, ((<cache>(<cache>(2)) = 2) or isnull(2)), true)) having (<if>(outer_field_is_not_null, <cache>(<is_not_null_test>(1)), true) and <if>(outer_field_is_not_null, <cache>(<is_not_null_test>(2)), true)))))) AS `(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)` from `test`.`t1`
20552055
SELECT (SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1) FROM t1;
20562056
(SELECT 1,2 FROM t2) NOT IN (SELECT 1,2 FROM t1)
20572057
NULL
20582058
DROP TABLE t1,t2;
2059+
#
2060+
# Bug#20729351 ASSERTION FAILED: ITEM_IN->LEFT_EXPR->ELEMENT_INDEX(0)->MAYBE_NULL
2061+
#
2062+
CREATE TABLE t1 (a LONGBLOB) ENGINE=INNODB;
2063+
INSERT INTO t1 VALUES ('a'), ('a'), ('a');
2064+
CREATE TABLE t2 (a INT) ENGINE=INNODB;
2065+
INSERT INTO t2 VALUES(1), (1), (1), (1);
2066+
ANALYZE TABLE t1, t2;
2067+
Table Op Msg_type Msg_text
2068+
test.t1 analyze status OK
2069+
test.t2 analyze status OK
2070+
SELECT
2071+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2072+
ANY(SELECT 1 FROM t2)
2073+
FROM t1;
2074+
(SELECT NULL IN (NULL) FROM t1 WHERE a) =
2075+
ANY(SELECT 1 FROM t2)
2076+
NULL
2077+
NULL
2078+
NULL
2079+
DROP TABLE t1, t2;
20592080
set @@optimizer_switch=@old_opt_switch;
20602081
SET sql_mode = default;
20612082
set optimizer_switch=default;

sql/item.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4884,15 +4884,15 @@ class Item_cache: public Item_basic_constant
48844884
value_cached(0)
48854885
{
48864886
fixed= 1;
4887-
null_value= 1;
4887+
maybe_null= null_value= 1;
48884888
}
48894889
Item_cache(enum_field_types field_type_arg):
48904890
example(0), used_table_map(0), cached_field(0),
48914891
cached_field_type(field_type_arg),
48924892
value_cached(0)
48934893
{
48944894
fixed= 1;
4895-
null_value= 1;
4895+
maybe_null= null_value= 1;
48964896
}
48974897

48984898
void set_used_tables(table_map map) { used_table_map= map; }

0 commit comments

Comments
 (0)