|
| 1 | +--source include/have_innodb.inc |
| 2 | + |
| 3 | +# Check failure of underlying engine |
| 4 | +create sequence s; |
| 5 | +let $datadir= `select @@datadir`; |
| 6 | +remove_file $datadir/test/s.MYD; |
| 7 | +write_file $datadir/test/s.MYD; |
| 8 | +foo |
| 9 | +EOF |
| 10 | +call mtr.add_suppression("ha_myisam"); |
| 11 | +call mtr.add_suppression("Checking table"); |
| 12 | +check table s; |
| 13 | +drop table s; |
| 14 | + |
| 15 | +# Insert a row into a sequence table updates that row |
| 16 | +create sequence s; |
| 17 | +insert into s values (3,1,9223372036854775806,1,1,1000,0,0); |
| 18 | +select * from s; |
| 19 | +# ok |
| 20 | +check table s; |
| 21 | +--disable_ps2_protocol |
| 22 | +select nextval(s); |
| 23 | +--enable_ps2_protocol |
| 24 | +drop sequence s; |
| 25 | + |
| 26 | +# More than one row |
| 27 | +let $datadir=`select @@datadir`; |
| 28 | +CREATE SEQUENCE s; |
| 29 | +copy_file $datadir/test/s.frm $datadir/test/s1.frm; |
| 30 | +ALTER TABLE s sequence=0; |
| 31 | +insert into s values (3,1,9223372036854775806,1,1,1000,0,0); |
| 32 | +FLUSH TABLES; |
| 33 | +remove_file $datadir/test/s.frm; |
| 34 | +move_file $datadir/test/s1.frm $datadir/test/s.frm; |
| 35 | +CHECK TABLE s; |
| 36 | +DROP SEQUENCE s; |
| 37 | + |
| 38 | +# Fewer than one row |
| 39 | +let $datadir=`select @@datadir`; |
| 40 | +CREATE SEQUENCE s; |
| 41 | +copy_file $datadir/test/s.frm $datadir/test/s1.frm; |
| 42 | +ALTER TABLE s sequence=0; |
| 43 | +delete from s; |
| 44 | +FLUSH TABLES; |
| 45 | +remove_file $datadir/test/s.frm; |
| 46 | +move_file $datadir/test/s1.frm $datadir/test/s.frm; |
| 47 | +CHECK TABLE s; |
| 48 | +DROP SEQUENCE s; |
| 49 | + |
| 50 | +# Wrong metadata (minvalue > maxvalue) |
| 51 | +let $datadir=`select @@datadir`; |
| 52 | +CREATE SEQUENCE s; |
| 53 | +copy_file $datadir/test/s.frm $datadir/test/s1.frm; |
| 54 | +ALTER TABLE s sequence=0; |
| 55 | +update s set minimum_value=200, maximum_value=100; |
| 56 | +FLUSH TABLES; |
| 57 | +remove_file $datadir/test/s.frm; |
| 58 | +move_file $datadir/test/s1.frm $datadir/test/s.frm; |
| 59 | +CHECK TABLE s; |
| 60 | +DROP SEQUENCE s; |
| 61 | + |
| 62 | +# Sequence run out tests. |
| 63 | +# |
| 64 | +# General principle: CHECK TABLE of a sequence table returns OK with a |
| 65 | +# warning of ER_SEQUENCE_RUN_OUT if a SELECT NEXTVAL of the sequence |
| 66 | +# in place of the CHECK TABLE statement would report |
| 67 | +# ER_SEQUENCE_RUN_OUT. |
| 68 | +create sequence s minvalue 13 maxvalue 15 increment by 4; |
| 69 | +check table s; |
| 70 | +--disable_ps2_protocol |
| 71 | +select nextval(s); |
| 72 | +--enable_ps2_protocol |
| 73 | +check table s; |
| 74 | +alter sequence s cycle; |
| 75 | +check table s; |
| 76 | +alter sequence s nocycle; |
| 77 | +check table s; |
| 78 | +# Still get run out because next_free_value has not changed. same |
| 79 | +# would happen with a SELECT NEXTVAL(s) statement without the |
| 80 | +# preceding check table statement. |
| 81 | +alter sequence s increment by 1; |
| 82 | +check table s; |
| 83 | +alter sequence s increment by 4; |
| 84 | +# If all_values_used is true, and then we make sequence cycle, check |
| 85 | +# table will be ok without warning, as expected. this is because the |
| 86 | +# ALTER SEQUENCE statement causes all_values_used to be reset. |
| 87 | +--disable_ps2_protocol |
| 88 | +--error ER_SEQUENCE_RUN_OUT |
| 89 | +select nextval(s); |
| 90 | +--enable_ps2_protocol |
| 91 | +alter sequence s cycle; |
| 92 | +check table s; |
| 93 | +alter sequence s maxvalue 23 nocycle; |
| 94 | +check table s; |
| 95 | +alter sequence s maxvalue 15; |
| 96 | +check table s; |
| 97 | +drop sequence s; |
| 98 | + |
| 99 | +# CHECK TABLE calls sequence_definition::check_and_adjust() with |
| 100 | +# adjust_next=false, so that there will be no flushing of |
| 101 | +# next_free_value in this call, hence no running out |
| 102 | +create sequence s minvalue 13 maxvalue 20 increment by 1; |
| 103 | +--disable_ps2_protocol |
| 104 | +select nextval(s); |
| 105 | +--enable_ps2_protocol |
| 106 | +check table s; |
| 107 | +--disable_ps2_protocol |
| 108 | +select nextval(s); |
| 109 | +--enable_ps2_protocol |
| 110 | +drop sequence s; |
| 111 | + |
| 112 | +# Without the CHECK TABLE statement below, the ALTER TABLE ... |
| 113 | +# SEQUENCE=1 statement would still cause flushing in subsequent SELECT |
| 114 | +# NEXTVAL statement (initialized == SQUENCE:SQL_UNITIALIZED => |
| 115 | +# read_initial_value() => => sequence_defitinion::adjust_values()), |
| 116 | +# resulting in sequence running out. |
| 117 | + |
| 118 | +# Same effect takes place with ALTER SEQUENCE, though different cause: |
| 119 | +# in ALTER SEQUENCE, sequence_defitinion::adjust_values() is called in |
| 120 | +# sequence_definition::check_and_adjust() which is called in |
| 121 | +# Sql_cmd_alter_sequence::execute() |
| 122 | +create sequence s minvalue 13 maxvalue 20 increment by 1; |
| 123 | +--disable_ps2_protocol |
| 124 | +select nextval(s); |
| 125 | +--enable_ps2_protocol |
| 126 | +alter table s sequence=0; |
| 127 | +alter table s sequence=1; |
| 128 | +check table s; |
| 129 | +--disable_ps2_protocol |
| 130 | +--error ER_SEQUENCE_RUN_OUT |
| 131 | +select nextval(s); |
| 132 | +--enable_ps2_protocol |
| 133 | +drop sequence s; |
| 134 | + |
| 135 | +# UPDATE is banned by the storage engine - no need to check. |
| 136 | +create sequence s; |
| 137 | +--error ER_ILLEGAL_HA |
| 138 | +update s set minimum_value=500, maximum_value=200; |
| 139 | +drop sequence s; |
0 commit comments