Skip to content

Commit

Permalink
MDEV-18478 ANALYZE for statement should show selectivity of ICP, part#1
Browse files Browse the repository at this point in the history
(Based on the original patch by Jason Cu)

Part #1:
- Add ha_handler_stats::{icp_attempts,icp_match}, make
  handler_index_cond_check() increment them.
- ANALYZE FORMAT=JSON now prints r_icp_filtered based on these counters.
  • Loading branch information
spetrunia committed Apr 23, 2024
1 parent 3f91821 commit e87d1e3
Show file tree
Hide file tree
Showing 9 changed files with 556 additions and 1 deletion.
415 changes: 415 additions & 0 deletions mysql-test/main/analyze_format_json.result

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions mysql-test/main/analyze_format_json.test
Expand Up @@ -269,4 +269,80 @@ where
set join_cache_level=@tmp;
drop table t10, t11;

--echo #
--echo # MDEV-18478: ANALYZE for statement should show selectivity of
--echo # pushed index condition
--echo #
create table t12 (a int, b varchar(10), c int, index(a,b), index(c));
create table t13 (a int not null primary key, b int, index(b));

insert into t12(a,b,c) values (1,"abc",100),
(2,"abd",200),(2,"bfd",300),(2,"efg",400),
(3,"abc",410),(3,"def",420),(3,"ghi",430),(3,"jkl",440),
(4,"abc",600),(4,"def",700),(4,"ghi",800),(4,"jkl",900);
insert into t13(a,b) values(1,1),(2,2),(3,3),(4,4),(5,5);
analyze table t12;
analyze table t13;

-- echo # eq key condition only, no pushed condition
# no r_pushed_condition in output because there is no pushed condition
# a=2 qualifies 3 rows (r_rows=3)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2;

-- echo # pushed index condition
# key condition a=2 gets 3 rows
# pushed condition b like '%f%' filters down to two of the 3 rows (66.667%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.b like '%f%';

-- echo # rowid filter only, no pushed condition
# key condition a=2 gets 3 rows
# rowid filter condition between 400 and 500 qualifies 1 of the 3 key rows (33.33%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.c
between 400 and 500;

-- echo # pushed index condition and rowid filter
# key condition a=2 gets 3 rows
# pushed condition b like '%f%' filters down to 2 of the 3 key rows (66.667%)
# rowid filter condition between 400 and 500 filters down to 1 of the icp 2 rows (50%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.c
between 400 and 500 and t12.b like '%f%';

-- echo # pushed index condition on the inner table (t12) of a join
# for inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 100% filtered by the index condition (t12.b like '%f%')
# for t13.a=2, 3 matching rows in t12, 66% filtered by the index cond
# r_rows_idx=2 (average 4 (1+3)/2 scans = 2 rows per scan)
# r_icp_filtered=50 (4 rows total, 2 survive the icp, both in the second scan)
--source include/analyze-format.inc
analyze format=json select * from t13,t12
where t13.a between 1 and 2 and t12.a=t13.a and t12.b like '%f%';

-- echo # rowid filter on inner table of a join, no ICP
# inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 0% survive the rowid filter (t12.c between 400 and 500)
# for t13.a=2, 3 matching rows in t12, 33% (1/3) survive the rowid filter
# rowid_filter r_lookups=2 (1+3 / 2 loops)
# rowid_filter r_selectivity_pct = 25 (1 / (1+3))
--source include/analyze-format.inc
analyze format=json select * from t13,t12 where t13.b between 1 and 2 and t12.a=t13.a and t12.c
between 400 and 450;

-- echo # rowid filter and ICP on inner table of a join
# inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 100% filtered by the index condition (t12.b like '%f%')
# for t13.a=2, 3 matching rows in t12, 66% filtered by the index cond
# r_rows_idx=2 (average 4 (1+3)/2 scans = 2 rows per scan)
# r_icp_filtered=50 (4 rows total, 2 survive the icp, both in the second scan)
# for t13.a=1, 0 rows after ICP
# for t13.a=2, 2 rows after ICP, 1 survives the rowid_filter (t12.c bewteen 400 and 500)
# rowid_filter r_lookups=2 (2 / 2 loops)
# rowid_filter r_selectivity_pct = 50 (1 survived / 2 rows after ICP)
--source include/analyze-format.inc
analyze format=json select * from t13,t12 where t13.b between 1 and 2 and t12.a=t13.a and t12.c
between 400 and 450 and t12.b like '%f%';

drop table t12,t13;
14 changes: 14 additions & 0 deletions mysql-test/main/rowid_filter.result
Expand Up @@ -154,6 +154,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.476269722,
"r_filtered": 100,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -269,6 +270,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.476269722,
"r_filtered": 9.742120344,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -418,6 +420,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "orders.o_totalprice between 200000 and 230000"
Expand Down Expand Up @@ -581,6 +584,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
Expand Down Expand Up @@ -763,6 +767,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.476269722,
"r_filtered": 100,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -928,6 +933,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.476269722,
"r_filtered": 9.742120344,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -1084,6 +1090,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "orders.o_totalprice between 200000 and 230000"
Expand Down Expand Up @@ -1268,6 +1275,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "orders.o_totalprice between 200000 and 230000"
Expand Down Expand Up @@ -1462,6 +1470,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1611,6 +1620,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1760,6 +1770,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 3.200000048,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -1910,6 +1921,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 3.200000048,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2073,6 +2085,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": {},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2233,6 +2246,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": {},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down
14 changes: 14 additions & 0 deletions mysql-test/main/rowid_filter_aria.result
Expand Up @@ -155,6 +155,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 11.80682755,
"r_filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
Expand Down Expand Up @@ -270,6 +271,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 11.80682755,
"r_filtered": 6.666666667,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
Expand Down Expand Up @@ -424,6 +426,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
Expand Down Expand Up @@ -583,6 +586,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
Expand Down Expand Up @@ -757,6 +761,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 11.80682755,
"r_filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
Expand Down Expand Up @@ -910,6 +915,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 11.80682755,
"r_filtered": 6.666666667,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
Expand Down Expand Up @@ -1067,6 +1073,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "orders.o_totalprice between 200000 and 230000"
Expand Down Expand Up @@ -1251,6 +1258,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 100,
"r_filtered": 100,
"index_condition": "orders.o_totalprice between 200000 and 230000"
Expand Down Expand Up @@ -1445,6 +1453,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.532889247,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1594,6 +1603,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.532889247,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1743,6 +1753,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 5,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -1893,6 +1904,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 5,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2056,6 +2068,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": {},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2216,6 +2229,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": {},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/main/rowid_filter_innodb.result
Expand Up @@ -157,6 +157,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.492922783,
"r_filtered": 100,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -272,6 +273,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.492922783,
"r_filtered": 9.742120344,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -742,6 +744,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 8.492922783,
"r_filtered": 100,
"index_condition": "lineitem.l_quantity > 47",
Expand Down Expand Up @@ -1411,6 +1414,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1560,6 +1564,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 0.566194832,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
Expand Down Expand Up @@ -1709,6 +1714,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 3.333333254,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -1859,6 +1865,7 @@ ANALYZE
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"r_icp_filtered": 100,
"filtered": 3.333333254,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2024,6 +2031,7 @@ ANALYZE
"r_engine_stats": {
"pages_accessed": 84
},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down Expand Up @@ -2188,6 +2196,7 @@ ANALYZE
"r_engine_stats": {
"pages_accessed": 84
},
"r_icp_filtered": 100,
"filtered": "REPLACED",
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
Expand Down

0 comments on commit e87d1e3

Please sign in to comment.