Commit 98b3f288 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-14217 [db crash] Recursive CTE when SELECT includes new field

parent 4e34eaf1
......@@ -2881,3 +2881,26 @@ f
2
set standard_compliant_cte=default;
DROP TABLE t;
#
# MDEV-14217 [db crash] Recursive CTE when SELECT includes new field
#
CREATE TEMPORARY TABLE a_tbl (
a VARCHAR(33) PRIMARY KEY,
b VARCHAR(33)
);
INSERT INTO a_tbl VALUES ('block0', 'block0'), ('block1', NULL);
WITH RECURSIVE Q0 AS (
SELECT T0.a, T0.b, 5
FROM a_tbl T0
WHERE b IS NULL
UNION ALL
SELECT T1.a, T1.b
FROM Q0
JOIN a_tbl T1
ON T1.a=Q0.a
) SELECT distinct(Q0.a), Q0.b
FROM Q0;
ERROR 21000: The used SELECT statements have a different number of columns
DROP TABLE a_tbl;
WITH RECURSIVE x AS (SELECT 1,2 UNION ALL SELECT 1 FROM x) SELECT * FROM x;
ERROR 21000: The used SELECT statements have a different number of columns
......@@ -1928,3 +1928,31 @@ set standard_compliant_cte=default;
DROP TABLE t;
--echo #
--echo # MDEV-14217 [db crash] Recursive CTE when SELECT includes new field
--echo #
CREATE TEMPORARY TABLE a_tbl (
a VARCHAR(33) PRIMARY KEY,
b VARCHAR(33)
);
INSERT INTO a_tbl VALUES ('block0', 'block0'), ('block1', NULL);
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
WITH RECURSIVE Q0 AS (
SELECT T0.a, T0.b, 5
FROM a_tbl T0
WHERE b IS NULL
UNION ALL
SELECT T1.a, T1.b
FROM Q0
JOIN a_tbl T1
ON T1.a=Q0.a
) SELECT distinct(Q0.a), Q0.b
FROM Q0;
DROP TABLE a_tbl;
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
WITH RECURSIVE x AS (SELECT 1,2 UNION ALL SELECT 1 FROM x) SELECT * FROM x;
......@@ -770,13 +770,7 @@ bool st_select_lex_unit::join_union_type_handlers(THD *thd_arg,
holders[pos].set_handler(item_type_handler);
else
{
if (first_sl->item_list.elements != sl->item_list.elements)
{
my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
ER_THD(thd_arg, ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT),
MYF(0));
DBUG_RETURN(true);
}
DBUG_ASSERT(first_sl->item_list.elements == sl->item_list.elements);
if (holders[pos].aggregate_for_result(item_type_handler))
{
my_error(ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION, MYF(0),
......@@ -1024,6 +1018,16 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
goto err;
}
}
else
{
if (first_sl->item_list.elements != sl->item_list.elements)
{
my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
ER_THD(thd_arg, ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT),
MYF(0));
goto err;
}
}
if (is_recursive)
{
if (!with_element->is_anchor(sl))
......
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