diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index 00fdc10f84a40..eada44e8e8425 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -453,6 +453,7 @@ ANALYZE "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, + "r_icp_filtered": 100, "filtered": 100, "r_filtered": 50, "index_condition": "t1.pk < 10", @@ -1291,3 +1292,417 @@ ANALYZE } set join_cache_level=@tmp; drop table t10, t11; +# +# MDEV-18478: ANALYZE for statement should show selectivity of +# pushed index condition +# +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; +Table Op Msg_type Msg_text +test.t12 analyze status Engine-independent statistics collected +test.t12 analyze status OK +analyze table t13; +Table Op Msg_type Msg_text +test.t13 analyze status Engine-independent statistics collected +test.t13 analyze status OK +# eq key condition only, no pushed condition +analyze format=json select * from t12 where t12.a=2; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["const"], + "loops": 1, + "r_loops": 1, + "rows": 3, + "r_rows": 3, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "filtered": 100, + "r_filtered": 100 + } + } + ] + } +} +# pushed index condition +analyze format=json select * from t12 where t12.a=2 and t12.b like '%f%'; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["const"], + "loops": 1, + "r_loops": 1, + "rows": 3, + "r_rows": 2, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "r_icp_filtered": 66.66666667, + "filtered": 100, + "r_filtered": 100, + "index_condition": "t12.b like '%f%'" + } + } + ] + } +} +# rowid filter only, no pushed condition +analyze format=json select * from t12 where t12.a=2 and t12.c +between 400 and 500; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a", "c"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "c", + "used_key_parts": ["c"] + }, + "rows": 5, + "selectivity_pct": 41.66666667, + "r_rows": 5, + "r_lookups": 3, + "r_selectivity_pct": 33.33333333, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, + "loops": 1, + "r_loops": 1, + "rows": 3, + "r_rows": 1, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "filtered": 41.66666794, + "r_filtered": 100, + "attached_condition": "t12.c between 400 and 500" + } + } + ] + } +} +# pushed index condition and rowid filter +analyze format=json select * from t12 where t12.a=2 and t12.c +between 400 and 500 and t12.b like '%f%'; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a", "c"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "c", + "used_key_parts": ["c"] + }, + "rows": 5, + "selectivity_pct": 41.66666667, + "r_rows": 5, + "r_lookups": 2, + "r_selectivity_pct": 50, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, + "loops": 1, + "r_loops": 1, + "rows": 3, + "r_rows": 1, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "r_icp_filtered": 66.66666667, + "filtered": 41.66666794, + "r_filtered": 100, + "index_condition": "t12.b like '%f%'", + "attached_condition": "t12.c between 400 and 500" + } + } + ] + } +} +# pushed index condition on the inner table (t12) of a join +analyze format=json select * from t13,t12 +where t13.a between 1 and 2 and t12.a=t13.a and t12.b like '%f%'; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t13", + "access_type": "range", + "possible_keys": ["PRIMARY"], + "key": "PRIMARY", + "key_length": "4", + "used_key_parts": ["a"], + "loops": 1, + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "cost": "REPLACED", + "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": "t13.a between 1 and 2" + } + }, + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t13.a"], + "loops": 2, + "r_loops": 2, + "rows": 3, + "r_rows": 1, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "r_icp_filtered": 50, + "filtered": 100, + "r_filtered": 100, + "index_condition": "t12.b like '%f%'" + } + } + ] + } +} +# rowid filter on inner table of a join, no ICP +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; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t13", + "access_type": "range", + "possible_keys": ["PRIMARY", "b"], + "key": "b", + "key_length": "5", + "used_key_parts": ["b"], + "loops": 1, + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "cost": "REPLACED", + "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": "t13.b between 1 and 2" + } + }, + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a", "c"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t13.a"], + "rowid_filter": { + "range": { + "key": "c", + "used_key_parts": ["c"] + }, + "rows": 5, + "selectivity_pct": 41.66666667, + "r_rows": 5, + "r_lookups": 4, + "r_selectivity_pct": 25, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, + "loops": 2, + "r_loops": 2, + "rows": 3, + "r_rows": 0.5, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "filtered": 41.66666794, + "r_filtered": 100, + "attached_condition": "t12.c between 400 and 450" + } + } + ] + } +} +# rowid filter and ICP on inner table of a join +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%'; +ANALYZE +{ + "query_optimization": { + "r_total_time_ms": "REPLACED" + }, + "query_block": { + "select_id": 1, + "cost": "REPLACED", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "nested_loop": [ + { + "table": { + "table_name": "t13", + "access_type": "range", + "possible_keys": ["PRIMARY", "b"], + "key": "b", + "key_length": "5", + "used_key_parts": ["b"], + "loops": 1, + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "cost": "REPLACED", + "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": "t13.b between 1 and 2" + } + }, + { + "table": { + "table_name": "t12", + "access_type": "ref", + "possible_keys": ["a", "c"], + "key": "a", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t13.a"], + "rowid_filter": { + "range": { + "key": "c", + "used_key_parts": ["c"] + }, + "rows": 5, + "selectivity_pct": 41.66666667, + "r_rows": 5, + "r_lookups": 2, + "r_selectivity_pct": 50, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, + "loops": 2, + "r_loops": 2, + "rows": 3, + "r_rows": 0.5, + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": REPLACED, + "r_icp_filtered": 50, + "filtered": 41.66666794, + "r_filtered": 100, + "index_condition": "t12.b like '%f%'", + "attached_condition": "t12.c between 400 and 450" + } + } + ] + } +} +drop table t12,t13; diff --git a/mysql-test/main/analyze_format_json.test b/mysql-test/main/analyze_format_json.test index 001616304cf38..87ed02d0406a3 100644 --- a/mysql-test/main/analyze_format_json.test +++ b/mysql-test/main/analyze_format_json.test @@ -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; diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index 11f92f5b6dda5..0bd4bb6ac5720 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -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", @@ -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", @@ -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" @@ -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'" @@ -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", @@ -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", @@ -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" @@ -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" @@ -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'", @@ -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'", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/mysql-test/main/rowid_filter_aria.result b/mysql-test/main/rowid_filter_aria.result index aa31a247f5fb9..98ae536023237 100644 --- a/mysql-test/main/rowid_filter_aria.result +++ b/mysql-test/main/rowid_filter_aria.result @@ -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'", @@ -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'", @@ -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'" @@ -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'" @@ -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'", @@ -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'", @@ -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" @@ -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" @@ -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'", @@ -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'", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 24b80881c6e01..31d412c17af68 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -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", @@ -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", @@ -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", @@ -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'", @@ -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'", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/mysql-test/main/rowid_filter_myisam.result b/mysql-test/main/rowid_filter_myisam.result index ecc6a9f3186a6..a9dac9368d092 100644 --- a/mysql-test/main/rowid_filter_myisam.result +++ b/mysql-test/main/rowid_filter_myisam.result @@ -359,6 +359,7 @@ ANALYZE "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, + "r_icp_filtered": 100, "filtered": 49.20000076, "r_filtered": 100, "index_condition": "t1.nm like '500%'", @@ -416,6 +417,7 @@ ANALYZE "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, + "r_icp_filtered": 100, "filtered": 49.20000076, "r_filtered": 100, "index_condition": "t1.nm like '500%'", @@ -616,6 +618,7 @@ ANALYZE "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, + "r_icp_filtered": 100, "filtered": 8.630000114, "r_filtered": 0, "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", @@ -673,6 +676,7 @@ ANALYZE "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, + "r_icp_filtered": 100, "filtered": 8.529999733, "r_filtered": 100, "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", diff --git a/sql/ha_handler_stats.h b/sql/ha_handler_stats.h index 726ba6041dc3a..121c1cc625878 100644 --- a/sql/ha_handler_stats.h +++ b/sql/ha_handler_stats.h @@ -29,9 +29,18 @@ class ha_handler_stats ulonglong pages_read_time; /* Time reading pages, in microsec. */ ulonglong undo_records_read; ulonglong engine_time; /* Time spent in engine in microsec */ + /* + Index Condition Pushdown: number of times condition was checked for index + tuple + */ + ulonglong icp_attempts; + /* + Index Condition Pushdown: number of times condition check evaluated to TRUE + */ + ulonglong icp_match; uint active; /* <> 0 if status has to be updated */ #define first_stat pages_accessed -#define last_stat engine_time +#define last_stat icp_match inline void reset() { bzero((void*) this, sizeof(*this)); diff --git a/sql/handler.cc b/sql/handler.cc index 515c729ce163f..b52551fee31dd 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7008,11 +7008,13 @@ extern "C" check_result_t handler_index_cond_check(void* h_arg) if (unlikely(h->end_range) && h->compare_key2(h->end_range) > 0) return CHECK_OUT_OF_RANGE; h->increment_statistics(&SSV::ha_icp_attempts); + h->active_handler_stats.icp_attempts++; res= CHECK_NEG; if (h->pushed_idx_cond->val_int()) { res= CHECK_POS; h->fast_increment_statistics(&SSV::ha_icp_match); + h->active_handler_stats.icp_match++; } return res; } diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index b8c9c87ce62da..36d7e7d315b7c 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1955,6 +1955,17 @@ static void trace_engine_stats(handler *file, Json_writer *writer) } } +static void print_r_icp_filtered(handler *file, Json_writer *writer) +{ + if (file && file->handler_stats && file->pushed_idx_cond) + { + ha_handler_stats *hs= file->handler_stats; + double r_icp_filtered = hs->icp_attempts ? + (double)(hs->icp_match) / (double)(hs->icp_attempts) : 1.0; + writer->add_member("r_icp_filtered").add_double(r_icp_filtered * 100); + } +} + void Explain_table_access::print_explain_json(Explain_query *query, Json_writer *writer, bool is_analyze) @@ -2113,6 +2124,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->add_member("r_other_time_ms").add_double(extra_time_tracker.get_time_ms()); } trace_engine_stats(handler_for_stats, writer); + print_r_icp_filtered(handler_for_stats, tracker, writer); } /* `filtered` */