You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MDEV-36032 Check whether a table can be a sequence when ALTERed with SEQUENCE=1
To check the rows, the table needs to be opened. To that end, and like
MDEV-36038, we force COPY algorithm on ALTER TABLE ... SEQUENCE=1.
This also results in checking the sequence state / metadata.
The table structure was already validated before this patch.
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
455
+
`increment` bigint(21) NOT NULL COMMENT 'increment value',
456
+
`cache_size` bigint(21) unsigned NOT NULL,
457
+
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
458
+
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
459
+
) ENGINE=innodb;
460
+
alter table s sequence=1;
461
+
ERROR HY000: Sequence 'test.s' table structure is invalid (Wrong number of columns)
462
+
drop table s;
463
+
create sequence s;
464
+
alter table s drop column next_not_cached_value;
465
+
ERROR HY000: Sequence 'test.s' table structure is invalid (Wrong number of columns)
466
+
drop sequence s;
467
+
CREATE TABLE `s1` (
468
+
`next_not_cached_value` bigint(21) NOT NULL,
469
+
`minimum_value` bigint(21) NOT NULL,
470
+
`maximum_value` bigint(21) NOT NULL,
471
+
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
472
+
`increment` bigint(21) NOT NULL COMMENT 'increment value',
473
+
`cache_size` bigint(21) unsigned NOT NULL,
474
+
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
475
+
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
476
+
) ENGINE=innodb;
477
+
alter table s1 sequence=1;
478
+
ERROR HY000: Fewer than one row in the table
479
+
alter table s1 sequence=0;
480
+
insert into s1 values (1,1,9223372036854775806,1,1,1000,0,0);
481
+
alter table s1 sequence=1;
482
+
alter table s1 sequence=0;
483
+
insert into s1 values (2,1,9223372036854775806,1,1,1000,0,0);
484
+
alter table s1 sequence=1;
485
+
ERROR HY000: More than one row in the table
486
+
alter table s1 sequence=0;
487
+
insert into s1 values (3,1,9223372036854775806,1,1,1000,0,0);
Copy file name to clipboardExpand all lines: mysql-test/suite/sql_sequence/alter.test
+81Lines changed: 81 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -295,3 +295,84 @@ DROP SEQUENCE s2;
295
295
--echo #
296
296
--echo # End of 10.6 tests
297
297
--echo #
298
+
299
+
--echo #
300
+
--echo # MDEV-36032 Check when doing ALTER TABLE table_name sequence=1 that table can be a sequence
301
+
--echo #
302
+
303
+
## Too many rows
304
+
create sequence s;
305
+
alter table s sequence=0;
306
+
insert into s values (3,1,9223372036854775806,1,1,1000,0,0);
307
+
--error ER_SEQUENCE_TABLE_HAS_TOO_MANY_ROWS
308
+
alter table s sequence=1;
309
+
drop table s;
310
+
311
+
## Insert a wrong row (min > max)
312
+
create sequence s;
313
+
alter table s sequence=0;
314
+
delete from s;
315
+
insert into s values (2,500,200,1,1,1000,0,0);
316
+
select * from s;
317
+
--error ER_SEQUENCE_INVALID_DATA
318
+
alter table s sequence=1;
319
+
check table s;
320
+
select * from s;
321
+
check table s;
322
+
drop table s;
323
+
324
+
## Invalid table structure (already implemented before MDEV-36032)
325
+
CREATE TABLE `s` (
326
+
# `next_not_cached_value` bigint(21) NOT NULL,
327
+
`minimum_value` bigint(21) NOT NULL,
328
+
`maximum_value` bigint(21) NOT NULL,
329
+
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
330
+
`increment` bigint(21) NOT NULL COMMENT 'increment value',
331
+
`cache_size` bigint(21) unsigned NOT NULL,
332
+
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
333
+
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
334
+
) ENGINE=innodb;
335
+
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
336
+
alter table s sequence=1;
337
+
drop table s;
338
+
339
+
## Altering a sequence table to a wrong structure is detected (already
340
+
## implemented before MDEV-36032)
341
+
create sequence s;
342
+
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
343
+
alter table s drop column next_not_cached_value;
344
+
drop sequence s;
345
+
346
+
## Create a normal table then alter to sequence
347
+
CREATE TABLE `s1` (
348
+
`next_not_cached_value` bigint(21) NOT NULL,
349
+
`minimum_value` bigint(21) NOT NULL,
350
+
`maximum_value` bigint(21) NOT NULL,
351
+
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
352
+
`increment` bigint(21) NOT NULL COMMENT 'increment value',
353
+
`cache_size` bigint(21) unsigned NOT NULL,
354
+
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
355
+
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
356
+
) ENGINE=innodb;
357
+
358
+
--error ER_SEQUENCE_TABLE_HAS_TOO_FEW_ROWS
359
+
alter table s1 sequence=1;
360
+
# (for coverage) alter a non sequence table with sequence=0
361
+
alter table s1 sequence=0;
362
+
insert into s1 values (1,1,9223372036854775806,1,1,1000,0,0);
363
+
alter table s1 sequence=1;
364
+
365
+
alter table s1 sequence=0;
366
+
insert into s1 values (2,1,9223372036854775806,1,1,1000,0,0);
367
+
--error ER_SEQUENCE_TABLE_HAS_TOO_MANY_ROWS
368
+
alter table s1 sequence=1;
369
+
370
+
# (for coverage) alter a non sequence table with sequence=0
371
+
alter table s1 sequence=0;
372
+
insert into s1 values (3,1,9223372036854775806,1,1,1000,0,0);
0 commit comments