View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 05:21 AM
Dan Buettner
 
Posts: n/a
Default Re: Date v. DateTime index performance

Thomas, I do not think in this case that one is better than the other,
for the most part, because both require using a value computed from
the column. Computing month from a DATE field should be just as fast
as computing from a DATETIME column I would think.

Also splitting into DATE and TIME columns can make your SQL a bit
trickier depending on your needs.

That being said, one difference that might come up in extreme cases is
that the size of an index on a DATE column will be smaller than on a
DATETIME (fewer unique values, less cardinality) so if you have a lot
of records you might be able to keep all or more of the index in
memory.

One potential solution might be to use an extra column that tracks
month_number, and populate it with a trigger on insert or update.
Index that field and then use it in your WHERE clause. One
possibility anyway.

HTH,
Dan


On 12/4/06, Thomas Bolioli <tpblists@terranovum.com> wrote:
> If one has a large number of records per month and normally searches for
> things by month, yet needs to keep things time coded, does anyone know
> if it make sense to use datetime or separate date and a time columns?
> Thanks,
> Tom
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com
>
>

Reply With Quote