mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-32351 Significant slowdown for query with many outer joins
This patch fixes a performance regression introduced in the patch for the bug MDEV-21104. The performance regression could affect queries for which join buffer was used for an outer join such that its on expression from which a conjunctive condition depended only on outer tables can be extracted. If the number of records in the join buffer for which this condition was false greatly exceeded the number of other records the slowdown could be significant. If there is a conjunctive condition extracted from the ON expression depending only on outer tables this condition is evaluated when interesting fields of each survived record of outer tables are put into the join buffer. Each such set of fields for any join operation is supplied with a match flag field used to generate null complemented rows. If the result of the evaluation of the condition is false the flag is set to MATCH_IMPOSSIBLE. When looking in the join buffer for records matching a record of the right operand of the outer join operation the records with such flags are not needed to be unpacked into record buffers for evaluation of on expressions. The patch for MDEV-21104 fixing some problem of wrong results when 'not exists' optimization by mistake broke the code that allowed to ignore records with the match flag set to MATCH_IMPOSSIBLE when looking for matching records. As a result such records were unpacked for each record of the right operand of the outer join operation. This caused significant execution penalty in some cases. One of the test cases added in the patch can be used only for demonstration of the restored performance for the reported query. The second test case is needed to demonstrate the validity of the fix.
This commit is contained in:
committed by
Oleksandr Byelkin
parent
11abc21911
commit
954a6decd4
@ -4247,6 +4247,64 @@ SET JOIN_buffer_size=16384;
|
||||
SELECT * FROM information_schema.statistics JOIN information_schema.COLUMNS USING (table_name,column_name);
|
||||
--enable_result_log
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-32351: Join buffer used for outer join with ON condition
|
||||
--echo # depending only on outer tables
|
||||
--echo #
|
||||
|
||||
--source include/have_sequence.inc
|
||||
|
||||
CREATE TABLE t1 (b int NOT NULL, PRIMARY KEY (b)) ENGINE=MYISAM;
|
||||
INSERT INTO t1 select seq from seq_1_to_10000;
|
||||
CREATE TABLE t2 (b int NOT NULL, d varchar(255), KEY (b)) ENGINE=MYISAM ;
|
||||
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
|
||||
CREATE TABLE t3 (c int NOT NULL, PRIMARY KEY (c)) ENGINE=MYISAM ;
|
||||
INSERT INTO t3 select seq from seq_1_to_3000;
|
||||
CREATE TABLE t4 (c int NOT NULL, PRIMARY KEY (c)) ENGINE=MYISAM;
|
||||
INSERT INTO t4 select seq from seq_1_to_3000;
|
||||
ANALYZE TABLE t1,t2,t3,t4;
|
||||
|
||||
let $q1=
|
||||
SELECT COUNT(*)
|
||||
FROM t1
|
||||
LEFT JOIN t2 ON t1.b = t2.b
|
||||
LEFT JOIN t3 ON t2.d = t3.c
|
||||
LEFT JOIN t4 ON t3.c=1;
|
||||
|
||||
set join_cache_level=0;
|
||||
eval EXPLAIN $q1;
|
||||
eval $q1;
|
||||
set join_cache_level=default;
|
||||
eval EXPLAIN $q1;
|
||||
eval $q1;
|
||||
|
||||
DROP TABLE t1,t2,t3,t4;
|
||||
|
||||
CREATE TABLE t1 (b int NOT NULL, PRIMARY KEY (b));
|
||||
INSERT INTO t1 select seq from seq_1_to_10;
|
||||
CREATE TABLE t2 (b int NOT NULL, d varchar(255), KEY (b)) ;
|
||||
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
|
||||
CREATE TABLE t3 (c int NOT NULL, PRIMARY KEY (c)) ;
|
||||
INSERT INTO t3 select seq from seq_1_to_3;
|
||||
CREATE TABLE t4 (c int NOT NULL, PRIMARY KEY (c)) ;
|
||||
INSERT INTO t4 select seq from seq_1_to_3;
|
||||
|
||||
let $q2=
|
||||
SELECT *
|
||||
FROM t1
|
||||
LEFT JOIN t2 ON t1.b = t2.b
|
||||
LEFT JOIN t3 ON t2.d = t3.c
|
||||
LEFT JOIN t4 ON t3.c=1;
|
||||
|
||||
set join_cache_level=0;
|
||||
eval EXPLAIN $q2;
|
||||
eval $q2;
|
||||
set join_cache_level=default;
|
||||
eval EXPLAIN $q2;
|
||||
eval $q2;
|
||||
|
||||
DROP TABLE t1,t2,t3,t4;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
--echo #
|
||||
|
Reference in New Issue
Block a user