Skip to content

Commit 07c0bac

Browse files
committed
Fixed mdev-14947 Assertion `0' fails in Field_null::can_optimize_keypart_ref
when number of NULLs in IN list reaches in_predicate_conversion_threshold The bug was fixed by removing an assertion that had been set in order just to test whether the code could be ever executed.
1 parent e15f4af commit 07c0bac

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

mysql-test/r/opt_tvc.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,27 @@ Warnings:
614614
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`c`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`c`),(`test`.`t2`.`a`,`test`.`t2`.`c`) in ( <materialize> (/* select#2 */ select `tvc_0`.`1`,`tvc_0`.`2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`1` and `test`.`t2`.`c` = `<subquery2>`.`2`))))
615615
drop table t1, t2, t3;
616616
set @@in_predicate_conversion_threshold= default;
617+
#
618+
# MDEV-14947: conversion of TVC with only NULL values
619+
#
620+
CREATE TABLE t1 (i INT);
621+
INSERT INTO t1 VALUES (3), (2), (7);
622+
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
623+
i
624+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
625+
id select_type table type possible_keys key key_len ref rows filtered Extra
626+
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
627+
Warnings:
628+
Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` where `test`.`t1`.`i` in (NULL,NULL,NULL,NULL,NULL)
629+
SET in_predicate_conversion_threshold= 5;
630+
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
631+
i
632+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
633+
id select_type table type possible_keys key key_len ref rows filtered Extra
634+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
635+
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
636+
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
637+
Warnings:
638+
Note 1003 /* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join ((values (NULL),(NULL),(NULL),(NULL),(NULL)) `tvc_0`) where `test`.`t1`.`i` = `tvc_0`.`NULL`
639+
SET in_predicate_conversion_threshold= default;
640+
DROP TABLE t1;

mysql-test/t/opt_tvc.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,25 @@ eval explain extended $query;
318318
drop table t1, t2, t3;
319319

320320
set @@in_predicate_conversion_threshold= default;
321+
322+
--echo #
323+
--echo # MDEV-14947: conversion of TVC with only NULL values
324+
--echo #
325+
326+
CREATE TABLE t1 (i INT);
327+
INSERT INTO t1 VALUES (3), (2), (7);
328+
329+
let $q=
330+
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
331+
332+
eval $q;
333+
eval EXPLAIN EXTENDED $q;
334+
335+
SET in_predicate_conversion_threshold= 5;
336+
337+
eval $q;
338+
eval EXPLAIN EXTENDED $q;
339+
340+
SET in_predicate_conversion_threshold= default;
341+
342+
DROP TABLE t1;

sql/field.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,13 +2372,11 @@ class Field_null :public Field_str {
23722372
bool can_optimize_keypart_ref(const Item_bool_func *cond,
23732373
const Item *item) const
23742374
{
2375-
DBUG_ASSERT(0);
23762375
return false;
23772376
}
23782377
bool can_optimize_group_min_max(const Item_bool_func *cond,
23792378
const Item *const_item) const
23802379
{
2381-
DBUG_ASSERT(0);
23822380
return false;
23832381
}
23842382
};

0 commit comments

Comments
 (0)