summaryrefslogtreecommitdiff
path: root/mysql-test/main/show_analyze.result
blob: 5595fadd60b890d12e908e76e034273b9f9ded0e (plain)
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
drop table if exists t0, t1, t2, t3, t4;
drop view if exists v1;
SET @old_debug= @@session.debug;
set debug_sync='RESET';
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int);
alter table t1 add b int, add c int, add filler char(32);
insert into t1 select A.a, 10*B.a, 100*C.a, 'foo filler' from t0 A, t0 B, t0 C;
alter table t1 add key(a), add key(b);
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	Table is already up to date
show analyze for 1001;
ERROR HY000: Unknown thread id: 1001
show analyze for (select a from t0 limit 1);
ERROR HY000: You may only use constant expressions in this statement
connect  con1, localhost, root,,;
connection con1;
SET @old_debug= @@session.debug;
connection default;
show analyze for $thr2;
ERROR HY000: Target is not executing an operation with a query plan
show analyze for $thr1;
ERROR HY000: Target is not executing an operation with a query plan
connection con1;
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
select count(*) from t1 where c < 500;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1000	1000.00	50.00	50.00	Using where
Warnings:
Note	1003	select count(*) from t1 where c < 500
connection con1;
count(*)
500
select max(c) from t1 where c < 10;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1000	1000.00	10.00	10.00	Using where
Warnings:
Note	1003	select max(c) from t1 where c < 10
connection con1;
max(c)
0
# We can catch ANALYZE too.
analyze select max(c) from t1 where a < 10;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	1000	1000.00	99.90	100.00	Using where
Warnings:
Note	1003	analyze select max(c) from t1 where a < 10
connection con1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	1000	1000.00	99.90	100.00	Using where
SET debug_dbug=@old_debug;
# UNION, select, first branch
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
select max(a) from t0 A where a<=5 union select max(a+1) from t0 B where a>=9;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	0.00	NULL	NULL	
Warnings:
Note	1003	select max(a) from t0 A where a<=5 union select max(a+1) from t0 B where a>=9
connection con1;
max(a)
5
10
# UNION, select, second branch
set @show_explain_probe_select_id=2;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
select max(a) from t0 A where a<=5 union select max(a+1) from t0 B where a>=9;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	10.00	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	0.00	NULL	NULL	
Warnings:
Note	1003	select max(a) from t0 A where a<=5 union select max(a+1) from t0 B where a>=9
connection con1;
max(a)
5
10
# UNION, analyze, first branch
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
analyze select a from t0 A where a<=5 union select a+1 from t0 B where a>=9;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	0.00	NULL	NULL	
Warnings:
Note	1003	analyze select a from t0 A where a<=5 union select a+1 from t0 B where a>=9
connection con1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	10.00	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	7.00	NULL	NULL	
# UNION, analyze, second branch
set @show_explain_probe_select_id=2;
analyze select a from t0 A where a<=5 union select a+1 from t0 B where a>=9;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	10.00	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	0.00	NULL	NULL	
Warnings:
Note	1003	analyze select a from t0 A where a<=5 union select a+1 from t0 B where a>=9
connection con1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	60.00	Using where
2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	10.00	Using where
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	7.00	NULL	NULL	
SET debug_dbug=@old_debug;
# Uncorrelated  subquery, select
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
select a, (select max(a) from t0 B where a>6) from t0 A where a<2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
Warnings:
Note	1003	select a, (select max(a) from t0 B where a>6) from t0 A where a<2
connection con1;
a	(select max(a) from t0 B where a>6)
0	9
1	9
SET debug_dbug=@old_debug;
# Uncorrelated  subquery, analyze
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
analyze select a, (select max(a) from t0 B where a>6) from t0 A where a<2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
Warnings:
Note	1003	analyze select a, (select max(a) from t0 B where a>6) from t0 A where a<2
connection con1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
SET debug_dbug=@old_debug;
# correlated subquery, select, before execution start
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_start';
select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
Warnings:
Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2
connection con1;
a	(select max(a) from t0 b where b.a+a.a<10)
0	9
1	8
SET debug_dbug=@old_debug;
# correlated subquery, select, after execution
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	95.00	Using where
Warnings:
Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2
connection con1;
a	(select max(a) from t0 b where b.a+a.a<10)
0	9
1	8
SET debug_dbug=@old_debug;
# correlated subquery, analyze
set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
analyze select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	95.00	Using where
Warnings:
Note	1003	analyze select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<2
connection con1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	20.00	Using where
2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	95.00	Using where
SET debug_dbug=@old_debug;
# Try to do SHOW ANALYZE for a query that runs a  SET command:
#
set @show_explain_probe_select_id=2;
SET debug_dbug='+d,show_explain_probe_join_exec_start';
set @foo= (select max(a) from t0 where sin(a) >0);
connection default;
show analyze for $thr2;
ERROR HY000: Target is not executing an operation with a query plan
kill query $thr2;
connection con1;
ERROR 70100: Query execution was interrupted
SET debug_dbug=@old_debug;
#
# Attempt SHOW ANALYZE for an UPDATE
#
create table t2 as select a as a, a as dummy from t0 limit 2;
set @show_explain_probe_select_id=2;
SET debug_dbug='+d,show_explain_probe_join_exec_start';
update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	1.00	100.00	0.00	Using where
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
Warnings:
Note	1003	update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	2.00	100.00	0.00	Using where
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
Warnings:
Note	1003	update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3
connection con1;
drop table t2;
SET debug_dbug=@old_debug;
#
# Attempt SHOW ANALYZE for a DELETE
#
create table t2 as select a as a, a as dummy from t0 limit 2;
set @show_explain_probe_select_id=2;
SET debug_dbug='+d,show_explain_probe_join_exec_start';
delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	1.00	100.00	0.00	Using where
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
Warnings:
Note	1003	delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	2.00	100.00	0.00	Using where
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
Warnings:
Note	1003	delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3
connection con1;
drop table t2;
SET debug_dbug=@old_debug;
#
# Multiple SHOW ANALYZE calls for one select
#
create table t2 as select a as a, a as dummy from t0 limit 3;
set @show_explain_probe_select_id=2;
SET debug_dbug='+d,show_explain_probe_join_exec_start';
select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	1.00	100.00	100.00	
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	NULL	100.00	NULL	Using where
Warnings:
Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	2.00	100.00	100.00	
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	30.00	Using where
Warnings:
Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	3.00	100.00	100.00	
2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	25.00	Using where
Warnings:
Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
connection con1;
a	SUBQ
0	0
1	0
2	0
SET debug_dbug=@old_debug;
drop table t2;
#
# SHOW ANALYZE for SELECT ... ORDER BY with "Using filesort"
#
SET debug_dbug='+d,show_explain_probe_join_exec_end';
set @show_explain_probe_select_id=1;
select * from t0 order by a;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	100.00	Using filesort
Warnings:
Note	1003	select * from t0 order by a
connection con1;
a
0
1
2
3
4
5
6
7
8
9
SET debug_dbug=@old_debug;
#
# SHOW ANALYZE for SELECT ... with "Using temporary"
#
connection con1;
SET debug_dbug='+d,show_explain_probe_join_exec_end';
set @show_explain_probe_select_id=1;
select distinct a from t0;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	100.00	Using temporary
Warnings:
Note	1003	select distinct a from t0
connection con1;
a
0
1
2
3
4
5
6
7
8
9
SET debug_dbug=@old_debug;
#
# SHOW ANALYZE for SELECT ... with "Using temporary; Using filesort"
#
SET debug_dbug='+d,show_explain_probe_join_exec_end';
set @show_explain_probe_select_id=1;
select distinct a from t0;
connection default;
show analyze for $thr2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	r_rows	filtered	r_filtered	Extra
1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	10.00	100.00	100.00	Using temporary
Warnings:
Note	1003	select distinct a from t0
connection con1;
a
0
1
2
3
4
5
6
7
8
9
SET debug_dbug=@old_debug;
drop table t0,t1;
#
# MDEV-28124: Server crashes in Explain_aggr_filesort::print_json_members
# upon SHOW ANALYZE/EXPLAIN FORMAT=JSON
#
connection con1;
set @show_explain_probe_query= 'SELECT count(*) - count(*) FROM sys.waits_by_user_by_latency';
set debug_dbug='+d,explain_notify_tables_are_closed';
SELECT count(*) - count(*) FROM sys.waits_by_user_by_latency;
connection default;
SHOW ANALYZE FOR $thr2;
ERROR HY000: Target is not executing an operation with a query plan
connection con1;
count(*) - count(*)
0
# End
connection default;
disconnect con1;
set debug_sync='RESET';
#
# MDEV-28201: Server crashes upon SHOW ANALYZE/EXPLAIN FORMAT=JSON
#
CREATE TABLE t1 ( a varchar(1));
INSERT INTO t1 VALUES ('a'),('b');
ANALYZE format=json 
SELECT 1 FROM t1 GROUP BY convert_tz('1969-12-31 22:00:00',a,'+10:00');
ANALYZE
{
  "query_optimization": {
    "r_total_time_ms": "REPLACED"
  },
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": "REPLACED",
    "filesort": {
      "sort_key": "convert_tz('1969-12-31 22:00:00',t1.a,'+10:00')",
      "r_loops": 1,
      "r_total_time_ms": "REPLACED",
      "r_used_priority_queue": false,
      "r_output_rows": 1,
      "r_buffer_size": "REPLACED",
      "r_sort_mode": "sort_key,rowid",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "t1",
              "access_type": "ALL",
              "r_loops": 1,
              "rows": 2,
              "r_rows": 2,
              "r_table_time_ms": "REPLACED",
              "r_other_time_ms": "REPLACED",
              "filtered": 100,
              "r_filtered": 100
            }
          }
        ]
      }
    }
  }
}
DROP TABLE t1;