Skip to content

Commit

Permalink
Fixed mdev-14947 Assertion `0' fails in Field_null::can_optimize_keyp…
Browse files Browse the repository at this point in the history
…art_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.
  • Loading branch information
igorbabaev committed Jan 19, 2018
1 parent e15f4af commit 07c0bac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
24 changes: 24 additions & 0 deletions mysql-test/r/opt_tvc.result
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,27 @@ Warnings:
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`))))
drop table t1, t2, t3;
set @@in_predicate_conversion_threshold= default;
#
# MDEV-14947: conversion of TVC with only NULL values
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (3), (2), (7);
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
i
EXPLAIN EXTENDED SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` where `test`.`t1`.`i` in (NULL,NULL,NULL,NULL,NULL)
SET in_predicate_conversion_threshold= 5;
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
i
EXPLAIN EXTENDED SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
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`
SET in_predicate_conversion_threshold= default;
DROP TABLE t1;
22 changes: 22 additions & 0 deletions mysql-test/t/opt_tvc.test
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,25 @@ eval explain extended $query;
drop table t1, t2, t3;

set @@in_predicate_conversion_threshold= default;

--echo #
--echo # MDEV-14947: conversion of TVC with only NULL values
--echo #

CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (3), (2), (7);

let $q=
SELECT * FROM t1 WHERE i IN (NULL, NULL, NULL, NULL, NULL);

eval $q;
eval EXPLAIN EXTENDED $q;

SET in_predicate_conversion_threshold= 5;

eval $q;
eval EXPLAIN EXTENDED $q;

SET in_predicate_conversion_threshold= default;

DROP TABLE t1;
2 changes: 0 additions & 2 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -2372,13 +2372,11 @@ class Field_null :public Field_str {
bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(0);
return false;
}
bool can_optimize_group_min_max(const Item_bool_func *cond,
const Item *const_item) const
{
DBUG_ASSERT(0);
return false;
}
};
Expand Down

0 comments on commit 07c0bac

Please sign in to comment.