Skip to content

Commit f8bc799

Browse files
committed
Import WL#6658 update_time tests from MySQL 5.7
1 parent 0055e1a commit f8bc799

File tree

5 files changed

+764
-0
lines changed

5 files changed

+764
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Test that INFORMATION_SCHEMA.TABLES.UPDATE_TIME is filled
3+
# correctly for InnoDB tables.
4+
#
5+
CREATE TABLE t (a INT) ENGINE=INNODB;
6+
SELECT update_time FROM information_schema.tables WHERE table_name = 't';
7+
update_time
8+
NULL
9+
INSERT INTO t VALUES (1);
10+
SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
11+
AND update_time IS NOT NULL;
12+
COUNT(*)
13+
1
14+
# We cant deterministically check that the saved value is correct, but
15+
# at least we check that it is a timestamp not older than 2 minutes.
16+
# Usually update_time and NOW() are equal below, but on heavily loaded
17+
# machines NOW() could be younger.
18+
SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
19+
AND TIMESTAMPDIFF(SECOND, update_time, NOW()) < 120;
20+
COUNT(*)
21+
1
22+
CREATE TABLE big (a TEXT) ENGINE=INNODB;
23+
SELECT COUNT(*) FROM information_schema.innodb_buffer_page
24+
WHERE table_name = '`test`.`t`';
25+
COUNT(*)
26+
1
27+
# INSERT lots of data in table 'big': begin
28+
# INSERT lots of data in table 'big': end
29+
SELECT COUNT(*) FROM information_schema.innodb_buffer_page
30+
WHERE table_name = '`test`.`t`';
31+
COUNT(*)
32+
0
33+
SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
34+
AND update_time IS NOT NULL;
35+
COUNT(*)
36+
1
37+
DROP TABLE big;
38+
# Test the behavior after restart with a prepared XA transaction
39+
XA START 'xatrx';
40+
INSERT INTO t VALUES (5);
41+
XA END 'xatrx';
42+
XA PREPARE 'xatrx';
43+
call mtr.add_suppression("Found 1 prepared XA transactions");
44+
# Kill and restart
45+
SELECT update_time FROM information_schema.tables WHERE table_name = 't';
46+
update_time
47+
NULL
48+
XA COMMIT 'xatrx';
49+
SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
50+
AND update_time IS NOT NULL;
51+
COUNT(*)
52+
1
53+
DROP TABLE t;
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
#create base table
2+
CREATE TABLE tab1(c1 int,c2 varchar(30), c3 BLOB) ENGINE=InnoDB;
3+
CREATE TABLE tab3(c1 int,c2 varchar(30)) ENGINE=InnoDB;
4+
CREATE TABLE tab4(c1 int,c2 varchar(30)) ENGINE=InnoDB;
5+
CREATE TABLE tab5(c1 int,c2 varchar(30)) ENGINE=InnoDB;
6+
#insert some base records
7+
INSERT INTO tab4 VALUES(1,'Test for Update');
8+
INSERT INTO tab5 VALUES(1,'Test for Delete');
9+
#create a trigger
10+
CREATE TRIGGER test_trig BEFORE INSERT ON tab1
11+
FOR EACH ROW BEGIN
12+
INSERT INTO tab3 VALUES(1,'Inserted From Trigger');
13+
UPDATE tab4 SET c2='Updated from Trigger' WHERE c1=1;
14+
DELETE FROM tab5;
15+
END |
16+
#restart the server
17+
# restart
18+
check the update_time Before DML, whether it is NULL
19+
SELECT table_name,update_time
20+
FROM information_schema.tables
21+
WHERE table_name IN ('tab1','tab3','tab4','tab5');
22+
table_name update_time
23+
tab1 NULL
24+
tab3 NULL
25+
tab4 NULL
26+
tab5 NULL
27+
SET AUTOCOMMIT=OFF;
28+
#case1:
29+
BEGIN WORK;
30+
INSERT INTO tab1
31+
VALUES(1,'Testing the wl6658', 'Testing the wl6658');
32+
check the update_time Before commit, whether it is NULL
33+
SELECT table_name,update_time
34+
FROM information_schema.tables WHERE table_name='tab1';
35+
table_name update_time
36+
tab1 NULL
37+
COMMIT;
38+
#check the record is inserted
39+
SELECT * FROM tab1;
40+
c1 c2 c3
41+
1 Testing the wl6658 Testing the wl6658
42+
#check the record is inserted
43+
SELECT * FROM tab3;
44+
c1 c2
45+
1 Inserted From Trigger
46+
#check the record is updated
47+
SELECT * FROM tab4;
48+
c1 c2
49+
1 Updated from Trigger
50+
#check no record exists
51+
SELECT * FROM tab5;
52+
c1 c2
53+
check the update_time After Commit, whether it is not NULL
54+
SELECT table_name,COUNT(update_time)
55+
FROM information_schema.tables
56+
WHERE table_name IN ('tab1','tab3','tab4','tab5')
57+
GROUP BY table_name;
58+
table_name COUNT(update_time)
59+
tab1 1
60+
tab3 1
61+
tab4 1
62+
tab5 1
63+
#restart the server
64+
# restart
65+
Testcase with UPDATE stmt and transaction
66+
#check the record is existing
67+
SELECT * FROM tab1;
68+
c1 c2 c3
69+
1 Testing the wl6658 Testing the wl6658
70+
check the update_time Before DML, whether it is NULL
71+
SELECT table_name,update_time
72+
FROM information_schema.tables WHERE table_name='tab1';
73+
table_name update_time
74+
tab1 NULL
75+
SET AUTOCOMMIT=OFF;
76+
#case2:
77+
START TRANSACTION;
78+
UPDATE tab1 SET c2='Updated',c3='Updated' WHERE c1=1;
79+
check the update_time Before commit, whether it is NULL
80+
SELECT table_name,update_time
81+
FROM information_schema.tables WHERE table_name='tab1';
82+
table_name update_time
83+
tab1 NULL
84+
COMMIT;
85+
#check the record is updated
86+
SELECT * FROM tab1;
87+
c1 c2 c3
88+
1 Updated Updated
89+
check the update_time After Commit, whether it is not NULL
90+
SELECT table_name,COUNT(update_time)
91+
FROM information_schema.tables WHERE table_name='tab1';
92+
table_name COUNT(update_time)
93+
tab1 1
94+
#restart the server
95+
# restart
96+
#check the record is existing
97+
SELECT * FROM tab1;
98+
c1 c2 c3
99+
1 Updated Updated
100+
check the update_time Before DML, whether it is NULL
101+
SELECT table_name,update_time
102+
FROM information_schema.tables WHERE table_name='tab1';
103+
table_name update_time
104+
tab1 NULL
105+
SET AUTOCOMMIT=OFF;
106+
#case3:
107+
START TRANSACTION;
108+
DELETE FROM tab1;
109+
check the update_time Before commit, whether it is NULL
110+
SELECT table_name,update_time
111+
FROM information_schema.tables WHERE table_name='tab1';
112+
table_name update_time
113+
tab1 NULL
114+
COMMIT;
115+
#check the record is deleted
116+
SELECT * FROM tab1;
117+
c1 c2 c3
118+
check the update_time After Commit, whether it is not NULL
119+
SELECT table_name,COUNT(update_time)
120+
FROM information_schema.tables WHERE table_name='tab1';
121+
table_name COUNT(update_time)
122+
tab1 1
123+
#restart the server
124+
# restart
125+
#check no records are existing
126+
SELECT * FROM tab1;
127+
c1 c2 c3
128+
check the update_time Before DML, whether it is NULL
129+
SELECT table_name,update_time
130+
FROM information_schema.tables WHERE table_name='tab1';
131+
table_name update_time
132+
tab1 NULL
133+
SET AUTOCOMMIT=OFF;
134+
#case4:
135+
START TRANSACTION;
136+
INSERT INTO tab1
137+
VALUES(1,'Testing the wl6658', 'Testing the wl6658');
138+
check the update_time Before Rollback, whether it is NULL
139+
SELECT table_name,update_time
140+
FROM information_schema.tables WHERE table_name='tab1';
141+
table_name update_time
142+
tab1 NULL
143+
ROLLBACK;
144+
#check no record is inserted.
145+
SELECT * FROM tab1;
146+
c1 c2 c3
147+
check the update_time After Rollback, whether it is NULL
148+
SELECT table_name,update_time
149+
FROM information_schema.tables WHERE table_name='tab1';
150+
table_name update_time
151+
tab1 NULL
152+
CREATE TABLE tab2(
153+
id INT NOT NULL,
154+
store_name VARCHAR(30),
155+
parts VARCHAR(30),
156+
store_id INT
157+
) ENGINE=InnoDB
158+
PARTITION BY LIST(store_id) (
159+
PARTITION pNorth VALUES IN (10,20,30),
160+
PARTITION pEast VALUES IN (40,50,60),
161+
PARTITION pWest VALUES IN (70,80,100)
162+
);
163+
check the update_time Before DML, whether it is NULL
164+
SELECT table_name,update_time
165+
FROM information_schema.tables WHERE table_name='tab2';
166+
table_name update_time
167+
tab2 NULL
168+
#case5:
169+
#create proc with DML
170+
CREATE PROCEDURE proc_wl6658()
171+
BEGIN
172+
INSERT INTO tab2 VALUES(1,'ORACLE','NUTT',10);
173+
INSERT INTO tab2 VALUES(2,'HUAWEI','BOLT',40);
174+
COMMIT;
175+
END |
176+
CALL proc_wl6658;
177+
#check the records are inserted
178+
SELECT * FROM tab2 ORDER BY id,store_id;
179+
id store_name parts store_id
180+
1 ORACLE NUTT 10
181+
2 HUAWEI BOLT 40
182+
check the update_time After Commit, whether it is not NULL
183+
SELECT table_name,COUNT(update_time)
184+
FROM information_schema.tables WHERE table_name='tab2';
185+
table_name COUNT(update_time)
186+
tab2 1
187+
#delete all records
188+
TRUNCATE TABLE tab2;
189+
#restart the server
190+
# restart
191+
#case6:
192+
SET AUTOCOMMIT=off;
193+
BEGIN WORK;
194+
INSERT INTO tab2 VALUES(1,'Oracle','NUTT',10);
195+
SAVEPOINT A;
196+
INSERT INTO tab2 VALUES(2,'HUAWEI','BOLT',40);
197+
SAVEPOINT B;
198+
INSERT INTO tab2 VALUES(3,'IBM','NAIL',70);
199+
SAVEPOINT C;
200+
ROLLBACK to A;
201+
#check 1 record is inserted
202+
SELECT * FROM tab2;
203+
id store_name parts store_id
204+
1 Oracle NUTT 10
205+
check the update_time Before DML, whether it is NULL
206+
SELECT table_name,update_time
207+
FROM information_schema.tables WHERE table_name='tab2';
208+
table_name update_time
209+
tab2 NULL
210+
#execute DDL instead of commit
211+
create table tab6(c1 int);
212+
check the update_time After Commit, whether it is not NULL
213+
SELECT table_name,COUNT(update_time)
214+
FROM information_schema.tables WHERE table_name='tab2';
215+
table_name COUNT(update_time)
216+
tab2 1
217+
#case7:
218+
#create some base tables
219+
set the flag to default
220+
SET AUTOCOMMIT=Default;
221+
CREATE TABLE tab7(c1 INT NOT NULL, PRIMARY KEY (c1)) ENGINE=INNODB;
222+
CREATE TABLE tab8(c1 INT PRIMARY KEY,c2 INT,
223+
FOREIGN KEY (c2) REFERENCES tab7(c1) ON DELETE CASCADE )
224+
ENGINE=INNODB;
225+
check the update_time Before DML, whether it is NULL
226+
SELECT table_name,update_time
227+
FROM information_schema.tables WHERE table_name='tab7';
228+
table_name update_time
229+
tab7 NULL
230+
check the update_time Before DML, whether it is NULL
231+
SELECT table_name,update_time
232+
FROM information_schema.tables WHERE table_name='tab8';
233+
table_name update_time
234+
tab8 NULL
235+
INSERT INTO tab7 VALUES(1);
236+
INSERT INTO tab8 VALUES(1,1);
237+
#check the record is inserted
238+
SELECT * FROM tab7;
239+
c1
240+
1
241+
#check the record is inserted
242+
SELECT * FROM tab8;
243+
c1 c2
244+
1 1
245+
check the update_time After Autocommit, whether it is not NULL
246+
SELECT table_name,COUNT(update_time)
247+
FROM information_schema.tables WHERE table_name='tab7';
248+
table_name COUNT(update_time)
249+
tab7 1
250+
check the update_time After Autocommit, whether it is not NULL
251+
SELECT table_name,COUNT(update_time)
252+
FROM information_schema.tables WHERE table_name='tab8';
253+
table_name COUNT(update_time)
254+
tab8 1
255+
#restart the server
256+
# restart
257+
SET AUTOCOMMIT=off;
258+
START TRANSACTION;
259+
DELETE FROM tab7;
260+
ROLLBACK;
261+
#check record exist
262+
SELECT * FROM tab7;
263+
c1
264+
1
265+
#check record exist
266+
SELECT * FROM tab8;
267+
c1 c2
268+
1 1
269+
check the update_time After Rollback, whether it is NULL
270+
SELECT table_name,update_time
271+
FROM information_schema.tables WHERE table_name='tab7';
272+
table_name update_time
273+
tab7 NULL
274+
check the update_time After Rollback, whether it is NULL
275+
SELECT table_name,update_time
276+
FROM information_schema.tables WHERE table_name='tab8';
277+
table_name update_time
278+
tab8 NULL
279+
START TRANSACTION;
280+
DELETE FROM tab7;
281+
COMMIT;
282+
#check no record exist
283+
SELECT * FROM tab7;
284+
c1
285+
#check no record exist
286+
SELECT * FROM tab8;
287+
c1 c2
288+
check the update_time After Commit, whether it is not NULL
289+
SELECT table_name,COUNT(update_time)
290+
FROM information_schema.tables WHERE table_name='tab7';
291+
table_name COUNT(update_time)
292+
tab7 1
293+
check the update_time After Commit, whether it is not NULL
294+
SELECT table_name,COUNT(update_time)
295+
FROM information_schema.tables WHERE table_name='tab8';
296+
table_name COUNT(update_time)
297+
tab8 1
298+
#cleanup
299+
DROP TRIGGER test_trig;
300+
DROP TABLE tab1,tab2,tab3,tab4,tab5,tab6,tab8,tab7;
301+
DROP PROCEDURE proc_wl6658;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb-buffer-pool-size=10M

0 commit comments

Comments
 (0)