I have user from different timezone and I need to improve one of my query:
WHERE DATE_ADD(pa.inspection_date, INTERVAL -39600 SECOND) >= Date( '2020-05-05')
AND DATE_ADD(ai.inspection_completed_date, INTERVAL -39600 SECOND) <= DATE(
'2020-05-06') + INTERVAL 1 DAY
Currently, this query is very slow ( 5 minutes) because I think the Date_add
broke(ignore) my index on inspection_date
field. If I remove Date_add
I got 0.2 second result.
All my time on my database are in UTC. So I would like to know, how can I perform a mysql query with the user timezone and let's mysql keep my index.
User can choose the date they they want for my example, they choose the start and the end date
Try this way:
WHERE pa.inspection_date >= (DATE('2020-05-05') + INTERVAL 11 HOUR)
AND ai.inspection_completed_date <= DATE('2020-05-06') + INTERVAL 35 HOUR
And check if both columns pa.inspection_date
and ai.inspection_completed_date
are indexed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.