Commit 103b1df5 authored by Igor Babaev's avatar Igor Babaev

MDEV-17222 Reproducible server crash in String_list::append_str or

           in Field_iterator_table::create_item

When IN predicate is converted to IN subquery we have to ensure that
any item from the select list of the subquery has some name and this name
is unique across the select list.
This was not guaranteed by the code before the patch for MDEV-17222.
If the name of an item of the select list was not set, and this happened
for binary constants, then the server crashed. If the first row in the IN
list contained the same constant in two different positions then the server
returned an error message.
This was fixed by providing all constants in the first row of the IN list
with generated names.
parent 74387028
This diff is collapsed.
......@@ -320,7 +320,7 @@ drop table t1, t2, t3;
set @@in_predicate_conversion_threshold= default;
--echo #
--echo # MDEV-14947: conversion of TVC with only NULL values
--echo # MDEV-14947: conversion to TVC with only NULL values
--echo #
CREATE TABLE t1 (i INT);
......@@ -342,7 +342,7 @@ SET in_predicate_conversion_threshold= default;
DROP TABLE t1;
--echo #
--echo # MDEV-14835: conversion of TVC with BIGINT or YEAR values
--echo # MDEV-14835: conversion to TVC with BIGINT or YEAR values
--echo #
SET @@in_predicate_conversion_threshold= 2;
......@@ -360,3 +360,39 @@ SELECT * FROM t2 WHERE y IN ('2009','2011');
DROP TABLE t1,t2;
SET @@in_predicate_conversion_threshold= default;
--echo #
--echo # MDEV-17222: conversion to TVC with no names for constants
--echo # conversion to TVC with the same constants in the first row
--echo #
SET @@in_predicate_conversion_threshold= 2;
CREATE TABLE t1 (f BINARY(16)) ENGINE=MYISAM;
INSERT INTO t1 VALUES
(x'BAE56AF2B1C2397D99D58E2A06761DDB'), (x'9B9B698BCCB939EE8F1EA56C1A2E5DAA'),
(x'A0A1C4FE39A239BABD3E0D8985E6BEA5');
SELECT COUNT(*) FROM t1 WHERE f IN
(x'9B9B698BCCB939EE8F1EA56C1A2E5DAA', x'E2362DBAB5EA30B5804917A0A7D881E2',
x'B78B2EEAD13635088D93EA3309E24802', x'BAE56AF2B1C2397D99D58E2A06761DDB');
CREATE TABLE t2 (f1 BINARY(16), f2 BINARY(16)) ENGINE=MYISAM;
INSERT INTO t2 VALUES
(x'55FB3B14D6B83D39859E42533906350D', x'00F3458C47FA39DDBEAD918A13F8342E'),
(x'86052C062AAF368D84247ED0F6346A70', x'BF5C35045C6037C79E11026ABB9A3A4E');
SELECT COUNT(*) FROM t2 WHERE (f1,f2) IN
((x'9B9B698BCCB939EE8F1EA56C1A2E5DAA', x'E2362DBAB5EA30B5804917A0A7D881E2'),
(x'B78B2EEAD13635088D93EA3309E24802', x'BAE56AF2B1C2397D99D58E2A06761DDB'),
(x'55FB3B14D6B83D39859E42533906350D', x'00F3458C47FA39DDBEAD918A13F8342E'),
(x'1606014E7C4A312F83EDC9D91BBFCACA', x'33F6068E56FD3A1D8326517F0D81CB5A'));
CREATE TABLE t3 (f1 int, f2 int) ENGINE=MYISAM;
INSERT INTO t3 VALUES (2,5), (2,3), (1,2), (7,8), (1,1);
SELECT * FROM t3 WHERE (f1,f2) IN ((2, 2), (1, 2), (3, 5), (1, 1));
DROP TABLE t1,t2,t3;
SET @@in_predicate_conversion_threshold= default;
......@@ -470,6 +470,7 @@ bool Item_func_in::create_value_list_for_tvc(THD *thd,
for (uint i=1; i < arg_count; i++)
{
char col_name[8];
List<Item> *tvc_value;
if (!(tvc_value= new (thd->mem_root) List<Item>()))
return true;
......@@ -480,13 +481,27 @@ bool Item_func_in::create_value_list_for_tvc(THD *thd,
for (uint j=0; j < row_list->cols(); j++)
{
if (i == 1)
{
sprintf(col_name, "_col_%i", j+1);
row_list->element_index(j)->set_name(thd, col_name, strlen(col_name),
thd->charset());
}
if (tvc_value->push_back(row_list->element_index(j),
thd->mem_root))
return true;
}
}
else if (tvc_value->push_back(args[i]->real_item()))
return true;
else
{
if (i == 1)
{
sprintf(col_name, "_col_%i", 1);
args[i]->set_name(thd, col_name, strlen(col_name), thd->charset());
}
if (tvc_value->push_back(args[i]->real_item()))
return true;
}
if (values->push_back(tvc_value, thd->mem_root))
return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment