Question

I want to query a table that has around 70 million records. The query is like:

SELECT * FROM tweetentities 
 WHERE applicationId = 6 
   AND isRetweet = false 
   AND (CURDATE() <= DATE_ADD(tweetDate, INTERVAL 7 DAY));

What I want to do is I try to get older records than 7 days on the table with other criteria like appId and isRetweet. The main point that I'd like to know is that does the query work faster if I request just the necessary columns rather than all columns with " * " symbol. Or if you have better idea to optimize the query above, please tell me this.

Thanks.

Was it helpful?

Solution

This is your query:

SELECT *
FROM tweetentities
WHERE applicationId = 6 AND
      isRetweet = false AND
      (CURDATE() <= DATE_ADD(tweetDate, INTERVAL 7 DAY));

You should rewrite it as:

SELECT *
FROM tweetentities
WHERE applicationId = 6 AND
      isRetweet = false AND
      tweetDate >= DATE_ADD(CURDATE(), INTERVAL -7 DAY)

Then build the index tweetentities(applicationId, isRetweet, tweetDate).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top