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:
@ -346,10 +346,10 @@ insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
|
||||
alter table t1 drop primary key, add primary key (f2, f1);
|
||||
explain select distinct f1 a, f1 b from t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary
|
||||
explain select distinct f1, f2 from t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20),
|
||||
INDEX (name));
|
||||
@ -396,7 +396,7 @@ test.t1 analyze status OK
|
||||
flush tables;
|
||||
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref name name 22 const 2 Using where; Using index
|
||||
1 SIMPLE t1 range name name 44 NULL 2 Using where; Using index for group-by
|
||||
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
|
||||
name dept
|
||||
rs5 cs10
|
||||
@ -405,7 +405,7 @@ DELETE FROM t1;
|
||||
# Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
|
||||
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref name name 22 const # Using where; Using index
|
||||
1 SIMPLE t1 range name name 44 NULL # Using where; Using index for group-by
|
||||
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
|
||||
name dept
|
||||
DROP TABLE t1;
|
||||
@ -1629,7 +1629,7 @@ c b d
|
||||
3 2 40
|
||||
EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL c 8 NULL 3 Using index
|
||||
1 SIMPLE t1 index NULL c 8 NULL 3
|
||||
SELECT c,b FROM t1 GROUP BY c,b;
|
||||
c b
|
||||
1 1
|
||||
@ -1787,7 +1787,7 @@ INSERT INTO t1 VALUES
|
||||
(191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
|
||||
EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where; Using filesort
|
||||
1 SIMPLE t1 ref_or_null idx idx 5 const 3 Using index condition; Using filesort
|
||||
SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
|
||||
id type d
|
||||
191 member 1
|
||||
@ -1797,13 +1797,16 @@ DROP TABLE t1;
|
||||
set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
|
||||
set global innodb_autoextend_increment=8;
|
||||
set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
|
||||
#
|
||||
# Bug #37830: ORDER BY ASC/DESC - no difference
|
||||
#
|
||||
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
|
||||
ENGINE=InnoDB;
|
||||
INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
|
||||
INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1), (100,2,2);
|
||||
INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
|
||||
EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range t1_b t1_b 5 NULL 8 Using where
|
||||
1 SIMPLE t1 ref t1_b t1_b 5 const 8 Using where
|
||||
SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
|
||||
a b c
|
||||
8 1 1
|
||||
@ -2190,7 +2193,7 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
|
||||
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
|
||||
2 DERIVED t1 ref c3,c2 c3 5 const 2 Using where
|
||||
2 DERIVED t1 ref c3,c2 c2 10 const,const 1
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
|
||||
ENGINE=InnoDB;
|
||||
@ -2204,7 +2207,7 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
|
||||
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
|
||||
2 DERIVED t1 ref c3,c2 c3 9 const 2 Using where
|
||||
2 DERIVED t1 ref c3,c2 c2 18 const,const 1
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2),
|
||||
KEY (c3), KEY (c2, c3))
|
||||
@ -2219,7 +2222,7 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
|
||||
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
|
||||
2 DERIVED t1 ref c3,c2 c3 7 const 2 Using where
|
||||
2 DERIVED t1 ref c3,c2 c2 14 const,const 1
|
||||
DROP TABLE t1;
|
||||
End of 5.1 tests
|
||||
#
|
||||
@ -2342,24 +2345,24 @@ EXPLAIN SELECT c FROM bar WHERE b>2;;
|
||||
id 1
|
||||
select_type SIMPLE
|
||||
table bar
|
||||
type ALL
|
||||
type range
|
||||
possible_keys b
|
||||
key NULL
|
||||
key_len NULL
|
||||
key b
|
||||
key_len 5
|
||||
ref NULL
|
||||
rows 6
|
||||
Extra Using where
|
||||
rows 5
|
||||
Extra Using index condition
|
||||
EXPLAIN SELECT c FROM foo WHERE b>2;;
|
||||
id 1
|
||||
select_type SIMPLE
|
||||
table foo
|
||||
type ALL
|
||||
type range
|
||||
possible_keys b
|
||||
key NULL
|
||||
key_len NULL
|
||||
key b
|
||||
key_len 5
|
||||
ref NULL
|
||||
rows 6
|
||||
Extra Using where
|
||||
rows 5
|
||||
Extra Using index condition
|
||||
EXPLAIN SELECT c FROM foo2 WHERE b>2;;
|
||||
id 1
|
||||
select_type SIMPLE
|
||||
@ -2970,7 +2973,7 @@ 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
|
||||
DROP TABLE t1,t2;
|
||||
#
|
||||
@ -3066,7 +3069,7 @@ f1 f2 f3 f4
|
||||
EXPLAIN SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
|
||||
ORDER BY f1 DESC LIMIT 5;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range f2,f4 f4 1 NULL 22 Using where
|
||||
1 SIMPLE t1 index f2,f4 PRIMARY 4 NULL 5 Using where
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug#54117 crash in thr_multi_unlock, temporary table
|
||||
@ -3114,8 +3117,8 @@ select_type SIMPLE
|
||||
table t1
|
||||
type index
|
||||
possible_keys NULL
|
||||
key PRIMARY
|
||||
key_len 8
|
||||
key b
|
||||
key_len 13
|
||||
ref NULL
|
||||
rows 3
|
||||
Extra Using index
|
||||
@ -3127,8 +3130,8 @@ select_type SIMPLE
|
||||
table t1
|
||||
type index
|
||||
possible_keys NULL
|
||||
key PRIMARY
|
||||
key_len 8
|
||||
key b
|
||||
key_len 18
|
||||
ref NULL
|
||||
rows 3
|
||||
Extra Using index
|
||||
@ -3291,7 +3294,7 @@ SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
|
||||
1 PRIMARY t2 index NULL PRIMARY 4 NULL 1 Using index; FirstMatch(t1); Using join buffer (incremental, BNL join)
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 FirstMatch(t1); Using join buffer (incremental, BNL join)
|
||||
SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
|
||||
b
|
||||
1
|
||||
|
Reference in New Issue
Block a user