Debian Codegraph @

mysql-test/suite/secondary_engine/t/query_preparation_debug.test

raw
1 --source include/have_debug.inc
2 --source include/have_debug_sync.inc
3
4 # Supplemental test case for query repreparation. Test what happens if
5 # EXECUTE fails to open the secondary tables after PREPARE has
6 # successfully opened them, using a debug flag to inject an error in
7 # EXECUTE.
8
9 --disable_query_log
10 eval INSTALL PLUGIN MOCK SONAME '$MOCK_PLUGIN';
11 --enable_query_log
12
13 CREATE TABLE t(x INT) SECONDARY_ENGINE MOCK;
14 INSERT INTO t VALUES (1);
15 ALTER TABLE t SECONDARY_LOAD;
16
17 # First execute the statement without the debug flag. The statement
18 # should be executed on the secondary engine.
19 FLUSH STATUS;
20 PREPARE ps FROM 'SELECT * FROM t';
21 EXECUTE ps;
22 SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
23
24 # Now set the debug flag. Execution fails when preparing the secondary
25 # engine. The failure triggers a repreparation against the primary
26 # storage engine.
27 FLUSH STATUS;
28 SET DEBUG = '+d,secondary_engine_mock_prepare_error';
29 EXECUTE ps;
30 SET DEBUG = '-d,secondary_engine_mock_prepare_error';
31 SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
32
33 # The statement remembers that the previous execution failed to open
34 # the secondary tables, so it will not attempt to use the secondary
35 # engine on re-execution.
36 FLUSH STATUS;
37 EXECUTE ps;
38 SHOW SESSION STATUS LIKE 'Secondary_engine_execution_count';
39
40 DROP TABLE t;
41
42 --echo #
43 --echo # WL#12389: Add interface for optimizing queries in secondary engines
44 --echo #
45
46 CREATE TABLE t1(x INT) SECONDARY_ENGINE MOCK;
47 INSERT INTO t1 VALUES (1), (2), (3);
48 CREATE TABLE t2(y INT) SECONDARY_ENGINE MOCK;
49 INSERT INTO t2 VALUES (3), (4), (5);
50 ALTER TABLE t1 SECONDARY_LOAD;
51 ALTER TABLE t2 SECONDARY_LOAD;
52 ANALYZE TABLE t1, t2;
53
54 # Verify that the secondary engine optimization was invoked by
55 # injecting an error in the secondary engine optimization. The error
56 # prevents the queries from being offloaded to the MOCK engine.
57 SET DEBUG = "+d,secondary_engine_mock_optimize_error";
58 FLUSH STATUS;
59 --sorted_result
60 SELECT * FROM t1;
61 --error ER_SECONDARY_ENGINE
62 SELECT /*+ SET_VAR(use_secondary_engine = FORCED) */ x FROM t1;
63 --sorted_result
64 SELECT (SELECT y FROM t2 WHERE y = 1) FROM t1;
65 --sorted_result
66 SELECT * FROM t1 UNION ALL SELECT * FROM t2;
67 --sorted_result
68 SELECT * FROM t1 UNION DISTINCT SELECT * FROM t2;
69 SET DEBUG = "-d,secondary_engine_mock_optimize_error";
70 SHOW STATUS LIKE 'Secondary_engine_execution_count'; # Should be 0
71
72 # The same queries should use the MOCK engine if no error is injected.
73 FLUSH STATUS;
74 SELECT * FROM t1;
75 SELECT (SELECT y FROM t2 WHERE y = 1) FROM t1;
76 SELECT * FROM t1 UNION ALL SELECT * FROM t2;
77 SELECT * FROM t1 UNION DISTINCT SELECT * FROM t2;
78 SHOW STATUS LIKE 'Secondary_engine_execution_count'; # Should be 4
79
80 DROP TABLE t1, t2;
81
82 # A query that is killed during secondary engine optimization, should
83 # not be retried in the primary engine.
84 CREATE TABLE t(x int) SECONDARY_ENGINE MOCK;
85 INSERT INTO t VALUES (1), (2), (3);
86 ALTER TABLE t SECONDARY_LOAD;
87 SET DEBUG_SYNC = 'before_mock_optimize SIGNAL mock WAIT_FOR continue';
88 --send SELECT * FROM t
89 --connect(conn1,localhost,root,,)
90 SET DEBUG_SYNC = 'now WAIT_FOR mock';
91 SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST
92 WHERE INFO = 'SELECT * FROM t' INTO @thread_id;
93 KILL QUERY @thread_id;
94 SET DEBUG_SYNC = 'now SIGNAL continue';
95 --connection default
96 --error ER_QUERY_INTERRUPTED
97 --reap
98 --disconnect conn1
99 DROP TABLE t;
100
101 --echo #
102 --echo # Bug#29615190: SELECTS ON TABLES OFFLOADED TO SECONDARY ENGINE ARE
103 --echo # WRITTEN TWICE TO THE MYSQLD GENERAL LOG
104 --echo #
105
106 # Test what is written to the general log if a statement is attempted
107 # offloaded, but rejected by the secondary engine. It used to be
108 # written three times to the general log. Once is enough.
109
110 CREATE TABLE t(x INT) SECONDARY_ENGINE MOCK;
111 ALTER TABLE t SECONDARY_LOAD;
112
113 SET @saved_general_log = @@global.general_log;
114 SET @saved_log_output = @@global.log_output;
115 SET GLOBAL general_log = 1;
116 SET GLOBAL log_output = 'table';
117 SET DEBUG = '+d,secondary_engine_mock_optimize_error';
118
119 TRUNCATE TABLE mysql.general_log;
120 SELECT * FROM t;
121 # Expect the query to be written once to the general log (or twice
122 # under ps protocol - once for preparation and once for execution).
123 --disable_query_log
124 eval SELECT COUNT(*) - $PS_PROTOCOL AS statement_count
125 FROM mysql.general_log
126 WHERE argument = 'SELECT * FROM t';
127 --enable_query_log
128 TRUNCATE TABLE mysql.general_log;
129 PREPARE ps FROM 'SELECT * FROM t';
130 SELECT COUNT(*) FROM mysql.general_log WHERE argument = 'SELECT * FROM t';
131 EXECUTE ps;
132 SELECT COUNT(*) FROM mysql.general_log WHERE argument = 'SELECT * FROM t';
133 DROP PREPARE ps;
134
135 SET GLOBAL general_log = @saved_general_log;
136 SET GLOBAL log_output = @saved_log_output;
137 SET DEBUG = '-d,secondary_engine_mock_optimize_error';
138
139 TRUNCATE TABLE mysql.general_log;
140 DROP TABLE t;
141
142 --disable_query_log
143 UNINSTALL PLUGIN mock;
144 --enable_query_log