mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Added test cases for preceding test
This includes all test changes from "Changing all cost calculation to be given in milliseconds" and forwards. Some of the things that caused changes in the result files: - As part of fixing tests, I added 'echo' to some comments to be able to easier find out where things where wrong. - MATERIALIZED has now a higher cost compared to X than before. Because of this some MATERIALIZED types have changed to DEPENDEND SUBQUERY. - Some test cases that required MATERIALIZED to repeat a bug was changed by adding more rows to force MATERIALIZED to happen. - 'Filtered' in SHOW EXPLAIN has in many case changed from 100.00 to something smaller. This is because now filtered also takes into account the smallest possible ref access and filters, even if they where not used. Another reason for 'Filtered' being smaller is that we now also take into account implicit filtering done for subqueries using FIRSTMATCH. (main.subselect_no_exists_to_in) This is caluculated in best_access_path() and stored in records_out. - Table orders has changed because more accurate costs. - 'index' and 'ALL' for small tables has changed to use 'range' or 'ref' because of optimizer_scan_setup_cost. - index can be changed to 'range' as 'range' optimizer assumes we don't have to read the blocks from disk that range optimizer has already read. This can be confusing in the case where there is no obvious where clause but instead there is a hidden 'key_column > NULL' added by the optimizer. (main.subselect_no_exists_to_in) - Scan on primary clustered key does not report 'Using Index' anymore (It's a table scan, not an index scan). - For derived tables, the number of rows is now 100 instead of 2, which can be seen in EXPLAIN. - More tests have "Using index for group by" as the cost of this optimization is now more correct (lower). - A primary key could be preferred for a normal key, even if it would access more rows, as it's faster to do 1 lokoup and 3 'index_next' on a clustered primary key than one lookup trough a secondary. (main.stat_tables_innodb) Notes: - There was a 4.7% more calls to best_extension_by_limited_search() in the main.greedy_optimizer test. However examining the test results it looked that the plans where slightly better (eq_ref where more chained together) so I assume this is ok. - I have verified a few test cases where there was notable/unexpected changes in the plan and in all cases the new optimizer plans where faster. (main.greedy_optimizer and some others)
This commit is contained in:
@ -19,11 +19,11 @@ insert into t1 (a,b) select seq,seq from seq_4001_to_4100;
|
||||
insert into t1 (a,b) select seq,seq from seq_10001_to_10100;
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
|
||||
1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
|
||||
alter table t1 partition by hash(a) partitions 1;
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
|
||||
1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
|
||||
DROP TABLE t1;
|
||||
create table t1 (a DATETIME)
|
||||
partition by range (TO_DAYS(a))
|
||||
@ -958,6 +958,11 @@ CREATE TABLE t1 (
|
||||
a INT,
|
||||
b INT,
|
||||
KEY ( a, b )
|
||||
);
|
||||
CREATE TABLE t1_part (
|
||||
a INT,
|
||||
b INT,
|
||||
KEY ( a, b )
|
||||
) PARTITION BY HASH (a) PARTITIONS 1;
|
||||
CREATE TABLE t2 (
|
||||
a INT,
|
||||
@ -969,36 +974,68 @@ INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
|
||||
INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
|
||||
INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
|
||||
INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
|
||||
INSERT INTO t1 values(10,0),(10,1),(10,2),(100,0),(100,1);
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
85
|
||||
select count(*) from t1 where a=10;
|
||||
count(*)
|
||||
4
|
||||
select count(*) from t1 where a=100;
|
||||
count(*)
|
||||
2
|
||||
INSERT INTO t1_part SELECT * FROM t1;
|
||||
INSERT INTO t2 SELECT * FROM t1;
|
||||
ANALYZE TABLE t1,t2;
|
||||
ANALYZE TABLE t1_part,t2;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
test.t1_part analyze status Engine-independent statistics collected
|
||||
test.t1_part analyze status OK
|
||||
test.t2 analyze status Engine-independent statistics collected
|
||||
test.t2 analyze status Table is already up to date
|
||||
# plans should be identical
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
|
||||
EXPLAIN SELECT a, MAX(b) FROM t1_part WHERE a IN (10,100) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 5 NULL 2 Using where; Using index
|
||||
1 SIMPLE t1_part range a a 5 NULL 2 Using where; Using index for group-by
|
||||
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index
|
||||
1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
|
||||
FLUSH status;
|
||||
SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
|
||||
SELECT a, MAX(b) FROM t1_part WHERE a IN (10, 100) GROUP BY a;
|
||||
a MAX(b)
|
||||
10 10
|
||||
# Should be no more than 4 reads.
|
||||
SHOW status LIKE 'handler_read_key';
|
||||
100 1
|
||||
SHOW status LIKE 'handler_read%';
|
||||
Variable_name Value
|
||||
Handler_read_key 2
|
||||
Handler_read_first 0
|
||||
Handler_read_key 6
|
||||
Handler_read_last 1
|
||||
Handler_read_next 0
|
||||
Handler_read_prev 0
|
||||
Handler_read_retry 0
|
||||
Handler_read_rnd 0
|
||||
Handler_read_rnd_deleted 0
|
||||
Handler_read_rnd_next 0
|
||||
FLUSH status;
|
||||
SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
|
||||
a MAX(b)
|
||||
10 10
|
||||
# Should be no more than 4 reads.
|
||||
SHOW status LIKE 'handler_read_key';
|
||||
100 1
|
||||
SHOW status LIKE 'handler_read%';
|
||||
Variable_name Value
|
||||
Handler_read_key 2
|
||||
Handler_read_first 0
|
||||
Handler_read_key 6
|
||||
Handler_read_last 1
|
||||
Handler_read_next 0
|
||||
Handler_read_prev 0
|
||||
Handler_read_retry 0
|
||||
Handler_read_rnd 0
|
||||
Handler_read_rnd_deleted 0
|
||||
Handler_read_rnd_next 0
|
||||
insert into t2 select 100,seq from seq_1_to_100;
|
||||
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
|
||||
DROP TABLE t1,t1_part,t2;
|
||||
#
|
||||
# MDEV-18501 Partition pruning doesn't work for historical queries
|
||||
#
|
||||
@ -1026,7 +1063,7 @@ d
|
||||
select * from t1 partition (p1);
|
||||
d
|
||||
2000-01-01 00:00:01.000000
|
||||
DROP TABLE t1, t2;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column
|
||||
#
|
||||
|
Reference in New Issue
Block a user