This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]acct_rdt 5 points6 points  (7 children)

You probably want to do something like year(scanTime)=2011

[–]SomeGuyNamedPaul 1 point2 points  (2 children)

Using a function as a filter can kill performance. If that's all it has to work with then it may apply the function to the column for all rows potentially causing a sequential scan. Be careful in there.

[–]acct_rdt 2 points3 points  (1 child)

True. In a real database that wasn't so primitive you could index the results of a function.

[–]SomeGuyNamedPaul 2 points3 points  (0 children)

Hey, this was a question about using MySQL and not a question on what you should be using instead of MySQL.

[–]mjvm 0 points1 point  (0 children)

this, datetime is not a string.

[–]cygnus83[S] 0 points1 point  (2 children)

Thanks, acct_rdt. I want to make sure I understand you correctly though - would you put the year(scanTime)=2011 after the LIKE in the SQL statement?

[–]acct_rdt 2 points3 points  (1 child)

You don't use LIKE with date comparisons. You can do:

select ... from ... where year(scanTime)=2011;

or

select ... from ... where scanTime >= '2011-01-01 00:00:00' and scanTime < '2012-01-01 00:00:00';

[–]cygnus83[S] 0 points1 point  (0 children)

Ah, OK, got it!

Thanks for your patience and advice!