summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2019-12-07 18:21:36 +0300
committerSergei Petrunia <psergey@askmonty.org>2020-01-12 15:48:46 +0300
commit9c3eca85141836548214e3c68f256b3868502509 (patch)
tree7a413fb85a8d963ac9d68880a252c7128ebabbc9 /sql
parentcba9ed12790727c70332f8862684b13ac3f25bbc (diff)
downloadmariadb-git-bb-10.3-mdev21243.tar.gz
MDEV-21243: Join buffer: condition is checked in wrong place for range accessbb-10.3-mdev21243
In this scenario: - There is a possible range access for table T - And there is a ref access on the same index which uses fewer key parts - The join optimizer picks the ref access (because it is cheaper) - make_join_select applies this heuristic to switch to range: /* Range uses longer key; Use this instead of ref on key */ Join buffer will be used without having called JOIN_TAB::make_scan_filter(). This means, conditions that should be checked when reading table T will be checked after T is joined with the contents of the join buffer, instead. Fixed this by adding a make_scan_filter() check. (updated patch after backport to 10.3) (Fix testcase on Windows)
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index da8dfdd015a..76cad16de28 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10966,6 +10966,13 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (i != join->const_tables && tab->use_quick != 2 &&
!tab->first_inner)
{ /* Read with cache */
+ /*
+ TODO: the execution also gets here when we will not be using
+ join buffer. Review these cases and perhaps, remove this call.
+ (The final decision whether to use join buffer is made in
+ check_join_cache_usage, so we should only call make_scan_filter()
+ there, too).
+ */
if (tab->make_scan_filter())
DBUG_RETURN(1);
}
@@ -11928,6 +11935,9 @@ uint check_join_cache_usage(JOIN_TAB *tab,
if ((tab->cache= new (root) JOIN_CACHE_BNL(join, tab, prev_cache)))
{
tab->icp_other_tables_ok= FALSE;
+ /* If make_join_select() hasn't called make_scan_filter(), do it now */
+ if (!tab->cache_select && tab->make_scan_filter())
+ goto no_join_cache;
return (2 - MY_TEST(!prev_cache));
}
goto no_join_cache;