mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +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:
@ -65,7 +65,7 @@ id id
|
||||
NULL 75
|
||||
explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 const PRIMARY NULL NULL NULL 1 Impossible ON condition
|
||||
1 SIMPLE t1 const PRIMARY NULL NULL NULL 0 Impossible ON condition
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where
|
||||
explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
@ -880,10 +880,10 @@ select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C;
|
||||
insert into t3 select * from t2 where a < 800;
|
||||
explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 range a,b a 5 NULL 198 Using index condition; Using where
|
||||
1 SIMPLE t2 ALL a,b NULL NULL NULL 1000 Using where
|
||||
1 SIMPLE t3 ref b b 5 test.t2.b 1
|
||||
drop table t1, t2, t3;
|
||||
create table t1 (a int);
|
||||
create table t1 (a int) engine=myisam;
|
||||
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
create table t2 (a int, b int, primary key(a));
|
||||
insert into t2 select @v:=A.a+10*B.a, @v from t1 A, t1 B;
|
||||
@ -892,14 +892,17 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
|
||||
show status like 'Last_query_cost';
|
||||
Variable_name Value
|
||||
Last_query_cost 3.508545
|
||||
Last_query_cost 0.011600
|
||||
select 'The cost of accessing t1 (dont care if it changes' '^';
|
||||
The cost of accessing t1 (dont care if it changes
|
||||
The cost of accessing t1 (dont care if it changes^
|
||||
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
|
||||
Z
|
||||
vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv
|
||||
set @@optimizer_cache_hit_ratio=0;
|
||||
select @@myisam.optimizer_disk_read_ratio;
|
||||
@@myisam.optimizer_disk_read_ratio
|
||||
0.020000
|
||||
set global myisam.optimizer_disk_read_ratio=0;
|
||||
explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
||||
@ -907,11 +910,14 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1
|
||||
show status like 'Last_query_cost';
|
||||
Variable_name Value
|
||||
Last_query_cost 48.527829
|
||||
Last_query_cost 0.046590
|
||||
select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z;
|
||||
Z
|
||||
^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error
|
||||
set @@optimizer_cache_hit_ratio=default;
|
||||
set global myisam.optimizer_disk_read_ratio=default;
|
||||
select @@myisam.optimizer_disk_read_ratio;
|
||||
@@myisam.optimizer_disk_read_ratio
|
||||
0.020000
|
||||
drop table t1, t2;
|
||||
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
|
||||
CREATE TABLE t2 (c INT PRIMARY KEY, d INT);
|
||||
@ -1278,7 +1284,7 @@ test.t2 analyze status Engine-independent statistics collected
|
||||
test.t2 analyze status OK
|
||||
explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL ix2 NULL NULL NULL 2 Using where; Using temporary; Using filesort
|
||||
1 SIMPLE t2 ref ix2 ix2 5 const 2 Using index condition; Using temporary; Using filesort
|
||||
1 SIMPLE t1 ref ix1 ix1 5 test.t2.v 1
|
||||
FLUSH STATUS;
|
||||
SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
|
||||
@ -1286,14 +1292,14 @@ pk v pk v
|
||||
SHOW STATUS LIKE 'Handler_read_%';
|
||||
Variable_name Value
|
||||
Handler_read_first 0
|
||||
Handler_read_key 0
|
||||
Handler_read_key 1
|
||||
Handler_read_last 0
|
||||
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 4
|
||||
Handler_read_rnd_next 1
|
||||
DROP TABLE t1, t2;
|
||||
End of 5.1 tests
|
||||
#
|
||||
@ -1329,9 +1335,9 @@ FROM t4 JOIN
|
||||
(t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1)
|
||||
ON t4.ref_t1=t1.c1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t4 ALL NULL NULL NULL NULL 4
|
||||
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
|
||||
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
|
||||
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
|
||||
EXPLAIN
|
||||
SELECT *
|
||||
@ -1340,9 +1346,9 @@ FROM t4 STRAIGHT_JOIN
|
||||
ON t4.ref_t1=t1.c1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
|
||||
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
|
||||
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
|
||||
drop table t1,t2,t3,t4;
|
||||
End of 5.2 tests
|
||||
#
|
||||
@ -1479,8 +1485,8 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE DU system dog_id NULL NULL NULL 1
|
||||
1 SIMPLE D system PRIMARY NULL NULL NULL 1
|
||||
1 SIMPLE DSAR system NULL NULL NULL NULL 1
|
||||
1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where
|
||||
1 SIMPLE DSA ref PRIMARY PRIMARY 8 const,test.DT.t_id,func 1 Using index
|
||||
1 SIMPLE DSA ref PRIMARY PRIMARY 4 const 3 Using where; Using index
|
||||
1 SIMPLE DT ref t_id t_id 2 test.DSA.t_id 2 Using where
|
||||
SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR
|
||||
WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND
|
||||
DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id;
|
||||
|
Reference in New Issue
Block a user