Skip to content

Commit dc1d621

Browse files
committed
MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins
In block-nl-join, add: - r_loops - this shows how many incoming record combinations this query plan node had. - r_effective_rows - this shows the average number of matching rows that this table had for each incoming record combination. This is comparable with r_rows in non-blocked access methods. For BNL-joins, it is always equal to $.table.r_rows * $.table.r_filtered For BNL-H joins the value cannot be computed from other values Reviewed by: Monty <monty@mariadb.org>
1 parent 169def1 commit dc1d621

14 files changed

+279
-30
lines changed

mysql-test/main/analyze_format_json.result

Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ ANALYZE
151151
"buffer_type": "flat",
152152
"buffer_size": "1Kb",
153153
"join_type": "BNL",
154-
"r_filtered": 100
154+
"r_loops": 20,
155+
"r_filtered": 100,
156+
"r_effective_rows": 60
155157
}
156158
}
157159
}
@@ -192,7 +194,9 @@ ANALYZE
192194
"buffer_size": "1Kb",
193195
"join_type": "BNL",
194196
"attached_condition": "tbl1.c > tbl2.c",
195-
"r_filtered": 15.83333333
197+
"r_loops": 20,
198+
"r_filtered": 15.83333333,
199+
"r_effective_rows": 60
196200
}
197201
}
198202
}
@@ -652,7 +656,9 @@ ANALYZE
652656
"buffer_size": "65",
653657
"join_type": "BNL",
654658
"attached_condition": "<in_optimizer>(t2.b,t2.b in (subquery#2))",
655-
"r_filtered": null
659+
"r_loops": 2,
660+
"r_filtered": null,
661+
"r_effective_rows": 0
656662
},
657663
"subqueries": [
658664
{
@@ -742,7 +748,9 @@ ANALYZE
742748
"buffer_type": "flat",
743749
"buffer_size": "1",
744750
"join_type": "BNL",
745-
"r_filtered": null
751+
"r_loops": 2,
752+
"r_filtered": null,
753+
"r_effective_rows": 0
746754
},
747755
"subqueries": [
748756
{
@@ -774,7 +782,9 @@ ANALYZE
774782
"buffer_size": "65",
775783
"join_type": "BNL",
776784
"attached_condition": "t2.f2 = t3.f3",
777-
"r_filtered": null
785+
"r_loops": 0,
786+
"r_filtered": null,
787+
"r_effective_rows": null
778788
}
779789
}
780790
}
@@ -849,3 +859,123 @@ ANALYZE
849859
}
850860
}
851861
drop table t0,t1,t2;
862+
#
863+
# MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins
864+
#
865+
create table t10 (
866+
a int,
867+
b int
868+
);
869+
insert into t10 select seq, seq/3 from seq_0_to_999;
870+
create table t11 (
871+
a int,
872+
b int
873+
);
874+
insert into t11 select seq, seq/5 from seq_0_to_999;
875+
analyze table t10,t11 persistent for all;
876+
Table Op Msg_type Msg_text
877+
test.t10 analyze status Engine-independent statistics collected
878+
test.t10 analyze status OK
879+
test.t11 analyze status Engine-independent statistics collected
880+
test.t11 analyze status OK
881+
analyze format=json
882+
select * from t10, t11
883+
where
884+
t10.a < 700 and
885+
t11.a < 100
886+
and t10.b=t11.b;
887+
ANALYZE
888+
{
889+
"query_block": {
890+
"select_id": 1,
891+
"r_loops": 1,
892+
"r_total_time_ms": "REPLACED",
893+
"table": {
894+
"table_name": "t11",
895+
"access_type": "ALL",
896+
"r_loops": 1,
897+
"rows": 1000,
898+
"r_rows": 1000,
899+
"r_table_time_ms": "REPLACED",
900+
"r_other_time_ms": "REPLACED",
901+
"filtered": 10.15625,
902+
"r_filtered": 10,
903+
"attached_condition": "t11.a < 100"
904+
},
905+
"block-nl-join": {
906+
"table": {
907+
"table_name": "t10",
908+
"access_type": "ALL",
909+
"r_loops": 1,
910+
"rows": 1000,
911+
"r_rows": 1000,
912+
"r_table_time_ms": "REPLACED",
913+
"r_other_time_ms": "REPLACED",
914+
"filtered": 70.3125,
915+
"r_filtered": 70,
916+
"attached_condition": "t10.a < 700"
917+
},
918+
"buffer_type": "flat",
919+
"buffer_size": "1Kb",
920+
"join_type": "BNL",
921+
"attached_condition": "t10.b = t11.b",
922+
"r_loops": 100,
923+
"r_filtered": 0.424285714,
924+
"r_effective_rows": 700
925+
}
926+
}
927+
}
928+
set @tmp=@@join_cache_level, join_cache_level=6;
929+
analyze format=json
930+
select * from t10, t11
931+
where
932+
t10.a < 700 and
933+
t11.a < 100
934+
and t10.b=t11.b;
935+
ANALYZE
936+
{
937+
"query_block": {
938+
"select_id": 1,
939+
"r_loops": 1,
940+
"r_total_time_ms": "REPLACED",
941+
"table": {
942+
"table_name": "t11",
943+
"access_type": "ALL",
944+
"r_loops": 1,
945+
"rows": 1000,
946+
"r_rows": 1000,
947+
"r_table_time_ms": "REPLACED",
948+
"r_other_time_ms": "REPLACED",
949+
"filtered": 10.15625,
950+
"r_filtered": 10,
951+
"attached_condition": "t11.a < 100 and t11.b is not null"
952+
},
953+
"block-nl-join": {
954+
"table": {
955+
"table_name": "t10",
956+
"access_type": "hash_ALL",
957+
"key": "#hash#$hj",
958+
"key_length": "5",
959+
"used_key_parts": ["b"],
960+
"ref": ["test.t11.b"],
961+
"r_loops": 1,
962+
"rows": 1000,
963+
"r_rows": 1000,
964+
"r_table_time_ms": "REPLACED",
965+
"r_other_time_ms": "REPLACED",
966+
"filtered": 70.3125,
967+
"r_filtered": 70,
968+
"attached_condition": "t10.a < 700"
969+
},
970+
"buffer_type": "flat",
971+
"buffer_size": "3Kb",
972+
"join_type": "BNLH",
973+
"attached_condition": "t10.b = t11.b",
974+
"r_loops": 100,
975+
"r_filtered": 100,
976+
"r_effective_rows": 2.97
977+
}
978+
}
979+
}
980+
set join_cache_level=@tmp;
981+
drop table t10, t11;

mysql-test/main/analyze_format_json.test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,45 @@ create table t2 as select * from t1;
226226
--source include/analyze-format.inc
227227
analyze format=json select a, (select t2.b from t2 where t2.a<t1.a order by t2.c limit 1) from t1 where t1.a<0;
228228
drop table t0,t1,t2;
229+
230+
231+
--echo #
232+
--echo # MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins
233+
--echo #
234+
--source include/have_sequence.inc
235+
create table t10 (
236+
a int,
237+
b int
238+
);
239+
insert into t10 select seq, seq/3 from seq_0_to_999;
240+
241+
create table t11 (
242+
a int,
243+
b int
244+
);
245+
insert into t11 select seq, seq/5 from seq_0_to_999;
246+
247+
analyze table t10,t11 persistent for all;
248+
249+
--source include/analyze-format.inc
250+
analyze format=json
251+
select * from t10, t11
252+
where
253+
t10.a < 700 and
254+
t11.a < 100
255+
and t10.b=t11.b;
256+
257+
set @tmp=@@join_cache_level, join_cache_level=6;
258+
259+
--source include/analyze-format.inc
260+
analyze format=json
261+
select * from t10, t11
262+
where
263+
t10.a < 700 and
264+
t11.a < 100
265+
and t10.b=t11.b;
266+
267+
set join_cache_level=@tmp;
268+
drop table t10, t11;
269+
270+

mysql-test/main/analyze_stmt_orderby.result

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ ANALYZE
441441
"buffer_size": "65",
442442
"join_type": "BNL",
443443
"attached_condition": "t3.a = t0.a",
444-
"r_filtered": 10
444+
"r_loops": 10,
445+
"r_filtered": 10,
446+
"r_effective_rows": 10
445447
}
446448
}
447449
}
@@ -516,7 +518,9 @@ ANALYZE
516518
"buffer_size": "119",
517519
"join_type": "BNL",
518520
"attached_condition": "t5.a = t6.a",
519-
"r_filtered": 21.42857143
521+
"r_loops": 4,
522+
"r_filtered": 21.42857143,
523+
"r_effective_rows": 7
520524
}
521525
}
522526
}

mysql-test/main/except.result

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ ANALYZE
334334
"buffer_type": "flat",
335335
"buffer_size": "119",
336336
"join_type": "BNL",
337-
"r_filtered": 100
337+
"r_loops": 2,
338+
"r_filtered": 100,
339+
"r_effective_rows": 2
338340
}
339341
}
340342
},
@@ -370,7 +372,9 @@ ANALYZE
370372
"buffer_type": "flat",
371373
"buffer_size": "119",
372374
"join_type": "BNL",
373-
"r_filtered": 100
375+
"r_loops": 2,
376+
"r_filtered": 100,
377+
"r_effective_rows": 2
374378
}
375379
}
376380
}
@@ -435,7 +439,9 @@ ANALYZE
435439
"buffer_type": "flat",
436440
"buffer_size": "119",
437441
"join_type": "BNL",
438-
"r_filtered": 100
442+
"r_loops": 2,
443+
"r_filtered": 100,
444+
"r_effective_rows": 2
439445
}
440446
}
441447
},
@@ -471,7 +477,9 @@ ANALYZE
471477
"buffer_type": "flat",
472478
"buffer_size": "119",
473479
"join_type": "BNL",
474-
"r_filtered": 100
480+
"r_loops": 2,
481+
"r_filtered": 100,
482+
"r_effective_rows": 2
475483
}
476484
}
477485
}

mysql-test/main/except_all.result

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ ANALYZE
453453
"buffer_type": "flat",
454454
"buffer_size": "119",
455455
"join_type": "BNL",
456-
"r_filtered": 100
456+
"r_loops": 3,
457+
"r_filtered": 100,
458+
"r_effective_rows": 3
457459
}
458460
}
459461
},
@@ -489,7 +491,9 @@ ANALYZE
489491
"buffer_type": "flat",
490492
"buffer_size": "119",
491493
"join_type": "BNL",
492-
"r_filtered": 100
494+
"r_loops": 2,
495+
"r_filtered": 100,
496+
"r_effective_rows": 3
493497
}
494498
}
495499
}
@@ -553,7 +557,9 @@ ANALYZE
553557
"buffer_type": "flat",
554558
"buffer_size": "119",
555559
"join_type": "BNL",
556-
"r_filtered": 100
560+
"r_loops": 3,
561+
"r_filtered": 100,
562+
"r_effective_rows": 3
557563
}
558564
}
559565
},
@@ -589,7 +595,9 @@ ANALYZE
589595
"buffer_type": "flat",
590596
"buffer_size": "119",
591597
"join_type": "BNL",
592-
"r_filtered": 100
598+
"r_loops": 2,
599+
"r_filtered": 100,
600+
"r_effective_rows": 3
593601
}
594602
}
595603
}

mysql-test/main/explain_json.result

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,9 @@ ANALYZE
15441544
"buffer_size": "400",
15451545
"join_type": "BKA",
15461546
"mrr_type": "Rowid-ordered scan",
1547-
"r_filtered": 100
1547+
"r_loops": 10,
1548+
"r_filtered": 100,
1549+
"r_effective_rows": 1
15481550
}
15491551
}
15501552
}

mysql-test/main/intersect.result

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ ANALYZE
395395
"buffer_type": "flat",
396396
"buffer_size": "256Kb",
397397
"join_type": "BNL",
398-
"r_filtered": 100
398+
"r_loops": 3,
399+
"r_filtered": 100,
400+
"r_effective_rows": 3
399401
}
400402
}
401403
}
@@ -478,7 +480,9 @@ ANALYZE
478480
"buffer_type": "flat",
479481
"buffer_size": "256Kb",
480482
"join_type": "BNL",
481-
"r_filtered": 100
483+
"r_loops": 3,
484+
"r_filtered": 100,
485+
"r_effective_rows": 3
482486
}
483487
}
484488
}

mysql-test/main/intersect_all.result

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ ANALYZE
426426
"buffer_type": "flat",
427427
"buffer_size": "65",
428428
"join_type": "BNL",
429-
"r_filtered": 100
429+
"r_loops": 5,
430+
"r_filtered": 100,
431+
"r_effective_rows": 7
430432
}
431433
}
432434
}
@@ -509,7 +511,9 @@ ANALYZE
509511
"buffer_type": "flat",
510512
"buffer_size": "65",
511513
"join_type": "BNL",
512-
"r_filtered": 100
514+
"r_loops": 5,
515+
"r_filtered": 100,
516+
"r_effective_rows": 7
513517
}
514518
}
515519
}

0 commit comments

Comments
 (0)