Skip to content

Commit c9787e5

Browse files
author
Olav Sandstaa
committed
WL#7339 Use improved records per key estimate interface in optimizer
This worklog implements the needed changes in the optimizer and server to start using the new "records per key" interface that was implmeneted in WL#7338. This interface allows storage engines to provide "records per key" values using float values instead of integer values. Using this new interface instead of using the currently used rec_per_key values gives more correct record estimates for ref access against an indexed column.
1 parent 7024d97 commit c9787e5

File tree

71 files changed

+734
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+734
-533
lines changed

mysql-test/include/explain_non_select.inc

+12
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
188188
INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
189189
INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
190190
INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
191+
# Need to run ANALYZE to get correct index statistics
192+
--disable_query_log
193+
--disable_result_log
194+
ANALYZE TABLE t1, t2, t3;
195+
--enable_result_log
196+
--enable_query_log
191197
--let $query = DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
192198
--let $select = SELECT * FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
193199
--source include/explain_utils.inc
@@ -591,6 +597,12 @@ CREATE TABLE t2(f3 INT, f4 INT);
591597
CREATE INDEX IDX ON t2(f3);
592598
INSERT INTO t1 VALUES(1,0),(2,0);
593599
INSERT INTO t2 VALUES(1,1),(2,2);
600+
# Need to run ANALYZE to get correct index statistics
601+
-- disable_query_log
602+
-- disable_result_log
603+
ANALYZE TABLE t1,t2;
604+
-- enable_result_log
605+
-- enable_query_log
594606
--let $query = UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
595607
--let $select = SELECT (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
596608
--source include/explain_utils.inc

mysql-test/include/subquery_sj.inc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4173,7 +4173,8 @@ INSERT INTO t1 VALUES
41734173
(15,2,'a','x'),
41744174
(16,1,'d','d'),
41754175
(17,8,'y','y'),
4176-
(18,6,'t','u');
4176+
(18,6,'t','u'),
4177+
(19,6,'t','u');
41774178

41784179
CREATE TABLE t2 (
41794180
pk int NOT NULL,

mysql-test/include/subquery_sj_innodb.inc

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ SET GLOBAL innodb_stats_persistent=0;
99
-- enable_query_log
1010

1111
create table t0 (a int);
12-
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
12+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),
13+
(10),(12),(14),(16),(18);
1314

1415
# First test simple cases: I20 order, no join buffering.
1516

@@ -26,11 +27,21 @@ create table t2 (
2627
) engine=innodb;
2728
insert into t2 select a, a/2 from t0;
2829

30+
# Run analyze to ensure more correct index statistics
31+
-- disable_query_log
32+
-- disable_result_log
33+
ANALYZE TABLE t1,t2;
34+
-- enable_result_log
35+
-- enable_query_log
36+
2937
select * from t1;
3038
select * from t2;
3139
explain select * from t2 where b in (select a from t1);
3240
select * from t2 where b in (select a from t1);
3341

42+
truncate table t0;
43+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
44+
3445
# Try an InnoDB table with very long rowid
3546
create table t3 (
3647
a int,

mysql-test/r/explain_for_connection_rqg_json.result

+32-63
Large diffs are not rendered by default.

mysql-test/r/explain_for_connection_rqg_trad.result

+2-9
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,13 @@ SYNC_POINT:before_reset_query_plan
103103
Diff: EXPLAIN NORMAL vs OTHER
104104
@@ -3,3 +3,3 @@
105105
1 PRIMARY <derived2> NULL ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop)
106-
-1 PRIMARY table3 NULL eq_ref PRIMARY,col_int_key PRIMARY 4 table2.pk 1 5.00 Using where
106+
-1 PRIMARY table3 NULL eq_ref PRIMARY,col_int_key PRIMARY 4 table2.pk 1 12.50 Using where
107107
+1 PRIMARY table3 NULL eq_ref PRIMARY,col_int_key PRIMARY 4 table2.pk 1 100.00 Using where
108108
3 DEPENDENT SUBQUERY subquery2_t1 NULL ALL NULL NULL NULL NULL 20 100.00 NULL
109109
QUERY: SELECT (SELECT MAX( DISTINCT sq1_alias1.col_int_key ) AS sq1_field1 FROM ( cc AS sq1_alias1 , bb AS sq1_alias2 ) WHERE sq1_alias2.pk <> alias1.pk AND sq1_alias2.pk <= alias1.col_int_key ) AS field1 , COUNT( alias1.col_varchar_key ) AS field2 FROM ( bb AS alias1 LEFT OUTER JOIN ( ( cc AS alias2 INNER JOIN cc AS alias3 ON (alias3.col_int_key = alias2.col_int_key ) ) ) ON (alias3.col_varchar_nokey = alias2.col_varchar_key ) ) WHERE ( EXISTS ( (SELECT sq2_alias1.col_varchar_nokey AS sq2_field1 FROM c AS sq2_alias1 WHERE ( sq2_alias1.col_varchar_nokey , sq2_alias1.col_varchar_nokey ) IN (SELECT c_sq1_alias1.col_varchar_key AS c_sq1_field1 , MAX( c_sq1_alias1.col_varchar_nokey ) AS c_sq1_field2 FROM cc AS c_sq1_alias1 ) GROUP BY sq2_field1 ) ) ) OR ( alias1.col_int_key > 51 AND alias1.col_int_key < ( 51 + 209 ) OR alias1.col_int_key > 51 AND alias1.col_int_key < ( 51 + 159 ) ) OR (SELECT SQL_SMALL_RESULT MIN( sq3_alias1.pk ) AS sq3_field1 FROM ( c AS sq3_alias1 RIGHT OUTER JOIN c AS sq3_alias2 ON (sq3_alias2.col_int_key = sq3_alias1.pk ) ) ) IS NOT NULL GROUP BY field1 HAVING field2 <> 5 ORDER BY alias1.col_time_key ASC , field2 , CONCAT( alias2.col_varchar_key, alias3.col_varchar_key )
110110
STATUS: EQUAL
111111
QUERY: SELECT (SELECT 5 FROM dummy ) AS field1 FROM ( b AS table1 INNER JOIN ( ( ( SELECT subquery2_t1.* FROM ( cc AS subquery2_t1 INNER JOIN cc AS subquery2_t2 ON (subquery2_t2.col_varchar_key = subquery2_t1.col_varchar_key ) ) ) AS table2 LEFT JOIN cc AS table3 ON (table3.col_int_key = table2.pk ) ) ) ON (table3.col_varchar_key = table2.col_varchar_key ) ) WHERE ( EXISTS ( (SELECT subquery3_t2.col_varchar_nokey AS subquery3_field1 FROM ( d AS subquery3_t1 INNER JOIN bb AS subquery3_t2 ON (subquery3_t2.col_int_key = subquery3_t1.pk ) ) ) ) ) OR ( table1.col_varchar_key = 'w' AND table1.col_varchar_key = table3.col_varchar_key ) ORDER BY table1.col_varchar_key DESC /*+JavaDB:Postgres: NULLS LAST */ , field1 /*+JavaDB:Postgres: NULLS FIRST */ LIMIT 10 OFFSET 6
112-
STATUS:NOT_EQUAL
113-
SYNC_POINT:before_reset_query_plan
114-
Diff: EXPLAIN NORMAL vs OTHER
115-
@@ -3,3 +3,3 @@
116-
1 PRIMARY <derived3> NULL ALL NULL NULL NULL NULL 20 100.00 Using join buffer (Block Nested Loop)
117-
-1 PRIMARY table3 NULL ref col_int_key,col_varchar_key col_int_key 5 table2.pk 1 5.00 Using where
118-
+1 PRIMARY table3 NULL ref col_int_key,col_varchar_key col_int_key 5 table2.pk 1 100.00 Using where
119-
4 SUBQUERY subquery3_t2 NULL ALL col_int_key NULL NULL NULL 1 100.00 Using where
112+
STATUS: EQUAL
120113
QUERY: SELECT alias1.col_time_key AS field1 , alias2.col_varchar_key AS field2 FROM ( b AS alias1 , ( SELECT sq1_alias1.* FROM cc AS sq1_alias1 ) AS alias2 , c AS alias3 ) WHERE ( EXISTS ( (SELECT 5 FROM DUAL ) ) ) OR ( alias1.col_varchar_key IN ('e' , 'USA') OR alias1.col_varchar_key IN ('USA') ) GROUP BY field1, field2 HAVING field2 > 'e'
121114
STATUS: EQUAL
122115
QUERY: SELECT (SELECT 'z' FROM dummy ) AS field1 , table1.pk AS field2 , table1.col_time_key AS field3 , table2.col_datetime_key AS field4 , table1.col_datetime_key AS field5 , table2.pk AS field6 FROM ( ( SELECT subquery2_t1.* FROM ( c AS subquery2_t1 INNER JOIN cc AS subquery2_t2 ON (subquery2_t2.pk = subquery2_t1.pk ) ) ) AS table1 INNER JOIN ( SELECT subquery3_t1.* FROM ( b AS subquery3_t1 LEFT JOIN c AS subquery3_t2 ON (subquery3_t2.pk = subquery3_t1.pk ) ) ) AS table2 ON (table2.pk = table1.col_int_key ) ) WHERE ( EXISTS ( (SELECT subquery4_t1.col_varchar_key AS subquery4_field1 FROM ( cc AS subquery4_t1 LEFT OUTER JOIN c AS subquery4_t2 ON (subquery4_t2.pk = subquery4_t1.col_int_key ) ) ) ) ) OR ( table1.pk = 141 AND table1.pk = 79 ) ORDER BY table1.col_datetime_key DESC /*+JavaDB:Postgres: NULLS LAST */

mysql-test/r/func_group_innodb_16k.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MIN(c)
1111
0
1212
EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
1313
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
14-
1 SIMPLE t1 NULL range b b 263 NULL 3 100.00 Using index for group-by
14+
1 SIMPLE t1 NULL range b b 263 NULL 2 100.00 Using index for group-by
1515
Warnings:
1616
Note 1003 /* select#1 */ select min(`test`.`t1`.`c`) AS `MIN(c)` from `test`.`t1` group by `test`.`t1`.`b`
1717
DROP TABLE t1;

0 commit comments

Comments
 (0)