Debian Codegraph @

mysql-test/suite/x/t/performance_schema_stmt.test

raw
1 ## Tests detecting presence of SQL statements executed through
2 # plugin service in PERFORMANCE_SCHEMA.
3
4 ## Preamble
5 --source ../include/have_performance_schema_statements.inc
6 --source include/xplugin_preamble.inc
7 --source include/xplugin_create_user.inc
8
9 # Tests
10 --write_file $MYSQL_TMP_DIR/performance_schema_stmt.xpl
11 -->import sql_history.macro
12 -->quiet
13
14 -->sql
15 TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
16 SELECT 1;
17 SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR from performance_schema.events_statements_summary_by_digest ORDER BY DIGEST;
18 -->endsql
19
20 -->stmtsql CREATE SCHEMA xtest DEFAULT CHARSET 'utf8mb4';
21 -->recvresult
22
23 -->callmacro Clear_sql_history
24 -->echo ######### create_collection #########
25 -->stmtadmin create_collection {"schema":"xtest", "name":"test"}
26 -->recvresult
27 -->callmacro Show_sql_history
28
29 -->callmacro Clear_sql_history
30 -->echo ######### Crud.Insert #########
31 Mysqlx.Crud.Insert {
32 collection {
33 name: "test"
34 schema: "xtest"
35 }
36 data_model: DOCUMENT
37 row {
38 field {
39 type: LITERAL
40 literal {
41 type: V_STRING
42 v_string {
43 value: "{\"_id\": \"one\"}"
44 }
45 }
46 }
47 }
48 }
49 -->recvresult
50 -->callmacro Show_sql_history
51
52 -->callmacro Clear_sql_history
53 -->echo ######### Crud.Insert (upsert) #########
54 Mysqlx.Crud.Insert {
55 data_model: DOCUMENT
56 collection { name: 'test' schema: 'xtest'}
57 row{
58 field{
59 type: LITERAL literal {
60 type: V_OCTETS v_octets {
61 value:'{"_id": "two"}'
62 content_type:2
63 }
64 }
65 }
66 }
67 upsert: true
68 }
69 -->recvresult
70 -->callmacro Show_sql_history
71
72 -->callmacro Clear_sql_history
73 -->echo ######### Crud.Update #########
74 Mysqlx.Crud.Update {
75 collection {
76 name: "test"
77 schema: "xtest"
78 }
79 data_model: DOCUMENT
80 criteria {
81 type: OPERATOR
82 operator {
83 name: "=="
84 param {
85 type: IDENT
86 identifier {
87 name: "_id"
88 }
89 }
90 param {
91 type: LITERAL
92 literal {
93 type: V_STRING
94 v_string {value:"one"}
95 }
96 }
97 }
98 }
99 operation {
100 source {
101 document_path {
102 type: MEMBER
103 value: "key"
104 }
105 }
106 operation: ITEM_SET
107 value {
108 type: LITERAL
109 literal {
110 type: V_STRING
111 v_string {
112 value: "val"
113 }
114 }
115 }
116 }
117 }
118 -->recvresult
119 -->callmacro Show_sql_history
120
121 -->callmacro Clear_sql_history
122 -->echo ######### Crud.CreateView #########
123 Mysqlx.Crud.CreateView {
124 collection { name: "test_view" schema: "xtest" }
125 stmt: {
126 collection { name: "test" schema: "xtest" }
127 projection {
128 alias: "id"
129 source { type: IDENT identifier { name: "_id" } }
130 }
131 data_model: DOCUMENT
132 }
133 }
134 -->recvtype Mysqlx.Ok
135 -->callmacro Show_sql_history
136
137 -->callmacro Clear_sql_history
138 -->echo ######### Crud.ModifyView #########
139 Mysqlx.Crud.ModifyView {
140 collection { name: "test_view" schema: "xtest" }
141 stmt: {
142 collection { name: "test" schema: "xtest"}
143 projection {
144 alias: "id"
145 source { type: IDENT identifier { name: "_id" } }
146 }
147 data_model: DOCUMENT
148 }
149 }
150 -->recvtype Mysqlx.Ok
151 -->callmacro Show_sql_history
152
153 -->callmacro Clear_sql_history
154 -->echo ######### Crud.DropView #########
155 Mysqlx.Crud.DropView {
156 collection { name: "test_view" schema: "xtest" }
157 }
158 -->recvtype Mysqlx.Ok
159 -->callmacro Show_sql_history
160
161 -->callmacro Clear_sql_history
162 -->echo ######### Crud.Find #########
163 Mysqlx.Crud.Find {
164 collection {
165 name: "test"
166 schema: "xtest"
167 }
168 data_model: DOCUMENT
169 }
170 -->recvresult
171 -->callmacro Show_sql_history
172
173 -->callmacro Clear_sql_history
174 -->echo ######### Crud.Find with shared lock #########
175 Mysqlx.Crud.Find {
176 collection {
177 name: "test"
178 schema: "xtest"
179 }
180 data_model: DOCUMENT
181 locking: SHARED_LOCK
182 }
183 -->recvresult
184 -->callmacro Show_sql_history
185
186 -->callmacro Clear_sql_history
187 -->echo ######### Crud.Find with exclusive lock #########
188 Mysqlx.Crud.Find {
189 collection {
190 name: "test"
191 schema: "xtest"
192 }
193 data_model: DOCUMENT
194 locking: EXCLUSIVE_LOCK
195 }
196 -->recvresult
197 -->callmacro Show_sql_history
198
199 -->callmacro Clear_sql_history
200 -->echo ######### Crud.Delete #########
201 Mysqlx.Crud.Delete {
202 collection { name: "test" schema: "xtest"}
203 data_model: DOCUMENT
204 criteria {
205 type: OPERATOR operator {
206 name: "=="
207 param {
208 type: IDENT
209 identifier {
210 name: "_id"
211 }
212 }
213 param {
214 type: LITERAL literal { type: V_STRING v_string { value: "one" } }
215 }
216 }
217 }
218 }
219 -->recvresult
220 -->callmacro Show_sql_history
221
222 -->callmacro Clear_sql_history
223 -->echo ######### create_collection #########
224 -->stmtadmin create_collection {"schema":"xtest", "name":"test2"}
225 -->recvresult
226 -->callmacro Show_sql_history
227
228 -->callmacro Clear_sql_history
229 -->echo ######### ensure_collection #########
230 -->stmtadmin ensure_collection {"schema":"xtest", "name":"test2"}
231 -->recvresult
232 -->callmacro Show_sql_history
233
234 -->echo ######### get validation error when working with collections #########
235 stmtadmin create_collection {"schema": "xtest", "name": "test3", "options": {
236 "validation": {
237 "level": "STRICT",
238 "schema": {
239 "type": "object", "properties": {
240 "value": {"type": "number", "minimum": 0, "maximum": 10}
241 },
242 "required": ["value"]
243 }
244 }
245 }};
246 -->recvresult
247 -->callmacro Clear_sql_history
248 Mysqlx.Crud.Insert {
249 collection {
250 name: "test3"
251 schema: "xtest"
252 }
253 data_model: DOCUMENT
254 row {
255 field {
256 type: LITERAL
257 literal {
258 type: V_STRING
259 v_string {
260 value: "{\"_id\": \"one\", \"value\": 100}"
261 }
262 }
263 }
264 }
265 }
266 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
267 -->callmacro Show_sql_history
268 -->stmtadmin drop_collection {"schema":"xtest", "name":"test3"}
269 -->recvresult
270
271 -->callmacro Clear_sql_history
272 -->echo ######### create_collection_index #########
273 -->stmtadmin create_collection_index {"schema": "xtest", "collection":"test2", "name":"foo", "unique":true, "fields":{"field":"$.foo", "type":"TEXT(1)", "required":false}}
274 -->recvresult
275 -->callmacro Show_sql_history
276
277 -->callmacro Clear_sql_history
278 -->echo ######### drop_collection_index #########
279 -->stmtadmin drop_collection_index {"schema":"xtest", "collection":"test2", "name": "foo"}
280 -->recvresult
281 -->callmacro Show_sql_history
282
283 # silent call for establishing static variables
284 -->stmtadmin list_objects {"schema":"xtest"}
285 -->recvresult be-quiet
286
287 -->callmacro Clear_sql_history
288 -->echo ######### create_collection_index (spatial) #########
289 -->stmtadmin create_collection_index {"schema": "xtest", "collection":"test2", "name":"bar", "type":"spatial", "unique":false, "fields":{"field":"$.foo", "type":"GEOJSON", "required":true}}
290 -->recvresult
291 -->callmacro Show_sql_history
292
293 -->callmacro Clear_sql_history
294 -->echo ######### drop_collection_index (spatial) #########
295 -->stmtadmin drop_collection_index {"schema":"xtest", "collection":"test2", "name": "bar"}
296 -->recvresult
297 -->callmacro Show_sql_history
298
299 -->callmacro Clear_sql_history
300 -->echo ######### create_collection_index (fulltext) #########
301 -->stmtadmin create_collection_index {"schema": "xtest", "collection":"test2", "name":"foobar", "type":"fulltext", "unique":false, "with_parser":"ngram", "fields":{"field":"$.foo", "type":"FULLTEXT", "required":true}}
302 -->recvresult
303 -->callmacro Show_sql_history
304
305 -->callmacro Clear_sql_history
306 -->echo ######### drop_collection_index (fulltext) #########
307 -->stmtadmin drop_collection_index {"schema":"xtest", "collection":"test2", "name": "foobar"}
308 -->recvresult
309 -->callmacro Show_sql_history
310
311 -->callmacro Clear_sql_history
312 -->echo ######### list_objects #########
313 -->stmtadmin list_objects {"schema":"xtest"}
314 -->recvresult
315 -->callmacro Show_sql_history
316
317 -->callmacro Clear_sql_history
318 -->echo ######### drop_collection #########
319 -->stmtadmin drop_collection {"schema":"xtest", "name":"test2"}
320 -->recvresult
321 -->callmacro Show_sql_history
322
323 -->callmacro Clear_sql_history
324 -->echo ######### list_clients #########
325 -->sql
326 create user unpriv@localhost;
327 set password for unpriv@localhost = 'x';
328 -->endsql
329 -->stmtadmin list_clients
330 -->recvresult
331 -->callmacro Show_sql_history
332
333 -->callmacro Clear_sql_history
334 -->echo ######### kill_client #########
335 # Perfrom single authentication using mysql41.
336 # One query is going to be execute on mysql.user
337 # and must be visible in PFS.
338 -->newsession_mysql41 unpriv unpriv x
339 -->varlet %CLIENT_ID% %ACTIVE_CLIENT_ID%
340 -->newsession_mysql41 x_root x_root
341 -->stmtadmin kill_client {"id": %CLIENT_ID%}
342 -->recvresult
343 -->setsession unpriv
344 -->recvuntildisc
345 -->setsession x_root
346 -->stmtsql drop user unpriv@localhost;
347 -->recvresult
348 -->callmacro Show_sql_history
349
350 -->callmacro Clear_sql_history
351 -->echo ######### list_notices #########
352 -->stmtadmin list_notices
353 -->recvresult
354 -->callmacro Show_sql_history
355
356 -->callmacro Clear_sql_history
357 -->echo ######### disable_notices #########
358 -->stmtadmin disable_notices {"notice":"warnings"}
359 -->recvresult
360 Mysqlx.Sql.StmtExecute {
361 stmt: "SELECT 1/0"
362 }
363 -->recvresult
364 -->callmacro Show_sql_history
365
366 -->callmacro Clear_sql_history
367 -->echo ######### enable_notices #########
368 -->stmtadmin enable_notices {"notice":["warnings"]}
369 -->recvresult
370 Mysqlx.Sql.StmtExecute {
371 stmt: "SELECT 1/0"
372 }
373 -->recvresult
374 -->callmacro Show_sql_history
375
376 -->callmacro Clear_sql_history
377 -->echo ######### ping #########
378 -->stmtadmin ping
379 -->recvresult
380 -->callmacro Show_sql_history
381
382 EOF
383
384 --let $MACROS= --import=$MYSQLXTEST_MACRO_DIR
385 --replace_regex /BINARY // /KILL [0-9]+/KILL/ /([a-z]*.+localhost[ ]+)[0-9]+/\1$SESSION/
386 --exec $MYSQLXTEST -ux_root --password='' $MACROS --file=$MYSQL_TMP_DIR/performance_schema_stmt.xpl 2>&1
387
388 ## Cleanup
389 --source ../include/xplugin_cleanup.inc