@@ -467,3 +467,116 @@ ANALYZE
467
467
}
468
468
}
469
469
drop table t0, t1;
470
+ #
471
+ # MDEV-7970: EXPLAIN FORMAT=JSON does not print HAVING
472
+ #
473
+ create table t0(a int);
474
+ insert into t0 values (0),(1),(2),(3);
475
+ create table t1(a int);
476
+ insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
477
+ create table t2 (
478
+ a int,
479
+ b int,
480
+ key (a)
481
+ );
482
+ insert into t2 select A.a*1000 + B.a, A.a*1000 + B.a from t0 A, t1 B;
483
+ # normal HAVING
484
+ analyze format=json select a, max(b) as TOP from t2 group by a having TOP > a;
485
+ ANALYZE
486
+ {
487
+ "query_block": {
488
+ "select_id": 1,
489
+ "r_loops": 1,
490
+ "r_total_time_ms": "REPLACED",
491
+ "having_condition": "(TOP > a)",
492
+ "filesort": {
493
+ "r_loops": 1,
494
+ "r_total_time_ms": "REPLACED",
495
+ "r_used_priority_queue": false,
496
+ "r_output_rows": 0,
497
+ "r_buffer_size": "5Kb",
498
+ "temporary_table": {
499
+ "table": {
500
+ "table_name": "t2",
501
+ "access_type": "ALL",
502
+ "r_loops": 1,
503
+ "rows": 256,
504
+ "r_rows": 256,
505
+ "r_total_time_ms": "REPLACED",
506
+ "filtered": 100,
507
+ "r_filtered": 100
508
+ }
509
+ }
510
+ }
511
+ }
512
+ }
513
+ # HAVING is always TRUE (not printed)
514
+ analyze format=json select a, max(b) as TOP from t2 group by a having 1<>2;
515
+ ANALYZE
516
+ {
517
+ "query_block": {
518
+ "select_id": 1,
519
+ "r_loops": 1,
520
+ "r_total_time_ms": "REPLACED",
521
+ "filesort": {
522
+ "r_loops": 1,
523
+ "r_total_time_ms": "REPLACED",
524
+ "r_used_priority_queue": false,
525
+ "r_output_rows": 256,
526
+ "r_buffer_size": "5Kb",
527
+ "temporary_table": {
528
+ "table": {
529
+ "table_name": "t2",
530
+ "access_type": "ALL",
531
+ "r_loops": 1,
532
+ "rows": 256,
533
+ "r_rows": 256,
534
+ "r_total_time_ms": "REPLACED",
535
+ "filtered": 100,
536
+ "r_filtered": 100
537
+ }
538
+ }
539
+ }
540
+ }
541
+ }
542
+ # HAVING is always FALSE (intercepted by message)
543
+ analyze format=json select a, max(b) as TOP from t2 group by a having 1=2;
544
+ ANALYZE
545
+ {
546
+ "query_block": {
547
+ "select_id": 1,
548
+ "table": {
549
+ "message": "Impossible HAVING"
550
+ }
551
+ }
552
+ }
553
+ # HAVING is absent
554
+ analyze format=json select a, max(b) as TOP from t2 group by a;
555
+ ANALYZE
556
+ {
557
+ "query_block": {
558
+ "select_id": 1,
559
+ "r_loops": 1,
560
+ "r_total_time_ms": "REPLACED",
561
+ "filesort": {
562
+ "r_loops": 1,
563
+ "r_total_time_ms": "REPLACED",
564
+ "r_used_priority_queue": false,
565
+ "r_output_rows": 256,
566
+ "r_buffer_size": "5Kb",
567
+ "temporary_table": {
568
+ "table": {
569
+ "table_name": "t2",
570
+ "access_type": "ALL",
571
+ "r_loops": 1,
572
+ "rows": 256,
573
+ "r_rows": 256,
574
+ "r_total_time_ms": "REPLACED",
575
+ "filtered": 100,
576
+ "r_filtered": 100
577
+ }
578
+ }
579
+ }
580
+ }
581
+ }
582
+ drop table t0, t1, t2;
0 commit comments