Skip to content
/ server Public

Commit ca39e66

Browse files
MDEV-38620: Server crashes in setup_returning_fields upon 2nd execution
of multi-table-styled DELETE from a view Analysis: The item_list of builtin_select stores the fields that are there in the RETURNING clause. During the "EXECUTE" command, a "dummy item" is added into the item_list of the select_lex(builtin_select) representing DELETE during Sql_cmd_delete::precheck(). This snippet that adds a dummy item is added because columnstore needs for temporary table. Results are put into a temporary table and to create a temporary table we need to know what columns are there which we get from the select_lex->item_list. As a result, the item_list now has an item even when there is not really RETURNING clause, resulting in execution of the setup_returning_fields() when it should have exited already. Fix: Instead of checking whether builint_select's item_list is empty to determine whether there is RETURNING clause, use a flag.
1 parent 2c2a418 commit ca39e66

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

mysql-test/main/ps.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6138,4 +6138,15 @@ a ? ?
61386138
1 700 900
61396139
DEALLOCATE PREPARE stmt;
61406140
DROP TABLE t1;
6141+
#
6142+
# MDEV-38620: Server crashes in setup_returning_fields upon 2nd
6143+
# execution of multi-table-styled DELETE from a view
6144+
#
6145+
CREATE TABLE t (a INT);
6146+
CREATE VIEW v AS SELECT * FROM t;
6147+
PREPARE stmt FROM "DELETE v FROM v";
6148+
EXECUTE stmt;
6149+
EXECUTE stmt;
6150+
DROP VIEW v;
6151+
DROP TABLE t;
61416152
# End of 11.4 tests

mysql-test/main/ps.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,4 +5592,18 @@ EXECUTE stmt USING 700, 900;
55925592
DEALLOCATE PREPARE stmt;
55935593
DROP TABLE t1;
55945594

5595+
--echo #
5596+
--echo # MDEV-38620: Server crashes in setup_returning_fields upon 2nd
5597+
--echo # execution of multi-table-styled DELETE from a view
5598+
--echo #
5599+
5600+
CREATE TABLE t (a INT);
5601+
CREATE VIEW v AS SELECT * FROM t;
5602+
PREPARE stmt FROM "DELETE v FROM v";
5603+
EXECUTE stmt;
5604+
EXECUTE stmt;
5605+
5606+
DROP VIEW v;
5607+
DROP TABLE t;
5608+
55955609
--echo # End of 11.4 tests

sql/sql_lex.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ void LEX::start(THD *thd_arg)
13371337

13381338
table_count_update= 0;
13391339

1340+
has_returning_list= false;
1341+
13401342
memset(&trg_chistics, 0, sizeof(trg_chistics));
13411343
DBUG_VOID_RETURN;
13421344
}

sql/sql_lex.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,9 @@ struct LEX: public Query_tables_list
36673667
Activates enforcement of the LIMIT ROWS EXAMINED clause, if present
36683668
in the query.
36693669
*/
3670+
3671+
bool has_returning_list;
3672+
36703673
void set_limit_rows_examined()
36713674
{
36723675
if (limit_rows_examined)
@@ -4946,7 +4949,7 @@ struct LEX: public Query_tables_list
49464949
SELECT_LEX *returning()
49474950
{ return &builtin_select; }
49484951
bool has_returning()
4949-
{ return !builtin_select.item_list.is_empty(); }
4952+
{ return has_returning_list; }
49504953

49514954
private:
49524955
bool stmt_create_routine_start(const DDL_options_st &options)

sql/sql_yacc.yy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13730,6 +13730,7 @@ opt_returning:
1373013730

1373113731
thd->lex->current_select->parsing_place= IN_RETURNING;
1373213732
thd->lex->push_context(&thd->lex->returning()->context);
13733+
thd->lex->has_returning_list= true;
1373313734
}
1373413735
select_item_list
1373513736
{

0 commit comments

Comments
 (0)