1# include/read_many_rows.inc
2#
3# Test how filesort and buffered-record-reads works
4# This test needs a lot of time.
5#
6# The variables
7#     $engine_type       -- storage engine to be tested
8#     $other_engine_type -- storage engine <> $engine_type, if possible
9#                           1. $other_engine_type must allow to store many rows
10#                              without using non standard server options
11#                              (does not need a t/read_many_rows_*-master.opt file)
12#                           2. $other_engine_type must point to an all time
13#                              available storage engine
14#                              2006-08 MySQL 5.1 MyISAM and MEMORY only
15# have to be set before sourcing this script.
16#
17# Last update:
18# 2006-08-03 ML test refactored (MySQL 5.1)
19#               main code t/innodb-big.test --> include/read_many_rows.inc
20#
21
22eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
23
24--disable_warnings
25DROP TABLE IF EXISTS t1, t2, t3, t4;
26--enable_warnings
27
28eval CREATE TABLE t1 (id INTEGER) ENGINE=$other_engine_type;
29CREATE TABLE t2 (id INTEGER PRIMARY KEY);
30CREATE TABLE t3 (a CHAR(32) PRIMARY KEY,id INTEGER);
31eval CREATE TABLE t4 (a CHAR(32) PRIMARY KEY,id INTEGER) ENGINE=$other_engine_type;
32
33INSERT INTO t1 (id) VALUES (1);
34INSERT INTO t1 SELECT id+1 FROM t1;
35INSERT INTO t1 SELECT id+2 FROM t1;
36INSERT INTO t1 SELECT id+4 FROM t1;
37INSERT INTO t1 SELECT id+8 FROM t1;
38INSERT INTO t1 SELECT id+16 FROM t1;
39INSERT INTO t1 SELECT id+32 FROM t1;
40INSERT INTO t1 SELECT id+64 FROM t1;
41INSERT INTO t1 SELECT id+128 FROM t1;
42INSERT INTO t1 SELECT id+256 FROM t1;
43INSERT INTO t1 SELECT id+512 FROM t1;
44INSERT INTO t1 SELECT id+1024 FROM t1;
45INSERT INTO t1 SELECT id+2048 FROM t1;
46INSERT INTO t1 SELECT id+4096 FROM t1;
47INSERT INTO t1 SELECT id+8192 FROM t1;
48INSERT INTO t1 SELECT id+16384 FROM t1;
49INSERT INTO t1 SELECT id+32768 FROM t1;
50INSERT INTO t1 SELECT id+65536 FROM t1;
51INSERT INTO t1 SELECT id+131072 FROM t1;
52INSERT INTO t1 SELECT id+262144 FROM t1;
53INSERT INTO t1 SELECT id+524288 FROM t1;
54INSERT INTO t1 SELECT id+1048576 FROM t1;
55
56INSERT INTO t2 SELECT * FROM t1;
57INSERT INTO t3 SELECT CONCAT(id),id FROM t2 ORDER BY -id;
58INSERT INTO t4 SELECT * FROM t3 ORDER BY CONCAT(a);
59SELECT SUM(id) FROM t3;
60
61DROP TABLE t1,t2,t3,t4;
62
63#
64# Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
65#
66CREATE TABLE t1 (f1 int NOT NULL) ENGINE=InnoDB;
67CREATE TABLE t2 (f2 int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
68DELIMITER |;
69CREATE TRIGGER t1_bi before INSERT
70    ON t1 FOR EACH ROW
71BEGIN
72  DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @a:= 'deadlock';
73  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
74  INSERT INTO t2 (f2) VALUES (NEW.f1);
75  DELETE FROM t2 WHERE f2 = NEW.f1;
76END;|
77
78CREATE PROCEDURE proc24989()
79BEGIN
80  DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @b:= 'deadlock';
81  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
82  INSERT INTO t2 (f2) VALUES (1);
83  DELETE FROM t2 WHERE f2 = 1;
84END;|
85
86create procedure proc24989_2()
87    deterministic
88begin
89  declare continue handler for sqlexception
90    select 'Outer handler' as 'exception';
91
92  insert into t1 values(1);
93  select "continued";
94end|
95
96DELIMITER ;|
97
98connect (con1,localhost,root,,);
99connect (con2,localhost,root,,);
100
101connection con1;
102start transaction;
103insert into t1 values(1);
104
105connection con2;
106start transaction;
107insert into t2 values(123);
108send insert into t1 values(1);
109
110connection con1;
111--sleep 1
112insert into t1 values(123);
113
114connection con2;
115--error 1213
116reap;
117select @a;
118# check that the whole transaction was rolled back
119select * from t2;
120
121connection con1;
122commit;
123start transaction;
124insert into t1 values(1);
125
126connection con2;
127start transaction;
128insert into t2 values(123);
129send call proc24989();
130
131connection con1;
132--sleep 1
133insert into t1 values(123);
134
135connection con2;
136reap;
137select @a,@b;
138# check that the whole transaction was rolled back
139select * from t2;
140
141connection con1;
142commit;
143start transaction;
144insert into t1 values(1);
145
146connection con2;
147start transaction;
148insert into t2 values(123);
149send call proc24989_2();
150
151connection con1;
152--sleep 1
153insert into t1 values(123);
154commit;
155
156connection con2;
157reap;
158# check that the whole transaction was rolled back
159select * from t2;
160
161disconnect con1;
162disconnect con2;
163connection default;
164drop procedure proc24989;
165drop procedure proc24989_2;
166drop table t1,t2;
167
168