mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
727491b72a
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)
123 lines
3.5 KiB
Text
123 lines
3.5 KiB
Text
#
|
|
# Run subselect_sj2.test with BKA enabled
|
|
#
|
|
|
|
set @save_optimizer_switch_jcl6=@@optimizer_switch;
|
|
set @@optimizer_switch='optimize_join_buffer_size=on';
|
|
set @@optimizer_switch='semijoin_with_cache=on';
|
|
set @@optimizer_switch='outer_join_with_cache=on';
|
|
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
|
|
|
|
set join_cache_level=6;
|
|
show variables like 'join_cache_level';
|
|
|
|
set @optimizer_switch_for_subselect_sj2_test=@@optimizer_switch;
|
|
set @join_cache_level_for_subselect_sj2_test=@@join_cache_level;
|
|
|
|
--source subselect_sj2.test
|
|
|
|
set @innodb_stats_persistent_save= @@innodb_stats_persistent;
|
|
set @innodb_stats_persistent_sample_pages_save=
|
|
@@innodb_stats_persistent_sample_pages;
|
|
|
|
set global innodb_stats_persistent= 1;
|
|
set global innodb_stats_persistent_sample_pages=100;
|
|
|
|
--echo #
|
|
--echo # Bug #898073: potential incremental join cache for semijoin
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a int, b varchar(1), KEY (b,a));
|
|
INSERT INTO t1 VALUES (0,'x'), (5,'r');
|
|
|
|
CREATE TABLE t2 (a int) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (8);
|
|
|
|
CREATE TABLE t3 (b varchar(1), c varchar(1)) ENGINE=InnoDB;
|
|
INSERT INTO t3 VALUES ('x','x');
|
|
|
|
CREATE TABLE t4 (a int NOT NULL, b varchar(1)) ENGINE=InnoDB;
|
|
INSERT INTO t4 VALUES (20,'r'), (10,'x');
|
|
|
|
set @tmp_optimizer_switch=@@optimizer_switch;
|
|
|
|
SET SESSION optimizer_switch='semijoin_with_cache=on';
|
|
|
|
SET SESSION join_cache_level=2;
|
|
EXPLAIN
|
|
SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
|
|
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
|
|
SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
|
|
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
|
|
|
|
set optimizer_switch=@tmp_optimizer_switch;
|
|
set join_cache_level=default;
|
|
|
|
DROP TABLE t1,t2,t3,t4;
|
|
|
|
--echo #
|
|
--echo # Bug #899696: potential incremental join cache for semijoin
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
|
|
INSERT INTO t1 VALUES (1, 6), (2, 8);
|
|
CREATE TABLE t2 (b int) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (8);
|
|
CREATE TABLE t3 (pk int PRIMARY KEY, a int);
|
|
INSERT INTO t3 VALUES (1, 6), (2, 8);
|
|
CREATE TABLE t4 (b int) ENGINE=InnoDB;
|
|
INSERT INTO t4 VALUES (2),(88),(99);
|
|
|
|
insert into t2 select seq from seq_100_to_200;
|
|
|
|
set @tmp_optimizer_switch=@@optimizer_switch;
|
|
|
|
SET optimizer_switch = 'semijoin_with_cache=on';
|
|
SET join_cache_level = 2;
|
|
|
|
--replace_column 9 #
|
|
EXPLAIN
|
|
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
|
|
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
|
|
|
|
set optimizer_switch=@tmp_optimizer_switch;
|
|
set join_cache_level=default;
|
|
|
|
DROP TABLE t1,t2,t3,t4;
|
|
|
|
|
|
--echo #
|
|
--echo # Bug #899962: materialized subquery with join_cache_level=3
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a varchar(1), b varchar(1)) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES ('v','v');
|
|
CREATE TABLE t2 (a varchar(1), b varchar(1)) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES ('v','v');
|
|
|
|
set @tmp_optimizer_switch=@@optimizer_switch;
|
|
|
|
SET optimizer_switch = 'semijoin_with_cache=on';
|
|
SET join_cache_level = 3;
|
|
|
|
EXPLAIN
|
|
SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a);
|
|
SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a);
|
|
|
|
EXPLAIN
|
|
SELECT * FROM t1 WHERE b IN (SELECT max(a) FROM t2 GROUP BY a);
|
|
SELECT * FROM t1 WHERE b IN (SELECT max(a) FROM t2 GROUP BY a);
|
|
|
|
set optimizer_switch=@tmp_optimizer_switch;
|
|
set join_cache_level=default;
|
|
|
|
DROP TABLE t1,t2;
|
|
|
|
set global innodb_stats_persistent= @innodb_stats_persistent_save;
|
|
set global innodb_stats_persistent_sample_pages=
|
|
@innodb_stats_persistent_sample_pages_save;
|
|
|
|
set @@optimizer_switch=@save_optimizer_switch_jcl6;
|
|
set @optimizer_switch_for_subselect_sj2_test=NULL;
|
|
set @join_cache_level_subselect_sj2_test=NULL;
|
|
|