Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
mysql with date function query running slow

I found something weird while executing query today and i want to know how this happens.

Below is my query:

select sum(price) as total from table_a where testing_date = '2020-06-10' 

this query takes 2-5 seconds while searching for the data. Now i did small change in the query as follow:

select sum(price) as total from table_a where date(testing_date) = '2020-06-10' 

In this case query takes 2-3 minutes. Here testing_date column data in dateTime format for example : 2020-06-01 00:00:00

Here total records size is more than 7 million.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Don't use a function on the column you filter on. This makes the query non-SARGeable, meaning that the database cannot take advantage of an existing index. Basically, you are forcing the database to do the computation on each and every value in the column before the filtering can happen.

If you want to filter on a given day, you can use inequalities with half-open intervals:

where testing_date >= '2020-06-10' and testing_date < '2020-06-11'
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!