~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/transaction_log/tests/t/transaction_log_delete.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# transaction_log_update
 
2
# test of various DELETE statements and
 
3
# how the transaction_log captures the relevant data
 
4
 
 
5
--echo Testing DELETE basic 
 
6
--disable_warnings
 
7
DROP TABLE IF EXISTS t1, t2;
 
8
--enable_warnings
 
9
 
 
10
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, PRIMARY KEY(a), KEY b_key1 (b));
 
11
 
 
12
INSERT INTO t1 (b) VALUES (10),(20),(30),(40),(50),(60);
 
13
 
 
14
DELETE FROM t1;
 
15
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
16
--echo
 
17
 
 
18
DROP TABLE t1;
 
19
 
 
20
# Truncate the log file to reset for the next test
 
21
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
22
--echo
 
23
 
 
24
--echo Testing simple DELETE with WHERE 
 
25
--disable_warnings
 
26
DROP TABLE IF EXISTS t1, t2;
 
27
--enable_warnings
 
28
 
 
29
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, c CHAR(100), PRIMARY KEY(a));
 
30
 
 
31
INSERT INTO t1 (b,c) VALUES (10,'a'),(20,'b'),(30,'c'),(40,'d'),(50,'e'),(60,'f');
 
32
 
 
33
 
 
34
DELETE FROM t1 WHERE a%2=0 ;
 
35
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
36
--echo
 
37
 
 
38
DROP TABLE t1;
 
39
 
 
40
# Truncate the log file to reset for the next test
 
41
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
42
--echo
 
43
 
 
44
--echo Testing simple DELETE with WHERE + LIMIT
 
45
--disable_warnings
 
46
DROP TABLE IF EXISTS t1, t2;
 
47
--enable_warnings
 
48
 
 
49
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, c CHAR(100), PRIMARY KEY(a));
 
50
 
 
51
INSERT INTO t1 (b,c) VALUES (10,'a'),(20,'b'),(30,'c'),(40,'d'),(50,'e'),(60,'f');
 
52
 
 
53
DELETE FROM t1 WHERE a%2=0 LIMIT 1;
 
54
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
55
--echo
 
56
 
 
57
DROP TABLE t1;
 
58
 
 
59
# Truncate the log file to reset for the next test
 
60
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
61
--echo
 
62
 
 
63
--echo Testing simple DELETE with WHERE + LIMIT + ORDER BY1 
 
64
--disable_warnings
 
65
DROP TABLE IF EXISTS t1, t2;
 
66
--enable_warnings
 
67
 
 
68
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, c CHAR(100), PRIMARY KEY(a));
 
69
 
 
70
INSERT INTO t1 (b,c) VALUES (10,'a'),(20,'b'),(30,'c'),(40,'d'),(50,'e'),(60,'f');
 
71
 
 
72
DELETE FROM t1 WHERE a%2=0 ORDER BY a DESC LIMIT 1;
 
73
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
74
--echo
 
75
 
 
76
DROP TABLE t1;
 
77
 
 
78
# Truncate the log file to reset for the next test
 
79
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
80
--echo
 
81
 
 
82
--echo Testing simple DELETE with WHERE + LIMIT + ORDER BY2
 
83
--disable_warnings
 
84
DROP TABLE IF EXISTS t1, t2;
 
85
--enable_warnings
 
86
 
 
87
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, c CHAR(100), PRIMARY KEY(a));
 
88
 
 
89
INSERT INTO t1 (b,c) VALUES (10,'a'),(20,'b'),(30,'c'),(40,'d'),(50,'e'),(60,'f');
 
90
 
 
91
DELETE FROM t1 WHERE a%2=0 ORDER BY a DESC LIMIT 10000;
 
92
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
93
--echo
 
94
 
 
95
DROP TABLE t1;
 
96
 
 
97
# Truncate the log file to reset for the next test
 
98
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
99
--echo
 
100
 
 
101
--echo Testing DELETE - Foreign Key constraints CASCADE
 
102
--disable_warnings
 
103
DROP TABLE IF EXISTS t1, t2;
 
104
--enable_warnings
 
105
 
 
106
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, PRIMARY KEY(a), KEY b_key1 (b));
 
107
 
 
108
CREATE TABLE t2(a INT NOT NULL AUTO_INCREMENT, b INT , PRIMARY KEY(a), KEY b_key (b),
 
109
CONSTRAINT fk_constraint_t2 FOREIGN KEY (b) REFERENCES t1(b) ON DELETE CASCADE ON UPDATE CASCADE);
 
110
 
 
111
INSERT INTO t1 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
112
 
 
113
INSERT INTO t2 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
114
 
 
115
DELETE FROM t1 WHERE b%2=0;
 
116
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
117
--echo
 
118
 
 
119
DROP TABLE t2;
 
120
 
 
121
DROP TABLE t1;
 
122
 
 
123
# Truncate the log file to reset for the next test
 
124
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
125
--echo
 
126
 
 
127
# Truncate the log file to reset for the next test
 
128
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
129
--echo
 
130
 
 
131
--echo Testing DELETE - Foreign Key constraints SET NULL 
 
132
--disable_warnings
 
133
DROP TABLE IF EXISTS t1, t2;
 
134
--enable_warnings
 
135
 
 
136
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, PRIMARY KEY(a), KEY b_key1 (b));
 
137
 
 
138
CREATE TABLE t2(a INT NOT NULL AUTO_INCREMENT, b INT , PRIMARY KEY(a), KEY b_key (b),
 
139
CONSTRAINT fk_constraint_t2 FOREIGN KEY (b) REFERENCES t1(b) ON DELETE SET NULL ON UPDATE CASCADE);
 
140
 
 
141
INSERT INTO t1 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
142
 
 
143
INSERT INTO t2 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
144
 
 
145
DELETE FROM t1 WHERE b%2=0;
 
146
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
147
--echo
 
148
 
 
149
DROP TABLE t2;
 
150
 
 
151
DROP TABLE t1;
 
152
 
 
153
# Truncate the log file to reset for the next test
 
154
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
155
--echo
 
156
 
 
157
# Truncate the log file to reset for the next test
 
158
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
159
--echo
 
160
 
 
161
--echo Testing DELETE - Foreign Key constraints CASCADE
 
162
--disable_warnings
 
163
DROP TABLE IF EXISTS t1, t2;
 
164
--enable_warnings
 
165
 
 
166
CREATE TABLE t1(a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL, PRIMARY KEY(a), KEY b_key1 (b));
 
167
 
 
168
CREATE TABLE t2(a INT NOT NULL AUTO_INCREMENT, b INT , PRIMARY KEY(a), KEY b_key (b),
 
169
CONSTRAINT fk_constraint_t2 FOREIGN KEY (b) REFERENCES t1(b) ON DELETE RESTRICT ON UPDATE CASCADE);
 
170
 
 
171
INSERT INTO t1 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
172
 
 
173
INSERT INTO t2 (b) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(100),(101);
 
174
 
 
175
--ERROR 1451
 
176
DELETE FROM t1 WHERE b%2=0;
 
177
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
178
--echo
 
179
 
 
180
DROP TABLE t2;
 
181
 
 
182
DROP TABLE t1;
 
183
 
 
184
# Truncate the log file to reset for the next test
 
185
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
186
--echo
 
187
 
 
188
--echo Testing DELETE basic2 
 
189
--disable_warnings
 
190
DROP TABLE IF EXISTS t1;
 
191
--enable_warnings
 
192
 
 
193
CREATE TABLE t1 (
 
194
  id INT NOT NULL
 
195
, padding VARCHAR(200) NOT NULL
 
196
, PRIMARY KEY (id)
 
197
);
 
198
 
 
199
INSERT INTO t1 VALUES (1, "I love testing.");
 
200
INSERT INTO t1 VALUES (2, "I hate testing.");
 
201
 
 
202
DELETE FROM t1 where id = 1;
 
203
 
 
204
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
205
--echo
 
206
 
 
207
DROP TABLE t1;
 
208
 
 
209
# Truncate the log file to reset for the next test
 
210
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
211
--echo
 
212
 
 
213
--echo Testing DELETE / TRUNCATE optimization
 
214
# Test the situation where no keys (WHERE clause)
 
215
# are specified in a DELETE statement.  In the absence
 
216
# of triggers, this equates to a TRUNCATE TABLE statement, 
 
217
# and this is what should be written to the transaction log, 
 
218
# not multiple DeleteRecord events.
 
219
#
 
220
# However, right now this optimization does not occur. We
 
221
# write individual DeleteRecord message to the log.  We will
 
222
# optimize this away once TableShare has been refactored
 
223
 
 
224
CREATE TABLE t1 (
 
225
  id INT NOT NULL
 
226
, other INT NOT NULL
 
227
, PRIMARY KEY (id)
 
228
);
 
229
 
 
230
INSERT INTO t1 VALUES (1, 1);
 
231
INSERT INTO t1 VALUES (2, 2);
 
232
INSERT INTO t1 VALUES (3, 3);
 
233
INSERT INTO t1 VALUES (4, 4);
 
234
INSERT INTO t1 VALUES (5, 5);
 
235
INSERT INTO t1 VALUES (6, 6);
 
236
INSERT INTO t1 VALUES (7, 7);
 
237
INSERT INTO t1 VALUES (8, 8);
 
238
 
 
239
--echo  This should produce a TRUNCATE event
 
240
DELETE FROM t1;
 
241
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
242
--echo
 
243
 
 
244
DROP TABLE t1;
 
245
 
 
246
# Truncate the log file to reset for the next test
 
247
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
248
--echo
 
249
 
 
250
--echo Testing DELETE Bug#496101
 
251
# Delete within a transaction does not generate the correct 
 
252
# statements in the transaction log.  We start a transaction
 
253
# and issue both inserts and deletes in the same transaction.
 
254
--disable_warnings
 
255
DROP TABLE IF EXISTS t1;
 
256
--enable_warnings
 
257
 
 
258
CREATE TABLE t1 (
 
259
  id INT NOT NULL
 
260
, padding VARCHAR(200) NOT NULL
 
261
, PRIMARY KEY (id)
 
262
);
 
263
 
 
264
START TRANSACTION;
 
265
 
 
266
INSERT INTO t1 VALUES (1, "I love testing.");
 
267
INSERT INTO t1 VALUES (2, "I hate testing.");
 
268
 
 
269
DELETE FROM t1 where id = 1;
 
270
 
 
271
COMMIT;
 
272
 
 
273
--source ../plugin/transaction_log/tests/t/check_transaction_log.inc
 
274
--echo
 
275
 
 
276
DROP TABLE t1;
 
277
 
 
278
# Truncate the log file to reset for the next test
 
279
--source ../plugin/transaction_log/tests/t/truncate_log.inc
 
280
--echo
 
281