mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-18478 ANALYZE for statement should show selectivity of ICP, part#1
(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.
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user