summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorOleg Smirnov <olernov@gmail.com>2023-02-17 19:21:30 +0700
committerOleg Smirnov <olernov@gmail.com>2023-03-20 10:56:41 +0700
commit22ebce8d684cbcbd7ff8c044f387b9cd5ca295f7 (patch)
tree39c73cedf0ee173d437da42c84d0090420e9554c /sql/sql_select.cc
parentce4a289f1c367987977f1a02bbb8d8b8e8e6bb53 (diff)
downloadmariadb-git-bb-11.0-MDEV-8320.tar.gz
MDEV-8320 Allow index usage for DATE(col) <=> const and YEAR <=> constbb-11.0-MDEV-8320
Rewrite datetime comparison conditions into sargeable. For example, YEAR(col) <= val -> col <= YEAR_END(val) YEAR(col) < val -> col < YEAR_START(val) YEAR(col) >= val -> col >= YEAR_START(val) YEAR(col) > val -> col > YEAR_END(val) YEAR(col) = val -> col BETWEEN YEAR_START(val) AND YEAR_END(val) Do the same with DATE(col), for example: DATE(col) <= val -> col <= DAY_END(val) After such a rewrite index lookup on column "col" can be employed
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9b9d93d182e..12d4eb2cd79 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2257,6 +2257,8 @@ JOIN::optimize_inner()
}
transform_in_predicates_into_equalities(thd);
+ if (thd->lex->are_date_funcs_used())
+ transform_date_conds_into_sargable();
conds= optimize_cond(this, conds, join_list, ignore_on_expr,
&cond_value, &cond_equal, OPT_LINK_EQUAL_FIELDS);
@@ -31095,6 +31097,20 @@ bool JOIN::transform_in_predicates_into_equalities(THD *thd)
/**
@brief
+ Rewrite datetime comparison conditions into sargable.
+ See details in the description for class Date_cmp_func_rewriter
+*/
+
+bool JOIN::transform_date_conds_into_sargable()
+{
+ DBUG_ENTER("JOIN::transform_date_conds_into_sargable");
+ DBUG_RETURN(transform_all_conds_and_on_exprs(
+ thd, &Item::date_conds_transformer));
+}
+
+
+/**
+ @brief
Transform all items in WHERE and ON expressions using a given transformer
@param thd The context of the statement