Skip to content

Commit fdec885

Browse files
committed
MDEV-25830 optimizer_use_condition_selectivity=4 sometimes produces worse plan than optimizer_use_condition_selectivity=1
The issue was that calc_cond_selectivity_for_table prefered ranges with many parts and when deciding on which selectivity to use. Fixed by going through ranges according to the number of rows in the range. This ensures that selectivity from ranges with few rows will be prefered over ranges with many rows for indexes that uses the same columns.
1 parent c75bee9 commit fdec885

File tree

5 files changed

+207
-24
lines changed

5 files changed

+207
-24
lines changed

mysql-test/main/group_min_max.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,27 +2078,27 @@ id select_type table type possible_keys key key_len ref rows Extra
20782078
explain extended select a1,a2,min(b),max(b) from t1
20792079
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2;
20802080
id select_type table type possible_keys key key_len ref rows filtered Extra
2081-
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 99.22 Using where; Using index
2081+
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 85.04 Using where; Using index
20822082
Warnings:
20832083
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`
20842084
explain extended select a1,a2,b,min(c),max(c) from t1
20852085
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b;
20862086
id select_type table type possible_keys key key_len ref rows filtered Extra
2087-
1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 45.12 Using where; Using temporary; Using filesort
2087+
1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 38.67 Using where; Using temporary; Using filesort
20882088
Warnings:
20892089
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,min(`test`.`t1`.`c`) AS `min(c)`,max(`test`.`t1`.`c`) AS `max(c)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
20902090
explain extended select a1,a2,b,c from t1
20912091
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c;
20922092
id select_type table type possible_keys key key_len ref rows filtered Extra
2093-
1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 45.12 Using where; Using temporary; Using filesort
2093+
1 SIMPLE t1 ALL idx_t1_0,idx_t1_1,idx_t1_2 NULL NULL NULL 128 38.67 Using where; Using temporary; Using filesort
20942094
Warnings:
20952095
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`d` > 'xy2' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`,`test`.`t1`.`c`
20962096
explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1;
20972097
id select_type table type possible_keys key key_len ref rows Extra
20982098
1 SIMPLE t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index
20992099
explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b;
21002100
id select_type table type possible_keys key key_len ref rows filtered Extra
2101-
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 99.22 Using where; Using index
2101+
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 77 85.04 Using where; Using index
21022102
Warnings:
21032103
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
21042104
explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;

mysql-test/main/mdev-25830.result

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB';
2+
set @innodb_stats_persistent_save= @@innodb_stats_persistent;
3+
set @innodb_stats_persistent_sample_pages_save=
4+
@@innodb_stats_persistent_sample_pages;
5+
set global innodb_stats_persistent= 1;
6+
set global innodb_stats_persistent_sample_pages=100;
7+
set optimizer_use_condition_selectivity=1;
8+
analyze SELECT sysapproval_approver0.`sys_id`
9+
FROM ((sysapproval_approver sysapproval_approver0
10+
INNER JOIN task task1
11+
ON sysapproval_approver0.`sysapproval` = task1.`sys_id`
12+
AND (( task1.`sys_domain_path` = '/'
13+
OR task1.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
14+
OR task1.`sys_domain_path` LIKE '!!!/!!!/%' )))
15+
INNER JOIN task task2
16+
ON task1.`parent` = task2.`sys_id`
17+
AND (( task2.`sys_domain_path` = '/'
18+
OR task2.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
19+
OR task2.`sys_domain_path` LIKE '!!!/!!!/%' )))
20+
WHERE task2.`sys_id` LIKE '8e7792a7dbfffb00fff8a345ca961934%'
21+
AND ( sysapproval_approver0.`sys_domain_path` = '/'
22+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
23+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!!/%' )
24+
ORDER BY sysapproval_approver0.`order`
25+
LIMIT 0, 50 ;
26+
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
27+
1 SIMPLE task2 range PRIMARY,sys_class_name_2,sys_domain_path PRIMARY 96 NULL 1 0.00 100.00 100.00 Using where; Using temporary; Using filesort
28+
1 SIMPLE task1 ref PRIMARY,task_parent,sys_class_name_2,sys_domain_path task_parent 99 mdev25830.task2.sys_id 1 NULL 100.00 NULL Using index condition; Using where
29+
1 SIMPLE sysapproval_approver0 ref sysapproval_approver_ref5,sys_domain_path,sysapproval_approver_CHG1975376 sysapproval_approver_ref5 99 mdev25830.task1.sys_id 1 NULL 100.00 NULL Using index condition; Using where
30+
set optimizer_use_condition_selectivity=4;
31+
analyze SELECT sysapproval_approver0.`sys_id`
32+
FROM ((sysapproval_approver sysapproval_approver0
33+
INNER JOIN task task1
34+
ON sysapproval_approver0.`sysapproval` = task1.`sys_id`
35+
AND (( task1.`sys_domain_path` = '/'
36+
OR task1.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
37+
OR task1.`sys_domain_path` LIKE '!!!/!!!/%' )))
38+
INNER JOIN task task2
39+
ON task1.`parent` = task2.`sys_id`
40+
AND (( task2.`sys_domain_path` = '/'
41+
OR task2.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
42+
OR task2.`sys_domain_path` LIKE '!!!/!!!/%' )))
43+
WHERE task2.`sys_id` LIKE '8e7792a7dbfffb00fff8a345ca961934%'
44+
AND ( sysapproval_approver0.`sys_domain_path` = '/'
45+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
46+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!!/%' )
47+
ORDER BY sysapproval_approver0.`order`
48+
LIMIT 0, 50 ;
49+
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
50+
1 SIMPLE task2 range PRIMARY,sys_class_name_2,sys_domain_path PRIMARY 96 NULL 1 0.00 98.00 100.00 Using where; Using temporary; Using filesort
51+
1 SIMPLE task1 ref PRIMARY,task_parent,sys_class_name_2,sys_domain_path task_parent 99 mdev25830.task2.sys_id 1 NULL 100.00 NULL Using index condition; Using where
52+
1 SIMPLE sysapproval_approver0 ref sysapproval_approver_ref5,sys_domain_path,sysapproval_approver_CHG1975376 sysapproval_approver_ref5 99 mdev25830.task1.sys_id 1 NULL 100.00 NULL Using index condition; Using where
53+
set global innodb_stats_persistent= @innodb_stats_persistent_save;
54+
set global innodb_stats_persistent_sample_pages=
55+
@innodb_stats_persistent_sample_pages_save;

mysql-test/main/mdev-25830.test

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# MDEV-25830: optimizer_use_condition_selectivity=4 sometimes produces worse plan than optimizer_use_condition_selectivity=1
3+
# https://jira.mariadb.org/browse/MDEV-25830
4+
#
5+
--source include/innodb_prefix_index_cluster_optimization.inc
6+
7+
SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB';
8+
9+
set @innodb_stats_persistent_save= @@innodb_stats_persistent;
10+
set @innodb_stats_persistent_sample_pages_save=
11+
@@innodb_stats_persistent_sample_pages;
12+
13+
set global innodb_stats_persistent= 1;
14+
set global innodb_stats_persistent_sample_pages=100;
15+
16+
--disable_query_log
17+
--disable_result_log
18+
--disable_warnings
19+
20+
create database if not exists mdev25830;
21+
use mdev25830;
22+
DROP TABLE IF EXISTS `sysapproval_approver`;
23+
CREATE TABLE `sysapproval_approver` (
24+
`order` int(11) DEFAULT NULL,
25+
`sysapproval` varchar(32) DEFAULT NULL,
26+
`sys_id` char(32) NOT NULL DEFAULT '',
27+
`sys_domain_path` varchar(255) DEFAULT NULL,
28+
PRIMARY KEY (`sys_id`),
29+
KEY `sysapproval_approver_ref5` (`sysapproval`),
30+
KEY `sys_domain_path` (`sys_domain_path`),
31+
KEY `sysapproval_approver_CHG1975376` (`sys_domain_path`,`sysapproval`)
32+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33+
34+
INSERT INTO `sysapproval_approver` VALUES (NULL,'c00004d787a8a5003fff83bdff434dea','000004d787a8a5003fff83bdff434dee','!!!/!!#/!!$/'),(NULL,NULL,'00000741db8bfb480be6a345ca96198e','!!!/!!#/!!$/'),(NULL,NULL,'00001605dbce48d0f7fca851ca961967','!!!/!!#/!!$/'),(NULL,'23b53105db2f324c5a4af85e0f96194e','000016c1db6ffa445d2f7aa31f9619a0','!!!/!!#/!!$/'),(NULL,NULL,'00001730dbe24890f7fca851ca9619aa','!!!/!!#/!!$/'),(NULL,NULL,'000017a01b127b00ada243f6fe4bcb8c','!!!/!!#/!!$/'),(NULL,'7f660139db6088185ed4a851ca961986','00001ab1dbecc8185ed4a851ca961970','!!!/!!#/!!$/'),(NULL,'6226cd801b19dc10a59033f2cd4bcb22','00001d84db9918505ed4a851ca96193f','!!!/!!!/(8]/'),(NULL,NULL,'00002246db83874002f17c541f961999','!!!/!!#/!!$/'),(NULL,NULL,'000026e01b9eb700ada243f6fe4bcbc5','!!!/!!#/!!$/'),(NULL,NULL,'000028e16f064e807b658e4c2c3ee4ae','!!!/!!#/!!$/'),(NULL,NULL,'00002914dba8670c54250b55ca961928','!!!/!!#/!!$/'),(NULL,NULL,'00002914dba8670c54250b55ca961931','!!!/!!#/!!$/'),(NULL,NULL,'00002914dba8670c54250b55ca96193a','!!!/!!#/!!$/'),(NULL,NULL,'00002914dba8670c54250b55ca961943','!!!/!!#/!!$/'),(NULL,NULL,'000030a4dbb90b40002af47e0f9619b1','!!!/!!#/!!$/'),(NULL,NULL,'000033fedb41fb041cd8a345ca9619fa','!!!/!!#/!!$/'),(NULL,NULL,'0000341ddb4ce3804ac3a851ca961916','!!!/!!#/!!$/'),(NULL,NULL,'0000393ddb709b002b6dfb651f961908','!!!/!!#/!!$/'),(NULL,'a81ca740db5cdc9416d2a345ca9619b3','00003b00dbdcdc9416d2a345ca961907','!!!/!!#/!!$/'),(NULL,'04003c88db5e3304d6a102d5ca961913','00003c88db5e3304d6a102d5ca96192a','!!!/!!#/!!$/'),(NULL,'4affb00cdbbf0f800e3dfb651f9619a0','0000450cdbbf0f800e3dfb651f961973','!!!/!!#/!!$/'),(NULL,NULL,'00005634dbd11fc4e9737a9e0f961988','!!!/!!#/!!$/'),(NULL,NULL,'00005634dbd11fc4e9737a9e0f9619ce','!!!/!!#/!!$/'),(NULL,NULL,'00005634dbd11fc4e9737a9e0f9619d7','!!!/!!#/!!$/'),(NULL,NULL,'00005784dbc49b00852c7a9e0f96198a','!!!/!!#/!!$/'),(NULL,NULL,'00005bc1dbcdd7042d1efb651f961978','!!!/!!#/!!$/'),(NULL,NULL,'0000637b6f37c24013568e4c2c3ee4d6','!!!/!!#/!!$/'),(NULL,'080069db0f858240a2c9982be1050eae','000069db0f858240a2c9982be1050eb2','!!!/!!#/!!$/'),(NULL,'f98e3bb21b155c10a59033f2cd4bcbef','00006c47db5d9010d82ffb24399619d8','!!!/!!!/#YZ/'),(NULL,NULL,'00006c50db6a0450d58ea345ca961972','!!!/!!#/!!$/'),(NULL,NULL,'00006e38dbc19304032a7a9e0f9619e4','!!!/!!#/!!$/'),(NULL,NULL,'00006edddbec8c5813b5fb24399619b9','!!!/!!#/!!$/'),(NULL,NULL,'000073fedb41fb041cd8a345ca961934','!!!/!!#/!!$/'),(NULL,NULL,'000073fedb41fb041cd8a345ca96195c','!!!/!!#/!!$/'),(NULL,'d03c6ee61b774410a59033f2cd4bcbf5','000076bfdbb74c981cd8a345ca9619ee','!!!/!!!/!;B/'),(NULL,NULL,'000076ecdbde48502be0a851ca9619dd','!!!/!!#/!!$/'),(NULL,NULL,'000076ecdbde48502be0a851ca9619fe','!!!/!!#/!!$/'),(NULL,NULL,'0000778d6fd01a4000270bae9f3ee4ff','!!!/!!#/!!$/'),(NULL,NULL,'000077c21b3fbb0cada243f6fe4bcba7','!!!/!!#/!!$/'),(NULL,NULL,'000077c21b3fbb0cada243f6fe4bcbcb','!!!/!!#/!!$/'),(NULL,'f6c5f2110f75de401c7e938172050e1b','000077e10f7d5e00e59b982be1050e62','!!!/!!#/!!$/'),(NULL,NULL,'00007fa76ff70a0000270bae9f3ee4b1','!!!/!!#/!!$/'),(NULL,'73ff6fe76f4761007ceff7307f3ee478','00007fe76f4761007ceff7307f3ee47c','!!!/!!#/!!$/'),(NULL,'a4d63f4bdb8fbf00414ed0c5ca96191d','0000881b1b8f7f00fff162c4bd4bcbe7','!!!/!!!/$)(/'),(NULL,'a4d63f4bdb8fbf00414ed0c5ca96191d','0000881b1b8f7f00fff162c4bd4bcbec','!!!/!!!/$)(/'),(NULL,NULL,'000094eb6f781a0099c5409e9f3ee48e','!!!/!!#/!!$/'),(NULL,NULL,'000094eb6f781a0099c5409e9f3ee493','!!!/!!#/!!$/'),(NULL,'401fb78cdb18d8dc1cd8a345ca9619c8','00009c10dbdc98dcfeb1a851ca96192f','!!!/!!!/$$8/'),(NULL,'9dd30a24db5c1cdc23f4a345ca96192b','00009e2cdb1c589c4819fb243996195c','!!!/!!#/!!$/');
35+
36+
DROP TABLE IF EXISTS `task`;
37+
CREATE TABLE `task` (
38+
`parent` varchar(32) DEFAULT NULL,
39+
`sys_id` char(32) NOT NULL DEFAULT '',
40+
`sys_domain_path` varchar(255) DEFAULT NULL,
41+
PRIMARY KEY (`sys_id`),
42+
KEY `task_parent` (`parent`),
43+
KEY `sys_class_name_2` (`sys_domain_path`),
44+
KEY `sys_domain_path` (`sys_domain_path`)
45+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46+
47+
INSERT INTO `task` VALUES (NULL,'-1','!!!/!!#/!!$/'),(NULL,'00000195dbe7f30413b5fb2439961936','!!!/!!#/!!$/'),(NULL,'0000032edb160f04d7e37aa31f961964','!!!/!!#/!!$/'),('a6fe0637dbddfb8c1cd8a345ca96196f','000003dcdb31f3c0a39a0b55ca961916','!!!/!!#/!!$/'),('2f1df65d6fca3100e7f68e4c2c3ee4e6','000004466f127d40e7f68e4c2c3ee4ce','!!!/!!#/!!$/'),('50dfb42edbbdd3403eb27a9e0f96199e','0000056edbbdd3403eb27a9e0f961995','!!!/!!!/+0{/'),('5f5af922dbb804d03bf6a851ca961999','000006eedb7c04d03bf6a851ca96190c','!!!/!!!/$9;/'),(NULL,'00000904db1dd45014d6fb24399619b7','!!!/!!#/!!$/'),('33c6e522db2c10104ac3a851ca9619f3','00000a06dbf0181416d2a345ca96197b','!!!/!!#/!!$/'),(NULL,'00000ccd6f9196041501f7307f3ee406','!!!/!!#/!!$/'),(NULL,'00000ee2dbb9bf4014d6fb24399619a7','!!!/!!#/!!$/'),(NULL,'00000f065bba40000a4de1945e425441','!!!/!!#/!!$/'),(NULL,'000013dedbc0bf00bbc40b55ca961959','!!!/!!!/,*7/'),(NULL,'000016bcdb29009cf7fca851ca961927','!!!/!!#/!!$/'),(NULL,'0000171bdbdb770066e0a345ca96195a','!!!/!!!/+N?/'),('8eb9317f1b895450d01143f6fe4bcb26','00001c80db5d509022e0fb24399619ed','!!!/!!!/0RG/'),(NULL,'00001d84dbf6f2405a4af85e0f9619f9','!!!/!!#/!!$/'),(NULL,'00001e31db25d4105ed4a851ca96195c','!!!/!!#/!!$/'),(NULL,'00001ea3db73c89823f4a345ca9619b5','!!!/!!#/!!$/'),('c3baf3fadb234c54d82ffb24399619e0','00001f4fdbab4c542be0a851ca96190c','!!!/!!#/!!$/'),(NULL,'0000221bdbb4b3c466e0a345ca9619f0','!!!/!!!/$^{/'),(NULL,'000022bcdb9c04d022e0fb24399619e1','!!!/!!#/!!$/'),('9b7152434f995a80f347524e0210c7e0','0000234b6f59de00fbd4409e9f3ee446','/'),('c64ed870145461009a1c80cd6740d192','00002434145461009a1c80cd6740d1e5','!!!/!!#/!!$/'),(NULL,'0000247edb84d7040e3dfb651f9619b2','!!!/!!#/!!$/'),(NULL,'000025f8dbb6ba007fc27c541f96195b','!!!/!!#/!!$/'),('9b691033485d95c0c5abf6bd15eef576','0000287348dd95c0c5abf6bd15eef572','!!!/!!#/!!$/'),('3c4f591edb7ce2406015f47e0f96191b','00002952dbbce2406015f47e0f961999','!!!/!!!/#MU/'),(NULL,'000029b0db6d5c104819fb24399619a8','!!!/!!#/!!$/'),(NULL,'00002a3d1b5f0010a59033f2cd4bcb90','!!!/!!!/&<#/'),(NULL,'00002a9fdb5787840e3dfb651f9619a6','!!!/!!#/!!$/'),(NULL,'00002c5adb5a0fc0d7e37aa31f9619ba','!!!/!!#/!!$/'),('fa753886dbd8181014d6fb2439961989','00002d5edbdc949466e0a345ca9619e4','!!!/!!!/$44/'),('56ff56bfdb469c503fa35583ca961987','00002e73db0a9c50364a5583ca961922','!!!/!!#/!!$/'),(NULL,'000031f6dba76b40c9c302d5ca9619c4','!!!/!!#/!!$/'),(NULL,'000036fadb1a0344d7e37aa31f96196d','!!!/!!#/!!$/'),(NULL,'000036ffdb046744d58ea345ca961937','!!!/!!#/!!$/'),(NULL,'000037c2dbaae700fb115583ca961926','!!!/!!#/!!$/'),(NULL,'000038eedbe32380b1b102d5ca9619c9','!!!/!!!/#2J/'),(NULL,'00003925dbb1c300225d7aa31f961993','!!!/!!#/!!$/'),('58c865acdb2944184ac3a851ca961901','0000392cdbe944184ac3a851ca9619ea','!!!/!!!/(*S/'),(NULL,'00003966db307a800e58fb651f9619a7','!!!/!!!/&C[/'),('bdeae17bdbfed3045ed4a851ca961933','0000397bdbb217045ed4a851ca96192e','!!!/!!#/!!$/'),('1b951202dbbe7b8014d6fb2439961926','00003a02db767f80fec4fb243996198f','!!!/!!!/#*L/'),(NULL,'00003e5bdbe33b8416d2a345ca961919','!!!/!!#/!!$/'),(NULL,'00003eef1b0a4410fff162c4bd4bcb0e','!!!/!!#/!!$/'),(NULL,'000040b6dbcfcb000e58fb651f9619d2','!!!/!!#/!!$/'),(NULL,'000040e5db0a185011762183ca9619c5','!!!/!!#/!!$/'),('101abff70ff99200a2c9982be1050ee7','000044c86f4a120000270bae9f3ee475','/'),('15d6f3c8dbb3ab0023f4a345ca9619ee','000045f2db5f2700f2eb02d5ca9619c6','!!!/!!!/#*./');
48+
49+
ANALYZE TABLE sysapproval_approver PERSISTENT FOR COLUMNS() INDEXES();
50+
ANALYZE TABLE task PERSISTENT FOR COLUMNS() INDEXES();
51+
52+
--enable_warnings
53+
--enable_result_log
54+
--enable_query_log
55+
56+
#explain format= json SELECT sysapproval_approver0.`sys_id` FROM ((sysapproval_approver sysapproval_approver0 INNER JOIN task task1 ON sysapproval_approver0.`sysapproval` = task1.`sys_id` AND ((task1.`sys_domain_path` = '/' OR task1.`sys_domain_path` LIKE '!!!/!!#/!!$/%' OR task1.`sys_domain_path` LIKE '!!!/!!!/%'))) INNER JOIN task task2 ON task1.`parent` = task2.`sys_id` AND ((task2.`sys_domain_path` = '/' OR task2.`sys_domain_path` LIKE '!!!/!!#/!!$/%' OR task2.`sys_domain_path` LIKE '!!!/!!!/%'))) WHERE task2.`sys_id` LIKE '8e7792a7dbfffb00fff8a345ca961934%' AND (sysapproval_approver0.`sys_domain_path` = '/' OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!#/!!$/%' OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!!/%') ORDER BY sysapproval_approver0.`order` LIMIT 0, 50;
57+
58+
59+
set optimizer_use_condition_selectivity=1;
60+
analyze SELECT sysapproval_approver0.`sys_id`
61+
FROM ((sysapproval_approver sysapproval_approver0
62+
INNER JOIN task task1
63+
ON sysapproval_approver0.`sysapproval` = task1.`sys_id`
64+
AND (( task1.`sys_domain_path` = '/'
65+
OR task1.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
66+
OR task1.`sys_domain_path` LIKE '!!!/!!!/%' )))
67+
INNER JOIN task task2
68+
ON task1.`parent` = task2.`sys_id`
69+
AND (( task2.`sys_domain_path` = '/'
70+
OR task2.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
71+
OR task2.`sys_domain_path` LIKE '!!!/!!!/%' )))
72+
WHERE task2.`sys_id` LIKE '8e7792a7dbfffb00fff8a345ca961934%'
73+
AND ( sysapproval_approver0.`sys_domain_path` = '/'
74+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
75+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!!/%' )
76+
ORDER BY sysapproval_approver0.`order`
77+
LIMIT 0, 50 ;
78+
79+
set optimizer_use_condition_selectivity=4;
80+
analyze SELECT sysapproval_approver0.`sys_id`
81+
FROM ((sysapproval_approver sysapproval_approver0
82+
INNER JOIN task task1
83+
ON sysapproval_approver0.`sysapproval` = task1.`sys_id`
84+
AND (( task1.`sys_domain_path` = '/'
85+
OR task1.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
86+
OR task1.`sys_domain_path` LIKE '!!!/!!!/%' )))
87+
INNER JOIN task task2
88+
ON task1.`parent` = task2.`sys_id`
89+
AND (( task2.`sys_domain_path` = '/'
90+
OR task2.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
91+
OR task2.`sys_domain_path` LIKE '!!!/!!!/%' )))
92+
WHERE task2.`sys_id` LIKE '8e7792a7dbfffb00fff8a345ca961934%'
93+
AND ( sysapproval_approver0.`sys_domain_path` = '/'
94+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!#/!!$/%'
95+
OR sysapproval_approver0.`sys_domain_path` LIKE '!!!/!!!/%' )
96+
ORDER BY sysapproval_approver0.`order`
97+
LIMIT 0, 50 ;
98+
99+
--disable_query_log
100+
--disable_result_log
101+
--disable_warnings
102+
103+
drop database mdev25830;
104+
105+
--enable_warnings
106+
--enable_result_log
107+
--enable_query_log
108+
109+
set global innodb_stats_persistent= @innodb_stats_persistent_save;
110+
set global innodb_stats_persistent_sample_pages=
111+
@innodb_stats_persistent_sample_pages_save;

mysql-test/main/opt_trace_index_merge_innodb.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
183183
},
184184
{
185185
"selectivity_for_indexes": [
186-
{
187-
"index_name": "PRIMARY",
188-
"selectivity_from_index": 1
189-
},
190186
{
191187
"index_name": "key1",
192188
"selectivity_from_index": 0.001
189+
},
190+
{
191+
"index_name": "PRIMARY",
192+
"selectivity_from_index": 1
193193
}
194194
],
195195
"selectivity_for_columns": [],

0 commit comments

Comments
 (0)