Skip to content

Commit bdae8bb

Browse files
committed
MDEV-24675 Server crash when table value constructor uses a subselect
This patch actually fixes the bug MDEV-24675 and the bug MDEV-24618: Assertion failure when TVC uses a row in the context expecting scalar value The cause of these bugs is the same wrong call of the function that fixes value expressions in the value list of a table value constructor. The assertion failure happened when an expression in the value list is of the row type. In this case an error message was expected, but it was not issued because the function fix_fields_if_needed() was called for to check fields of value expressions in a TVC instead of the function fix_fields_if_needed_for_scalar() that would also check that the value expressions are are of a scalar type. The first bug happened when a table value expression used an expression returned by single-row subselect. In this case the call of the fix_fields_if_needed_for_scalar virtual function must be provided with and address to which the single-row subselect has to be attached. Test cases were added for each of the bugs. Approved by Oleksandr Byelkin <sanja@mariadb.com>
1 parent 21809f9 commit bdae8bb

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

mysql-test/main/table_value_constr.result

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,3 +2621,57 @@ EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
26212621
ERROR HY000: 'ignore' is not allowed in this context
26222622
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
26232623
ERROR HY000: 'default' is not allowed in this context
2624+
#
2625+
# MDEV-24675: TVC using subqueries
2626+
#
2627+
values((select 1));
2628+
(select 1)
2629+
1
2630+
values (2), ((select 1));
2631+
2
2632+
2
2633+
1
2634+
values ((select 1)), (2), ((select 3));
2635+
(select 1)
2636+
1
2637+
2
2638+
3
2639+
values ((select 1), 2), (3,4), (5, (select 6));
2640+
(select 1) 2
2641+
1 2
2642+
3 4
2643+
5 6
2644+
create table t1 (a int, b int);
2645+
insert into t1 values (1,3), (2,3), (3,2), (1,2);
2646+
values((select max(a) from t1));
2647+
(select max(a) from t1)
2648+
3
2649+
values((select min(b) from t1));
2650+
(select min(b) from t1)
2651+
2
2652+
values ((select max(a) from t1), (select min(b) from t1));
2653+
(select max(a) from t1) (select min(b) from t1)
2654+
3 2
2655+
values((select * from (select max(b) from t1) as t));
2656+
(select * from (select max(b) from t1) as t)
2657+
3
2658+
drop table t1;
2659+
#
2660+
# MDEV-24618: TVC contains extra parenthesis for row expressions
2661+
# in value list
2662+
#
2663+
create table t1 (a int, b int);
2664+
insert into t1 values (1,3), (2,3);
2665+
insert into t1 values ((5,4));
2666+
ERROR 21000: Operand should contain 1 column(s)
2667+
values ((1,2));
2668+
ERROR 21000: Operand should contain 1 column(s)
2669+
select * from (values ((1,2))) dt;
2670+
ERROR 21000: Operand should contain 1 column(s)
2671+
values (1,2);
2672+
1 2
2673+
1 2
2674+
values ((select min(a), max(b) from t1));
2675+
ERROR 21000: Operand should contain 1 column(s)
2676+
drop table t1;
2677+
End of 10.3 tests

mysql-test/main/table_value_constr.test

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,3 +1353,52 @@ VALUES (DEFAULT);
13531353
EXECUTE IMMEDIATE 'VALUES (?)' USING IGNORE;
13541354
--error ER_UNKNOWN_ERROR
13551355
EXECUTE IMMEDIATE 'VALUES (?)' USING DEFAULT;
1356+
1357+
--echo #
1358+
--echo # MDEV-24675: TVC using subqueries
1359+
--echo #
1360+
1361+
values((select 1));
1362+
1363+
values (2), ((select 1));
1364+
1365+
values ((select 1)), (2), ((select 3));
1366+
1367+
values ((select 1), 2), (3,4), (5, (select 6));
1368+
1369+
create table t1 (a int, b int);
1370+
insert into t1 values (1,3), (2,3), (3,2), (1,2);
1371+
1372+
values((select max(a) from t1));
1373+
1374+
values((select min(b) from t1));
1375+
1376+
values ((select max(a) from t1), (select min(b) from t1));
1377+
1378+
values((select * from (select max(b) from t1) as t));
1379+
1380+
drop table t1;
1381+
1382+
--echo #
1383+
--echo # MDEV-24618: TVC contains extra parenthesis for row expressions
1384+
--echo # in value list
1385+
--echo #
1386+
1387+
create table t1 (a int, b int);
1388+
insert into t1 values (1,3), (2,3);
1389+
--error ER_OPERAND_COLUMNS
1390+
insert into t1 values ((5,4));
1391+
1392+
--error ER_OPERAND_COLUMNS
1393+
values ((1,2));
1394+
1395+
--error ER_OPERAND_COLUMNS
1396+
select * from (values ((1,2))) dt;
1397+
1398+
values (1,2);
1399+
--error ER_OPERAND_COLUMNS
1400+
values ((select min(a), max(b) from t1));
1401+
1402+
drop table t1;
1403+
1404+
--echo End of 10.3 tests

sql/sql_tvc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool fix_fields_for_tvc(THD *thd, List_iterator_fast<List_item> &li)
4747

4848
while ((lst= li++))
4949
{
50-
List_iterator_fast<Item> it(*lst);
50+
List_iterator<Item> it(*lst);
5151
Item *item;
5252

5353
while ((item= it++))
@@ -59,7 +59,7 @@ bool fix_fields_for_tvc(THD *thd, List_iterator_fast<List_item> &li)
5959
while replacing their values to NAME_CONST()s.
6060
So fix only those that have not been.
6161
*/
62-
if (item->fix_fields_if_needed(thd, 0) ||
62+
if (item->fix_fields_if_needed_for_scalar(thd, it.ref()) ||
6363
item->check_is_evaluable_expression_or_error())
6464
DBUG_RETURN(true);
6565
}

0 commit comments

Comments
 (0)