Home » Performance » MySQL » INT vs. TIMESTAMP data types
INT vs. TIMESTAMP data types [message #2934] Fri, 11 April 2008 16:26 Go to next message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Hi,

Currently for a blog platform I have:

year=YEAR
month=TINYINT
day=TINYINT
timestamp=INT

I was contemplating using the TIMESTAMP type.

To get previous usage like yearly monthly etc archives I would do:

WHERE author=4 AND YEAR(timestamp)=2008 AND MONTH(timestamp)=4

Would this utilize an index on INDEX(author, timestamp) or would the functions YEAR() and MONTH() which extract kill the index usage?

Cheers!


Martin Gallagher | Speeple: The latest news
Re: INT vs. TIMESTAMP data types [message #2936 is a reply to message #2934 ] Fri, 11 April 2008 21:01 Go to previous messageGo to next message
carpii  is currently offline carpii
Messages: 46
Registered: November 2006
Member
It will not be able to use the index for the YEAR and MONTH parts.
But it will still use the index to narrow down the author
Re: INT vs. TIMESTAMP data types [message #2937 is a reply to message #2934 ] Sat, 12 April 2008 03:35 Go to previous messageGo to next message
Hubert Roksor
Messages: 3
Registered: April 2008
Junior Member
You can work around using YEAR() by converting the date boundaries to timestamps. For instance, that clause can use your whole index:

WHERE author=4
  AND timestamp BETWEEN UNIX_TIMESTAMP('2008-04-01') AND UNIX_TIMESTAMP(LAST_DAY('2008-04-01'))


Of course, you can also convert the dates using your favourite programming language if you prefer.
Re: INT vs. TIMESTAMP data types [message #2938 is a reply to message #2934 ] Sat, 12 April 2008 07:07 Go to previous message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Thanks for clearling that up and the helpful tips chaps!

[Updated on: Sat, 12 April 2008 07:21]


Martin Gallagher | Speeple: The latest news
Previous Topic:ndb size
Next Topic:Tweak Innodb parameters
Goto Forum:
  



Current Time: Tue Oct 7 12:41:30 EDT 2008

Total time taken to generate the page: 0.01815 seconds
.:: Contact :: Home :: MySQL Support by Percona.com ::.

Powered by: FUDforum 2.7.5.
Copyright ©2001-2006 FUD Forum Bulletin Board Software

MySQL Performance | Forum authority Badge