Commit 2d29ccda authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-29771 Server crashes in check_sequence_fields upon CREATE TABLE .. SEQUENCE=1 AS SELECT ..

Pass name separately for sequence check because sequence can be created with
CREATE TABLE (see https://mariadb.com/kb/en/create-table/#sequence )
parent 554aa1e2
......@@ -716,4 +716,12 @@ CREATE SEQUENCE seq1 START WITH 2;
CREATE TRIGGER s1 BEFORE UPDATE ON seq1 FOR EACH ROW SET @a= 5;
ERROR HY000: Trigger's 'seq1' is view, temporary table or sequence
DROP SEQUENCE seq1;
#
# MDEV-29771: Server crashes in check_sequence_fields upon
# CREATE TABLE .. SEQUENCE=1 AS SELECT ..
#
create table s sequence=1 as select 1;
ERROR HY000: Sequence 'test.s' table structure is invalid (Wrong number of columns)
#
# End of 10.4 test
#
......@@ -554,4 +554,14 @@ CREATE SEQUENCE seq1 START WITH 2;
CREATE TRIGGER s1 BEFORE UPDATE ON seq1 FOR EACH ROW SET @a= 5;
DROP SEQUENCE seq1;
--echo #
--echo # MDEV-29771: Server crashes in check_sequence_fields upon
--echo # CREATE TABLE .. SEQUENCE=1 AS SELECT ..
--echo #
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
create table s sequence=1 as select 1;
--echo #
--echo # End of 10.4 test
--echo #
......@@ -186,7 +186,8 @@ void sequence_definition::store_fields(TABLE *table)
true Failure
*/
bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
bool check_sequence_fields(LEX *lex, List<Create_field> *fields,
const LEX_CSTRING db, const LEX_CSTRING table_name)
{
Create_field *field;
List_iterator_fast<Create_field> it(*fields);
......@@ -234,8 +235,7 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
err:
my_error(ER_SEQUENCE_INVALID_TABLE_STRUCTURE, MYF(0),
lex->first_select_lex()->table_list.first->db.str,
lex->first_select_lex()->table_list.first->table_name.str, reason);
db.str, table_name.str, reason);
DBUG_RETURN(TRUE);
}
......
......@@ -162,6 +162,8 @@ class SEQUENCE_LAST_VALUE
class Create_field;
extern bool prepare_sequence_fields(THD *thd, List<Create_field> *fields);
extern bool check_sequence_fields(LEX *lex, List<Create_field> *fields);
extern bool check_sequence_fields(LEX *lex, List<Create_field> *fields,
const LEX_CSTRING db,
const LEX_CSTRING table_name);
extern bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *table_list);
#endif /* SQL_SEQUENCE_INCLUDED */
......@@ -3471,7 +3471,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
/* The user specified fields: check that structure is ok */
if (check_sequence_fields(thd->lex, &alter_info->create_list))
if (check_sequence_fields(thd->lex, &alter_info->create_list,
db, table_name))
DBUG_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