summaryrefslogtreecommitdiff
path: root/mysql-test/suite/sql_sequence/other.test
blob: 70c4efa40e5d55d06dcbe4c9c6f1f20a24e78e2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
--source include/have_sequence.inc
--source include/have_innodb.inc

#
# Test various combinations of operations on sequence
#

--echo #
--echo # Create and check
--echo #

create sequence s1 engine=innodb;
check table s1;
select next value for s1;
flush tables;
check table s1;
select next value for s1;
flush tables;
repair table s1;
select next value for s1;
drop sequence s1;

create or replace sequence s1 engine=innodb;
select next value for s1;
repair table s1;
check table s1;
select next value for s1;
select * from s1;
drop sequence s1;

--echo #
--echo # INSERT
--echo #

create sequence s1;
create sequence s2;
--error ER_NO_DEFAULT_FOR_FIELD
insert into s1 (next_not_cached_value, minimum_value) values (100,1000);
--error ER_UPDATE_TABLE_USED
insert into s1 values (next value for s1, 1,9223372036854775806,1,1,1000,0,0);
--error ER_SEQUENCE_INVALID_DATA
insert into s1 values(1000,9223372036854775806,1,1,1,1000,0,0);
--error ER_SEQUENCE_INVALID_DATA
insert into s1 values(0,9223372036854775806,1,1,1,1000,0,0);
select * from s1;
insert into s1 values(1000,1,9223372036854775806,1,1,1000,0,0);
select * from s1;
select next value for s1;
select * from s1;
--error ER_SEQUENCE_INVALID_DATA
insert into s2 values(0, 1, 10, 1, 2, 1, 1, 0);

select * from s1;
insert into s1 values (next value for s2, 1,9223372036854775806,1,1,1000,0,0);
select * from s1;
select * from s2;
insert into s1 select * from s2;
select * from s1;
drop sequence s1,s2;

--echo #
--echo # UPDATE and DELETE
--echo #

create sequence s1;
--error ER_ILLEGAL_HA
update s1 set next_not_cached_value=100;
--error ER_ILLEGAL_HA
delete from s1 where next_not_cached_value > 0;
drop sequence s1;

--echo #
--echo # SHOW TABLES
--echo #

create sequence s1;
create table t1 (a int);
create view v1 as select * from s1;
show full tables;
SELECT TABLE_TYPE,ENGINE FROM INFORMATION_SCHEMA.TABLES where table_schema="test" ORDER BY TABLE_NAME;
drop table t1,s1;
drop view v1;

--echo #
--echo # LOCK TABLES (as in mysqldump)
--echo #

create sequence s1 engine=innodb;
LOCK TABLES s1 READ;
SELECT * from s1;
UNLOCK TABLES;
LOCK TABLES s1 WRITE;
insert into s1 values (1,1,9223372036854775806, 1, 1, 1000, 0, 0);
UNLOCK TABLES;
drop table s1;

--echo #
--echo # Many sequence calls with innodb
--echo #

create sequence s1 cache=1000 engine=innodb;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;
commit;
select * from s1;
drop sequence s1;

create sequence s1  cache=1000 engine=innodb;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;

connect (addconroot, localhost, root,,);
connection addconroot;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;
select * from s1;
commit;
disconnect addconroot;
connection default;
select * from s1;
commit;
drop sequence s1;

--echo #
--echo # Flush tables with read lock
--echo #

create sequence s1;
select next value for s1;
flush tables with read lock;
--error 1223
create sequence s2;
--error 1223
select next value for s1;
unlock tables;
drop sequence s1;

--echo #
--echo # MDEV-14761
--echo # Assertion `!mysql_parse_status || thd->is_error() ||
--echo # thd->get_internal_handler()' failed in parse_sql
--echo #

CREATE SEQUENCE s1;
--error ER_DUP_ARGUMENT
ALTER SEQUENCE s1 MAXVALUE 100 NO MAXVALUE;
DROP SEQUENCE s1;

--echo #
--echo # Don't allow SEQUENCE to be used with CHECK or virtual fields
--echo #

CREATE SEQUENCE s1 nocache engine=myisam;
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE table t1 (a int check (next value for s1 > 0));
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE table t1 (a int check (previous value for s1 > 0));
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE table t1 (a int check (setval(s1,10)));
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
CREATE TABLE t1 (a int, b int as (next value for s1 > 0));
drop sequence s1;


--echo #
--echo # MDEV-13024: Server crashes in my_store_ptr upon DELETE from
--echo # sequence in multi-table format
--echo #
CREATE SEQUENCE s;
CREATE table t1 (a int);
insert into t1 values (1),(2);
--error ER_ILLEGAL_HA
DELETE s FROM s;
--error ER_ILLEGAL_HA
delete t1,s from s,t1;
--error ER_ILLEGAL_HA
delete s,t1 from t1,s;
DROP SEQUENCE s;
DROP TABLE t1;


--echo #
--echo # MDEV-20074: Lost connection on update trigger
--echo #

--echo # INSERT & table
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);

insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');

DELIMITER $$;

CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO t2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
DELIMITER ;$$

update t1 set p_first_name='Yunxi' where p_id=1;

drop sequence s1;
drop table t1,t2;


--echo # INSERT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;

insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');

DELIMITER $$;

CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO v2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
DELIMITER ;$$

update t1 set p_first_name='Yunxi' where p_id=1;

drop view v2;
drop table t1,t2;
drop sequence s1;


--echo # INSERT SELECT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;

insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');

DELIMITER $$;

CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO v2(a_p_name, a_p_first_name) SELECT old.p_name, old.p_first_name;
END;
$$
DELIMITER ;$$

update t1 set p_first_name='Yunxi' where p_id=1;

drop view v2;
drop table t1,t2;
drop sequence s1;


--echo # REPLACE & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;

insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');

DELIMITER $$;

CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
REPLACE INTO v2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
DELIMITER ;$$

update t1 set p_first_name='Yunxi' where p_id=1;

drop view v2;
drop table t1,t2;
drop sequence s1;


--echo # REPLACE SELECT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;

insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');

DELIMITER $$;

CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
REPLACE INTO v2(a_p_name, a_p_first_name) SELECT old.p_name, old.p_first_name;
END;
$$
DELIMITER ;$$

update t1 set p_first_name='Yunxi' where p_id=1;

drop view v2;
drop table t1,t2;
drop sequence s1;

--echo # End of 10.3 tests