Last active
September 17, 2016 15:20
SQL performance tips --- Using DATE columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE INDEX tbl_idx ON tbl (date_column); | |
SELECT text, date_column | |
FROM tbl | |
WHERE YEAR(date_column) = '2012'; | |
# It should changes to the below: | |
# Wrapping the table column in a function renders the index useless for this query. | |
# Write queries for continuous periods as explicit range condition: | |
SELECT text, date_column | |
FROM tbl | |
WHERE date_column >= STR_TO_DATE('2012-01-01', '%Y-%m-%d') | |
AND date_column < STR_TO_DATE('2013-01-01', '%Y-%m-%d'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment