note 37120 deleted from function.time by aidan
| From: | aidan@php.net | Date: | Sat, 08 Oct 2005 01:06:41 +0000 |
| Subject: | note 37120 deleted from function.time by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96637@lists.php.net to get a copy of this message | ||
Note Submitter: infiwebcon at comcast dot net
----
In reference to the note from mwwaygoo about storing timestamps...
I have found that storing a datetime and then doing selects based on the mysql function
UNIX_TIMESTAMP(field_name) has problems with regard to using indices.
For instance, let's say you have a table with a 'start_datetime' and an
'end_datetime' field that holds a standard datetime value and is a true
"datetime" field. You have an index that refers to the start_datetime and end_datetime
fields in place.
However, when you do a select using something like:
SELECT * from table_name where UNIX_TIMESTAMP(start_datetime) > 'some_value' AND
UNIX_TIMESTAMP(end_datetime) < 'another value'
I have noticed problems using those indices when using the EXPLAIN function.
Has anyone else encountered this?
In my case, I changed the fields to INT and stored the timestamp itself. (it is misleading in that
the 'timestamp' field type in mysql holds a datetime value that updates itself unless you
explicitly set it). Now when I use EXPLAIN to see which index it will use, it is using the one I
created.