SELECT dateToFind FROM table1 INNER JOIN table2 ON dateToFind BETWEEN dateFrom AND dateTo
I need to improve the performance of this kind of query. I added BTREE indexes on dateToFind, dateFrom, dateTo and a combination of dateFrom and dateTo.
But nothing changed, with or without indexes the query time is the same. I know BETWEEN doesn't use indexes, is it true?
As M Khalid Junaid suggested, this is the EXPLAIN PLAN of the above query:
+----+-------------+--------------+------+--------------------------------+------+---------+------+-------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+------+--------------------------------+------+---------+------+-------+------------------------------------------------+
| 1 | SIMPLE | table1 | ALL | dateToFind | NULL | NULL | NULL | 32027 | |
| 1 | SIMPLE | table2 | ALL | dateFrom,dateTo,dateFrom_dateTo| NULL | NULL | NULL | 6951 | Range checked for each record (index map: 0xE) |
+----+-------------+--------------+------+--------------------------------+------+---------+------+-------+------------------------------------------------+
Any suggestion?
EXPLAIN
plan for the above query ?BETWEEN
use >= it's much clearer that way.