1
0
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:
Igor Babaev
2023-10-19 12:09:41 -07:00
committed by Oleksandr Byelkin
parent 11abc21911
commit 954a6decd4
4 changed files with 202 additions and 12 deletions

View File

@ -340,6 +340,9 @@ protected:
/* The length of an embedded key value */
uint emb_key_length;
/* This flag is used only when 'not exists' optimization can be applied */
bool not_exists_opt_is_applicable;
/*
This object provides the methods to iterate over records of
the joined table join_tab when looking for join matches between
@ -536,6 +539,7 @@ protected:
prev_cache= next_cache= 0;
buff= 0;
min_buff_size= max_buff_size= 0; // Caches
not_exists_opt_is_applicable= false;
}
/*