Skip to content

Commit fe3adde

Browse files
committed
MDEV-29060 main.view_debug fix
MDEV-28567 counted two execution sequences, there is third one which executes ALTER VIEW before f() is created. The more appropriate place for this test case is lock_sync.test
1 parent 2b9fb34 commit fe3adde

File tree

4 files changed

+143
-151
lines changed

4 files changed

+143
-151
lines changed

mysql-test/main/lock_sync.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,29 @@ SET DEBUG_SYNC="RESET";
878878
disconnect con1;
879879
disconnect con2;
880880
DROP TABLES t1, t2;
881+
#
882+
# MDEV-28567 Assertion `0' in open_tables upon function-related operation
883+
#
884+
CREATE TABLE t1 (a INT);
885+
CREATE TABLE t2 (b INT);
886+
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW UPDATE t2 SET b = 0;
887+
CREATE TRIGGER tr2 BEFORE INSERT ON t2 FOR EACH ROW UPDATE t1 SET a = 6;
888+
CREATE VIEW v1 AS SELECT * FROM t1;
889+
SET AUTOCOMMIT=OFF;
890+
SELECT * FROM t1;
891+
a
892+
DROP TRIGGER tr1;
893+
INSERT INTO t2 SELECT * FROM t2;
894+
SELECT f() FROM t2;
895+
ERROR 42000: FUNCTION test.f does not exist
896+
set debug_sync= 'after_open_table_mdl_shared signal s1';
897+
ALTER VIEW v1 AS SELECT f() FROM t1;
898+
CREATE FUNCTION f() RETURNS INT RETURN 1;
899+
set debug_sync= 'now wait_for s1';
900+
SELECT * FROM ( SELECT * FROM v1 ) sq;
901+
a
902+
COMMIT;
903+
DROP VIEW v1;
904+
DROP FUNCTION f;
905+
DROP TABLE t1, t2;
906+
set debug_sync= 'reset';

mysql-test/main/lock_sync.test

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,120 @@ DROP TABLES t1, t2;
11031103
# Check that all connections opened by test cases in this file are really
11041104
# gone so execution of other tests won't be affected by their presence.
11051105
--source include/wait_until_count_sessions.inc
1106+
1107+
--echo #
1108+
--echo # MDEV-28567 Assertion `0' in open_tables upon function-related operation
1109+
--echo #
1110+
# To get MDL trace run this case like this:
1111+
# mtr --mysqld=--debug=d,mdl,query:i:o,/tmp/mdl.log ...
1112+
# Cleanup trace like this:
1113+
# sed -i -re '/(mysql|performance_schema|sys|mtr)\// d; /MDL_BACKUP_|MDL_INTENTION_/ d; /\/(t2|tr1|tr2)/ d' /tmp/mdl.log
1114+
1115+
CREATE TABLE t1 (a INT);
1116+
CREATE TABLE t2 (b INT);
1117+
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW UPDATE t2 SET b = 0;
1118+
CREATE TRIGGER tr2 BEFORE INSERT ON t2 FOR EACH ROW UPDATE t1 SET a = 6;
1119+
CREATE VIEW v1 AS SELECT * FROM t1;
1120+
1121+
SET AUTOCOMMIT=OFF;
1122+
SELECT * FROM t1;
1123+
# T@6
1124+
# Seized: test/t1 (MDL_SHARED_READ)
1125+
1126+
--connect (con1,localhost,root,,test)
1127+
--send
1128+
DROP TRIGGER tr1;
1129+
# T@7
1130+
# Seized: test/t1 (MDL_SHARED_NO_WRITE)
1131+
# Waiting: test/t1 (MDL_EXCLUSIVE)
1132+
# Waiting: test/t1 (MDL_SHARED_WRITE)
1133+
# Deadlock: test/t1 (MDL_SHARED_WRITE)
1134+
1135+
--connection default
1136+
--error 0, ER_LOCK_DEADLOCK
1137+
INSERT INTO t2 SELECT * FROM t2;
1138+
# T@6
1139+
# Released: test/t1 (MDL_SHARED_READ)
1140+
# T@7
1141+
# Acquired: test/t1 (MDL_EXCLUSIVE) (good)
1142+
--error ER_SP_DOES_NOT_EXIST
1143+
SELECT f() FROM t2;
1144+
# T@6
1145+
# Seized: test/f (MDL_SHARED)
1146+
# T@7
1147+
# Released: test/t1 (MDL_EXCLUSIVE)
1148+
# Good1: continue T@6 below
1149+
# Bad1: continue T@8 below
1150+
1151+
# Now we hold test/f, the below code creates concurrent
1152+
# waiting of 3 threads for test/f which leads to deadlock (Bad)
1153+
1154+
# To achive Good comment out 'now wait_for s1' below and run multiple times.
1155+
1156+
--connect (con2,localhost,root,,test)
1157+
set debug_sync= 'after_open_table_mdl_shared signal s1';
1158+
--send
1159+
ALTER VIEW v1 AS SELECT f() FROM t1;
1160+
# T@8
1161+
# Good2: Waiting: test/v1 (MDL_EXCLUSIVE)
1162+
# Good2-3: continue T@7 below
1163+
# Good5: Acquired: test/v1 (MDL_EXCLUSIVE)
1164+
# Good5: Seized: test/v1 (MDL_EXCLUSIVE)
1165+
# Good5-6: continue T@7 below
1166+
# Good7: Seized: test/t1 (MDL_SHARED_READ)
1167+
# Good7: Waiting: test/f (MDL_SHARED)
1168+
# Good7-8: continue T@7 below
1169+
# Good9: Acquired: test/f (MDL_SHARED)
1170+
# Good9: Released: test/f (MDL_SHARED)
1171+
# Good9: Released: test/t1 (MDL_SHARED_READ)
1172+
# Good9: Released: test/v1 (MDL_EXCLUSIVE)
1173+
# Good9: command finished without error
1174+
# Bad1: Seized: test/v1 (MDL_EXCLUSIVE)
1175+
# Bad1: Seized: test/v1 (MDL_EXCLUSIVE)
1176+
# Bad1: Seized: test/t1 (MDL_SHARED_READ)
1177+
# Bad1-2: continue T@6 below
1178+
# Bad4: Waiting: test/f (MDL_SHARED)
1179+
# Bad4: Deadlock: test/f (MDL_SHARED)
1180+
# Bad4: command finished with error
1181+
1182+
--connection con1
1183+
--reap
1184+
--send
1185+
CREATE FUNCTION f() RETURNS INT RETURN 1;
1186+
# T@7
1187+
# Good3: Waiting: test/f (MDL_EXCLUSIVE)
1188+
# Good3-4: continue T@6 below
1189+
# Good6: Acquired: test/f (MDL_EXCLUSIVE)
1190+
# Good6-7: continue T@8 above
1191+
# Good8: Released: test/f (MDL_EXCLUSIVE)
1192+
# Good8-9: continue T@8 above
1193+
# Bad3: Waiting: test/f (MDL_EXCLUSIVE)
1194+
# Bad3-4: continue T@8 above
1195+
1196+
--connection default
1197+
set debug_sync= 'now wait_for s1';
1198+
SELECT * FROM ( SELECT * FROM v1 ) sq;
1199+
# T@6
1200+
# Good1: Seized: test/v1 (MDL_SHARED_READ)
1201+
# Good1-2: continue T@8 above
1202+
# Good4: Seized: test/t1 (MDL_SHARED_READ)
1203+
# Bad2: Waiting: test/v1 (MDL_SHARED_READ)
1204+
# Bad2-3: continue T@7 above
1205+
1206+
# Cleanup
1207+
COMMIT;
1208+
# Good4: Released: test/t1 (MDL_SHARED_READ)
1209+
# Good4: Released: test/v1 (MDL_SHARED_READ)
1210+
# Good4: Released: test/f (MDL_SHARED)
1211+
# Good4-5: continue T@8 above
1212+
1213+
--connection con2
1214+
--error 0, ER_SP_DOES_NOT_EXIST
1215+
--reap
1216+
--disconnect con1
1217+
--disconnect con2
1218+
--connection default
1219+
DROP VIEW v1;
1220+
DROP FUNCTION f;
1221+
DROP TABLE t1, t2;
1222+
set debug_sync= 'reset';

mysql-test/main/view_debug.result

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,3 @@ disconnect con2;
2626
connection default;
2727
drop procedure proc;
2828
drop view v1,v2;
29-
#
30-
# MDEV-28567 Assertion `0' in open_tables upon function-related operation
31-
#
32-
CREATE TABLE t1 (a INT);
33-
CREATE TABLE t2 (b INT);
34-
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW UPDATE t2 SET b = 0;
35-
CREATE TRIGGER tr2 BEFORE INSERT ON t2 FOR EACH ROW UPDATE t1 SET a = 6;
36-
CREATE VIEW v1 AS SELECT * FROM t1;
37-
SET AUTOCOMMIT=OFF;
38-
SELECT * FROM t1;
39-
a
40-
connect con1,localhost,root,,test;
41-
DROP TRIGGER tr1;
42-
connection default;
43-
INSERT INTO t2 SELECT * FROM t2;
44-
SELECT f() FROM t2;
45-
ERROR 42000: FUNCTION test.f does not exist
46-
connect con2,localhost,root,,test;
47-
set debug_sync= 'after_open_table_mdl_shared signal s1';
48-
ALTER VIEW v1 AS SELECT f() FROM t1;
49-
connection con1;
50-
CREATE FUNCTION f() RETURNS INT RETURN 1;
51-
connection default;
52-
set debug_sync= 'now wait_for s1';
53-
SELECT * FROM ( SELECT * FROM v1 ) sq;
54-
a
55-
COMMIT;
56-
connection con2;
57-
disconnect con1;
58-
disconnect con2;
59-
connection default;
60-
DROP VIEW v1;
61-
DROP FUNCTION f;
62-
DROP TABLE t1, t2;
63-
set debug_sync= 'reset';

mysql-test/main/view_debug.test

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -36,119 +36,3 @@ SET DEBUG_SYNC= 'RESET';
3636
--connection default
3737
drop procedure proc;
3838
drop view v1,v2;
39-
40-
--echo #
41-
--echo # MDEV-28567 Assertion `0' in open_tables upon function-related operation
42-
--echo #
43-
# To get MDL trace run this case like this:
44-
# mtr --mysqld=--debug=d,mdl,query:i:o,/tmp/mdl.log ...
45-
# Cleanup trace like this:
46-
# sed -i -re '/(mysql|performance_schema|sys|mtr)\// d; /MDL_BACKUP_|MDL_INTENTION_/ d; /\/(t2|tr1|tr2)/ d' /tmp/mdl.log
47-
48-
CREATE TABLE t1 (a INT);
49-
CREATE TABLE t2 (b INT);
50-
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW UPDATE t2 SET b = 0;
51-
CREATE TRIGGER tr2 BEFORE INSERT ON t2 FOR EACH ROW UPDATE t1 SET a = 6;
52-
CREATE VIEW v1 AS SELECT * FROM t1;
53-
54-
SET AUTOCOMMIT=OFF;
55-
SELECT * FROM t1;
56-
# T@6
57-
# Seized: test/t1 (MDL_SHARED_READ)
58-
59-
--connect (con1,localhost,root,,test)
60-
--send
61-
DROP TRIGGER tr1;
62-
# T@7
63-
# Seized: test/t1 (MDL_SHARED_NO_WRITE)
64-
# Waiting: test/t1 (MDL_EXCLUSIVE)
65-
# Waiting: test/t1 (MDL_SHARED_WRITE)
66-
# Deadlock: test/t1 (MDL_SHARED_WRITE)
67-
68-
--connection default
69-
--error 0, ER_LOCK_DEADLOCK
70-
INSERT INTO t2 SELECT * FROM t2;
71-
# T@6
72-
# Released: test/t1 (MDL_SHARED_READ)
73-
# T@7
74-
# Acquired: test/t1 (MDL_EXCLUSIVE) (good)
75-
--error ER_SP_DOES_NOT_EXIST
76-
SELECT f() FROM t2;
77-
# T@6
78-
# Seized: test/f (MDL_SHARED)
79-
# T@7
80-
# Released: test/t1 (MDL_EXCLUSIVE)
81-
# Good1: continue T@6 below
82-
# Bad1: continue T@8 below
83-
84-
# Now we hold test/f, the below code creates concurrent
85-
# waiting of 3 threads for test/f which leads to deadlock (Bad)
86-
87-
# To achive Good comment out 'now wait_for s1' below and run multiple times.
88-
89-
--connect (con2,localhost,root,,test)
90-
set debug_sync= 'after_open_table_mdl_shared signal s1';
91-
--send
92-
ALTER VIEW v1 AS SELECT f() FROM t1;
93-
# T@8
94-
# Good2: Waiting: test/v1 (MDL_EXCLUSIVE)
95-
# Good2-3: continue T@7 below
96-
# Good5: Acquired: test/v1 (MDL_EXCLUSIVE)
97-
# Good5: Seized: test/v1 (MDL_EXCLUSIVE)
98-
# Good5-6: continue T@7 below
99-
# Good7: Seized: test/t1 (MDL_SHARED_READ)
100-
# Good7: Waiting: test/f (MDL_SHARED)
101-
# Good7-8: continue T@7 below
102-
# Good9: Acquired: test/f (MDL_SHARED)
103-
# Good9: Released: test/f (MDL_SHARED)
104-
# Good9: Released: test/t1 (MDL_SHARED_READ)
105-
# Good9: Released: test/v1 (MDL_EXCLUSIVE)
106-
# Good9: command finished without error
107-
# Bad1: Seized: test/v1 (MDL_EXCLUSIVE)
108-
# Bad1: Seized: test/v1 (MDL_EXCLUSIVE)
109-
# Bad1: Seized: test/t1 (MDL_SHARED_READ)
110-
# Bad1-2: continue T@6 below
111-
# Bad4: Waiting: test/f (MDL_SHARED)
112-
# Bad4: Deadlock: test/f (MDL_SHARED)
113-
# Bad4: command finished with error
114-
115-
--connection con1
116-
--reap
117-
--send
118-
CREATE FUNCTION f() RETURNS INT RETURN 1;
119-
# T@7
120-
# Good3: Waiting: test/f (MDL_EXCLUSIVE)
121-
# Good3-4: continue T@6 below
122-
# Good6: Acquired: test/f (MDL_EXCLUSIVE)
123-
# Good6-7: continue T@8 above
124-
# Good8: Released: test/f (MDL_EXCLUSIVE)
125-
# Good8-9: continue T@8 above
126-
# Bad3: Waiting: test/f (MDL_EXCLUSIVE)
127-
# Bad3-4: continue T@8 above
128-
129-
--connection default
130-
set debug_sync= 'now wait_for s1';
131-
SELECT * FROM ( SELECT * FROM v1 ) sq;
132-
# T@6
133-
# Good1: Seized: test/v1 (MDL_SHARED_READ)
134-
# Good1-2: continue T@8 above
135-
# Good4: Seized: test/t1 (MDL_SHARED_READ)
136-
# Bad2: Waiting: test/v1 (MDL_SHARED_READ)
137-
# Bad2-3: continue T@7 above
138-
139-
# Cleanup
140-
COMMIT;
141-
# Good4: Released: test/t1 (MDL_SHARED_READ)
142-
# Good4: Released: test/v1 (MDL_SHARED_READ)
143-
# Good4: Released: test/f (MDL_SHARED)
144-
# Good4-5: continue T@8 above
145-
146-
--connection con2
147-
--reap
148-
--disconnect con1
149-
--disconnect con2
150-
--connection default
151-
DROP VIEW v1;
152-
DROP FUNCTION f;
153-
DROP TABLE t1, t2;
154-
set debug_sync= 'reset';

0 commit comments

Comments
 (0)