note 39648 added to function.time
| From: | twillaert at cereus dot be | Date: | Fri, 06 Feb 2004 00:04:05 +0000 |
| Subject: | note 39648 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64705@lists.php.net to get a copy of this message | ||
In response to infiwebcon:
Always try to avoid using a function on where fields in your database queries. This is the reason
you did not see any usage of your indices. Every row has to be fetched, the unix_timestamp()
function has to be applied, and then compared to the value you are looking for. Instead, apply the
functions on the constants you specify in your where clause. The following query would give you the
same result, with much better performance:
SELECT * table_name where start_datetime > from_unixtime('some_value') AND end_datetime
< from_unixtime('another value')
In this case you would have used your indices. Even if you don't have indices you will see a
performance boost. If you have a table with 1000 lines, you'll be calling unix_timestamp() 2000
times using a malformed query. When written correctly it's only 2 times for a table of any
size.
Keep storing your timestamps as datetime because they're easier to query that way.
Note: Some databases support function based indices. Still, this would be a bad place to use them.
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39648
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39648&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39648&report=yes
Search -- http://master.php.net/manage/user-notes.php