File: delete_innodb.test

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (260 lines) | stat: -rw-r--r-- 7,185 bytes parent folder | download | duplicates (2)
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
--source include/have_innodb.inc
--source include/have_sequence.inc

--source include/innodb_stable_estimates.inc

--echo # Tests for delete with INNODB

--echo #
--echo # MDEV-22187: SIGSEGV in ha_innobase::cmp_ref on DELETE
--echo #

SET @save_sort_buffer_size= @@sort_buffer_size;
SET sort_buffer_size=1024;
CREATE TABLE t1(c1 CHAR(255) PRIMARY KEY) ENGINE=InnoDB;

INSERT INTO t1 VALUES (0), ('a'), ('b');
ANALYZE TABLE t1 PERSISTENT FOR ALL;
SELECT * FROM t1;
EXPLAIN DELETE b FROM t1 AS a JOIN t1 AS b;
DELETE b FROM t1 AS a JOIN t1 AS b;
SELECT * FROM t1;

SET sort_buffer_size=@save_sort_buffer_size;
DROP TABLE t1;

--echo #
--echo # MDEV-35944 DELETE fails to notice transaction abort, violating ACID
--echo #

CREATE TABLE t1 (id INT PRIMARY KEY, col_varchar VARCHAR(8)) ENGINE=InnoDB;
INSERT INTO t1 (id) VALUES (1),(2);
CREATE TABLE t2 (id INT, f INT, s DATE, e DATE, PERIOD FOR p(s,e), PRIMARY KEY(id, p WITHOUT OVERLAPS)) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1,0,'2000-01-01','2000-01-02');
CREATE TABLE t3 (id INT, f BLOB, UNIQUE(f)) ENGINE=InnoDB;

--connection default
SET innodb_lock_wait_timeout=1;
START TRANSACTION;
DELETE FROM t1;

--connect (con1,localhost,root,,)
START TRANSACTION;
UPDATE t2 SET f = 20;

--connection default
--send
  DELETE FROM t2 FOR PORTION OF p FROM '2000-01-01' TO '2000-01-02';

--connection con1
INSERT INTO t3 (id) VALUES (1), (2);
UPDATE t1 SET col_varchar = 'bar';
COMMIT;

--connection default
--error ER_LOCK_DEADLOCK
--reap
COMMIT;
UPDATE t3 SET f = 'foo' ORDER BY f LIMIT 1;

# Cleanup
DROP TABLE t1, t2, t3;

--echo # End of 10.5 tests

--echo #
--echo # MDEV-32212 DELETE with ORDER BY and semijoin optimization causing crash
--echo #

CREATE TABLE t1 (c1 INT) ENGINE=InnoDB;
CREATE TABLE t2 (c2 INT) ENGINE=InnoDB;
INSERT INTO t1 values (1),(2),(3),(4),(5),(6);
INSERT INTO t2 values (2);

DELETE FROM t1 WHERE c1 IN (select c2 from t2);
select * from t1;
truncate t1;
truncate t2;
INSERT INTO t1 values (1),(2),(3),(4),(5),(6);
INSERT INTO t2 values (2);
--echo check sj optimization with order-by
analyze DELETE FROM t1 WHERE c1 IN (select c2 from t2) ORDER BY c1;
select * from t1;
truncate t2;
INSERT INTO t2 values (3);
--echo disallows sj optimization
analyze DELETE FROM t1 WHERE c1 IN (select c2 from t2) ORDER BY c1 limit 1;
select * from t1;

DROP TABLE t1, t2;

--echo #
--echo # MDEV-33533: multi-delete using rowid filter
--echo #

set @save_default_storage_engine=@@default_storage_engine;
set default_storage_engine=InnoDB;

CREATE DATABASE dbt3_s001;

use dbt3_s001;

--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
--enable_warnings
--enable_result_log
--enable_query_log

create index i_n_name on nation(n_name);
analyze table
  nation, lineitem, customer, orders, part, supplier, partsupp, region
persistent for all;

let $c1=
        o_orderDATE between '1992-01-01' and '1992-06-30' and
        o_custkey =  c_custkey and
        c_nationkey = n_nationkey and
        n_name='PERU';

eval
explain
select o_orderkey, o_totalprice from orders, customer, nation where $c1;
--source include/explain-no-costs.inc
eval
explain format=json
select o_orderkey, o_totalprice from orders, customer, nation where $c1;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;
eval
create table t as
select orders.* from orders, customer, nation where $c1;

eval
explain
delete from orders using orders, customer, nation where $c1;
--source include/explain-no-costs.inc
eval
explain format=json
delete from orders using orders, customer, nation where $c1;
eval
delete from orders using orders, customer, nation where $c1;
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;

insert into orders select * from t;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;

eval
prepare stmt from "
delete from orders using orders, customer, nation where $c1;
";

execute stmt;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;
insert into orders select * from t;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;

execute stmt;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;
insert into orders select * from t;
--sorted_result
eval
select o_orderkey, o_totalprice from orders, customer, nation where $c1;

deallocate prepare stmt;

drop table t;

let $c1=
        o_orderDATE between '1992-01-01' and '1992-06-30' and
        o_custkey in (select c_custkey from customer
                        where c_nationkey in (select n_nationkey from nation
                                                where n_name='PERU'));

eval
explain
select o_orderkey, o_totalprice from orders where $c1;
--source include/explain-no-costs.inc
eval
explain format=json
select o_orderkey, o_totalprice from orders where $c1;
--sorted_result
eval
select o_orderkey, o_totalprice from orders where $c1;
eval
create table t as
select * from orders where $c1;

eval
explain
delete from orders where $c1;
--source include/explain-no-costs.inc
eval
explain format=json
delete from orders where $c1;
eval
delete from orders where $c1;
eval
select o_orderkey, o_totalprice from orders where $c1;

insert into orders select * from t;
--sorted_result
eval
select o_orderkey, o_totalprice from orders where $c1;
drop table t;

DROP DATABASE dbt3_s001;

set default_storage_engine=@save_default_storage_engine;

--echo #
--echo # Additional tests of first table and rowid filter
--echo #

CREATE DATABASE dbt3_s001;

use dbt3_s001;

set @save_default_storage_engine=@@default_storage_engine;
set default_storage_engine=InnoDB;

--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
--enable_warnings
--enable_result_log
--enable_query_log

CREATE INDEX i_l_quantity ON lineitem(l_quantity);
CREATE INDEX i_o_totalprice ON orders(o_totalprice);
ANALYZE TABLE lineitem, orders;
set optimizer_use_condition_selectivity=2;
create table second(s_receiptDATE date, filler char(100), key(s_receiptDATE)) ;
insert into second select date_add(l_receiptDATE, interval 1 day), 'helllo' from lineitem ;

select count(*) from lineitem, second   WHERE  l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 47 and second.s_receiptDATE = date_add(l_receiptDATE, interval 1 day);

--echo # lineitem should be first and with "Using rowid filter"
explain delete lineitem FROM lineitem, second   WHERE  l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 47 and second.s_receiptDATE = date_add(l_receiptDATE, interval 1 day);

delete lineitem FROM lineitem, second   WHERE  l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 47 and second.s_receiptDATE = date_add(l_receiptDATE, interval 1 day);

--echo # Should be 0
select count(*) from lineitem, second   WHERE  l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 47 and second.s_receiptDATE = date_add(l_receiptDATE, interval 1 day);

drop database  dbt3_s001;
set default_storage_engine=@save_default_storage_engine;

--echo # End of 11.1 tests