@@ -381,7 +381,7 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f
381
381
1 SIMPLE t3 ALL NULL NULL NULL NULL 1 0.00 100.00 100.00 Using filesort
382
382
drop table t3;
383
383
#
384
- #
384
+ # A test for duplicate_removal()
385
385
#
386
386
create table t3 (a int, b int);
387
387
insert into t3 select a, 123 from t0;
@@ -426,5 +426,109 @@ ANALYZE
426
426
}
427
427
}
428
428
}
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;
429
533
drop table t3;
430
534
drop table t0,t1;
0 commit comments