Salagir <SalagirjeruCITEDELESPACE.org.invalid> wrote:If you have an index on `whenitwas`, those queries should be blindingly> Hi. I have a datetime field, named 'whenitwas'.
> What search would be faster ?
>
> ..WHERE whenitwas >= '2006-01-01' AND whenitwas < '2006-01-01'+INTERVAL 1 DAY
> ..WHERE whenitwas >= '2006-01-01 00:00:00' AND whenitwas <= '2006-01-01 23:59:59'
fast. Also there is no difference in speed.
This will not use an index on `whenitwas`. It will be even more slower> ..WHERE DATE_FORMAT(whenitwas, ,'%Y-%m-%d') = '2006-01-01'
than the required full table scan suggests, because the DATE_FORMAT()
call is expensive.
Use the source, Luke! DATETIME is held in a C struct, defined in> After all, I don't know how datetimes are written in a databases, maybe
> the format make it readable as easily in text form as in timestamp
> form.
mysql_time.h
IMHO this optimization is out of the scope of an SQL pr.> - when using " field + 5 < 10 ", is mysql clever and comparing on each
> row `field` to 5 or does he stupidly add 5 each time?
If field is indexed, this optimization could make the difference> And even if it
> did, would the optimisation of doing " field < 10 - 5 " (of course 10
> is from a dynamic var in the code) win us more than 0.00001 seconds?
between an index lookup and a full table scan.
XL
Bookmarks