Skip to content

Commit

Permalink
MDEV-8320 Allow index usage for DATE(col) <=> const and YEAR <=> const
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Olernov committed Apr 25, 2023
1 parent 54c1127 commit f0b665f
Show file tree
Hide file tree
Showing 17 changed files with 3,421 additions and 8 deletions.
4 changes: 3 additions & 1 deletion libmysqld/CMakeLists.txt
Expand Up @@ -68,7 +68,9 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/key.cc ../sql/lock.cc ../sql/log.cc
../sql/log_event.cc ../sql/log_event_server.cc
../sql/mf_iocache.cc ../sql/my_decimal.cc
../sql/net_serv.cc ../sql/opt_range.cc ../sql/opt_sum.cc
../sql/net_serv.cc ../sql/opt_range.cc
../sql/opt_rewrite_date_cmp.cc
../sql/opt_sum.cc
../sql/parse_file.cc ../sql/procedure.cc ../sql/protocol.cc
../sql/records.cc ../sql/repl_failsafe.cc ../sql/rpl_filter.cc
../sql/rpl_record.cc ../sql/des_key_file.cc
Expand Down

0 comments on commit f0b665f

Please sign in to comment.