Skip to content

Commit

Permalink
Don't allow ALTER TABLE ... ORDER BY on SEQUENCE objects
Browse files Browse the repository at this point in the history
MDEV-19320 Sequence gets corrupted and produces ER_KEY_NOT_FOUND
           (Can't find record) after ALTER .. ORDER BY
  • Loading branch information
montywi committed Jun 7, 2020
1 parent e6a6382 commit a9bee98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mysql-test/suite/sql_sequence/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,10 @@ CREATE SEQUENCE t1 engine=innodb;
ALTER IGNORE TABLE t1 ADD CHECK (start_value < minimum_value);
ERROR HY000: Sequence 'test.t1' table structure is invalid (Sequence tables cannot have any constraints)
DROP SEQUENCE t1;
CREATE SEQUENCE s;
ALTER TABLE s ORDER BY cache_size;
ERROR HY000: Sequence 'test.s' table structure is invalid (ORDER BY)
SELECT NEXTVAL(s);
NEXTVAL(s)
1
DROP SEQUENCE s;
11 changes: 11 additions & 0 deletions mysql-test/suite/sql_sequence/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ CREATE SEQUENCE t1 engine=innodb;
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
ALTER IGNORE TABLE t1 ADD CHECK (start_value < minimum_value);
DROP SEQUENCE t1;

#
# MDEV-19320 Sequence gets corrupted and produces ER_KEY_NOT_FOUND (Can't
# find record) after ALTER .. ORDER BY
#

CREATE SEQUENCE s;
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
ALTER TABLE s ORDER BY cache_size;
SELECT NEXTVAL(s);
DROP SEQUENCE s;
5 changes: 5 additions & 0 deletions sql/sql_sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
reason= "Sequence tables cannot have any constraints";
goto err;
}
if (lex->alter_info.flags & ALTER_ORDER)
{
reason= "ORDER BY";
goto err;
}

for (field_no= 0; (field= it++); field_no++)
{
Expand Down

0 comments on commit a9bee98

Please sign in to comment.