Skip to content

Commit cbb8b2d

Browse files
committed
More testcases.
1 parent ebe2bd7 commit cbb8b2d

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed

mysql-test/r/analyze_stmt_orderby.result

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f
381381
1 SIMPLE t3 ALL NULL NULL NULL NULL 1 0.00 100.00 100.00 Using filesort
382382
drop table t3;
383383
#
384-
#
384+
# A test for duplicate_removal()
385385
#
386386
create table t3 (a int, b int);
387387
insert into t3 select a, 123 from t0;
@@ -426,5 +426,109 @@ ANALYZE
426426
}
427427
}
428428
}
429+
#
430+
# A query with two filesort calls:
431+
# - first is needed to do group-by-group grouping to calculate COUNT(DISTINCT)
432+
# - the second is need to produce ORDER BY.
433+
# (see MDEV-7836 for description of the query plan)
434+
create table t5 (a int , b int) ;
435+
create table t6 like t5 ;
436+
create table t7 like t5 ;
437+
insert into t5 values (0, 100), (1, 2), (1, 3), (2, 2), (2, 7),
438+
(2, -1), (3, 10);
439+
insert into t6 values (0, 0), (1, 1), (2, 1), (3, 1), (4, 1);
440+
insert into t7 values (3, 3), (2, 2), (1, 1);
441+
# TODO: This ANALYZE output doesn't make it clear what is used for what.
442+
analyze format=json
443+
select count(distinct t5.b) as sum from t5, t6
444+
where t5.a=t6.a and t6.b > 0 and t5.a <= 5
445+
group by t5.a order by sum limit 1;
446+
ANALYZE
447+
{
448+
"query_block": {
449+
"select_id": 1,
450+
"r_loops": 1,
451+
"r_total_time_ms": "REPLACED",
452+
"filesort": {
453+
"r_loops": 1,
454+
"r_limit": 1,
455+
"r_used_priority_queue": true,
456+
"r_output_rows": 2,
457+
"filesort": {
458+
"r_loops": 1,
459+
"r_used_priority_queue": false,
460+
"r_output_rows": 6,
461+
"r_buffer_size": "REPLACED",
462+
"temporary_table": {
463+
"temporary_table": {
464+
"table": {
465+
"table_name": "t6",
466+
"access_type": "ALL",
467+
"r_loops": 1,
468+
"rows": 5,
469+
"r_rows": 5,
470+
"r_total_time_ms": "REPLACED",
471+
"filtered": 100,
472+
"r_filtered": 80,
473+
"attached_condition": "((t6.b > 0) and (t6.a <= 5))"
474+
},
475+
"block-nl-join": {
476+
"table": {
477+
"table_name": "t5",
478+
"access_type": "ALL",
479+
"r_loops": 1,
480+
"rows": 7,
481+
"r_rows": 7,
482+
"r_total_time_ms": "REPLACED",
483+
"filtered": 100,
484+
"r_filtered": 100
485+
},
486+
"buffer_type": "flat",
487+
"buffer_size": "128Kb",
488+
"join_type": "BNL",
489+
"attached_condition": "(t5.a = t6.a)",
490+
"r_filtered": 21.429
491+
}
492+
}
493+
}
494+
}
495+
}
496+
}
497+
}
498+
explain format=json
499+
select count(distinct t5.b) as sum from t5, t6
500+
where t5.a=t6.a and t6.b > 0 and t5.a <= 5
501+
group by t5.a order by sum limit 1;
502+
EXPLAIN
503+
{
504+
"query_block": {
505+
"select_id": 1,
506+
"filesort": {
507+
"temporary_table": {
508+
"function": "buffer",
509+
"table": {
510+
"table_name": "t6",
511+
"access_type": "ALL",
512+
"rows": 5,
513+
"filtered": 100,
514+
"attached_condition": "((t6.b > 0) and (t6.a <= 5))"
515+
},
516+
"block-nl-join": {
517+
"table": {
518+
"table_name": "t5",
519+
"access_type": "ALL",
520+
"rows": 7,
521+
"filtered": 100
522+
},
523+
"buffer_type": "flat",
524+
"buffer_size": "128Kb",
525+
"join_type": "BNL",
526+
"attached_condition": "(t5.a = t6.a)"
527+
}
528+
}
529+
}
530+
}
531+
}
532+
drop table t5,t6,t7;
429533
drop table t3;
430534
drop table t0,t1;

mysql-test/t/analyze_stmt_orderby.test

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ delete from t3 order by a;
110110
drop table t3;
111111

112112
--echo #
113-
--echo #
113+
--echo # A test for duplicate_removal()
114114
--echo #
115115
create table t3 (a int, b int);
116116
insert into t3 select a, 123 from t0;
@@ -119,5 +119,34 @@ insert into t3 select a, 123 from t0;
119119
analyze format=json
120120
select distinct max(t3.b) Q from t0, t3 where t0.a=t3.a group by t0.a order by null;
121121

122+
123+
--echo #
124+
--echo # A query with two filesort calls:
125+
--echo # - first is needed to do group-by-group grouping to calculate COUNT(DISTINCT)
126+
--echo # - the second is need to produce ORDER BY.
127+
--echo # (see MDEV-7836 for description of the query plan)
128+
129+
130+
create table t5 (a int , b int) ;
131+
create table t6 like t5 ;
132+
create table t7 like t5 ;
133+
insert into t5 values (0, 100), (1, 2), (1, 3), (2, 2), (2, 7),
134+
(2, -1), (3, 10);
135+
insert into t6 values (0, 0), (1, 1), (2, 1), (3, 1), (4, 1);
136+
insert into t7 values (3, 3), (2, 2), (1, 1);
137+
138+
--echo # TODO: This ANALYZE output doesn't make it clear what is used for what.
139+
--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ /"r_buffer_size": "[^"]+"/"r_buffer_size": "REPLACED"/
140+
analyze format=json
141+
select count(distinct t5.b) as sum from t5, t6
142+
where t5.a=t6.a and t6.b > 0 and t5.a <= 5
143+
group by t5.a order by sum limit 1;
144+
145+
explain format=json
146+
select count(distinct t5.b) as sum from t5, t6
147+
where t5.a=t6.a and t6.b > 0 and t5.a <= 5
148+
group by t5.a order by sum limit 1;
149+
drop table t5,t6,t7;
150+
122151
drop table t3;
123152
drop table t0,t1;

0 commit comments

Comments
 (0)