Skip to content

Commit 9d97e60

Browse files
committed
MDEV-14835 Server crashes in Field_iterator_table::create_item when number of
elements of BIGINT or YEAR type in the IN list reaches in_predicate_conversion_threshold The bug appears at the prepare stage when IN-predicate with the long list of values is converted into IN-subquery. It happens because values in the right operand of the IN-predicate that have BIGINT or YEAR types are converted into the Item_int_with_ref. To fix it in the procedure Item_func_in::create_value_list_for_tvc real_item() is taken for each value in the right operand of the IN-predicate.
1 parent 947efe1 commit 9d97e60

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

mysql-test/r/opt_tvc.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,21 @@ Warnings:
638638
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`
639639
SET in_predicate_conversion_threshold= default;
640640
DROP TABLE t1;
641+
#
642+
# MDEV-14835: conversion of TVC with BIGINT or YEAR values
643+
#
644+
SET @@in_predicate_conversion_threshold= 2;
645+
CREATE TABLE t1 (a BIGINT);
646+
CREATE TABLE t2 (y YEAR);
647+
INSERT INTO t1 VALUES (1), (2), (3);
648+
INSERT INTO t2 VALUES (2009), (2010), (2011);
649+
SELECT * FROM t1 WHERE a IN ('1','5','3');
650+
a
651+
1
652+
3
653+
SELECT * FROM t2 WHERE y IN ('2009','2011');
654+
y
655+
2009
656+
2011
657+
DROP TABLE t1,t2;
658+
SET @@in_predicate_conversion_threshold= default;

mysql-test/t/opt_tvc.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,23 @@ eval EXPLAIN EXTENDED $q;
340340
SET in_predicate_conversion_threshold= default;
341341

342342
DROP TABLE t1;
343+
344+
--echo #
345+
--echo # MDEV-14835: conversion of TVC with BIGINT or YEAR values
346+
--echo #
347+
348+
SET @@in_predicate_conversion_threshold= 2;
349+
350+
CREATE TABLE t1 (a BIGINT);
351+
CREATE TABLE t2 (y YEAR);
352+
353+
INSERT INTO t1 VALUES (1), (2), (3);
354+
INSERT INTO t2 VALUES (2009), (2010), (2011);
355+
356+
SELECT * FROM t1 WHERE a IN ('1','5','3');
357+
358+
SELECT * FROM t2 WHERE y IN ('2009','2011');
359+
360+
DROP TABLE t1,t2;
361+
362+
SET @@in_predicate_conversion_threshold= default;

sql/sql_tvc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ bool Item_func_in::create_value_list_for_tvc(THD *thd,
479479
return true;
480480
}
481481
}
482-
else if (tvc_value->push_back(args[i]))
482+
else if (tvc_value->push_back(args[i]->real_item()))
483483
return true;
484484

485485
if (values->push_back(tvc_value, thd->mem_root))

0 commit comments

Comments
 (0)