Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 6:58 PM   #1
Salagir
 
Salagir's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default DateTime search optimisation

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'

...WHERE DATE_FORMAT(whenitwas, ,'%Y-%m-%d') = '2006-01-01'

I would say it's the first.
And that second is the same as first.

Same question if the field is an index



I also saw the following code :
....WHERE UNIX_TIMESTAMP(whenitwas) + 3600 > UNIX_TIMESTAMP(NOW())

And after yelling in the office there was a crazy or ignorant guy among
us, I had the following questions :

- I thought comparing on UNIX_TIMESTAMP(whenitwas) instead of whenitwas
would take much much time, especially if it's indexed, as a modification
would be done before comparring (and so losing the advantage of the
index), but I compared the 2 ways in a request and it's didn't seem very
different.
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.

- when using " field + 5 < 10 ", is mysql clever and comparing on each
row `field` to 5 or does he stupidly add 5 each time? 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?


Thanks for your anwsers and forgive my english

--
My Webcomic: www.geeksworld.org -+- All my websites: manaworld.free.fr
<morganj> 0 is false and 1 is true, correct?
<alec_eso> 1, morganj
<morganj> bastard.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 6:59 PM   #2
Axel Schwenke
 
Axel Schwenke's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default DateTime search optimisation

Salagir <Salagir@jeruCITEDELESPACE.org.invalid> wrote:
> 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'


If you have an index on `whenitwas`, those queries should be blindingly
fast. Also there is no difference in speed.

> ..WHERE DATE_FORMAT(whenitwas, ,'%Y-%m-%d') = '2006-01-01'


This will not use an index on `whenitwas`. It will be even more slower
than the required full table scan suggests, because the DATE_FORMAT()
call is expensive.

> 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.


Use the source, Luke! DATETIME is held in a C struct, defined in
mysql_time.h

> - when using " field + 5 < 10 ", is mysql clever and comparing on each
> row `field` to 5 or does he stupidly add 5 each time?


IMHO this optimization is out of the scope of an SQL parser.

> 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?


If field is indexed, this optimization could make the difference
between an index lookup and a full table scan.


XL
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 7:01 PM   #3
Salagir
 
Salagir's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default DateTime search optimisation

On Fri, 10 Feb 2006 13:14:18 +0100, in comp.databases.mysql,
Axel Schwenke wrote:
> Salagir <Salagir@jeruCITEDELESPACE.org.invalid> wrote:
>> 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'

> If you have an index on `whenitwas`, those queries should be blindingly
> fast. Also there is no difference in speed.
>> ..WHERE DATE_FORMAT(whenitwas, ,'%Y-%m-%d') = '2006-01-01'

> This will not use an index on `whenitwas`. It will be even more slower
> than the required full table scan suggests, because the DATE_FORMAT()
> call is expensive.


As I thought.

>> 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.

> Use the source, Luke! DATETIME is held in a C struct, defined in
> mysql_time.h


^_^ each time I try that, I'm kind of drowned in the complexity.
Plus, all the magic goes away

>> - when using " field + 5 < 10 ", is mysql clever and comparing on each
>> row `field` to 5 or does he stupidly add 5 each time?

> IMHO this optimization is out of the scope of an SQL parser.


Humans still rule!

>> 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?

> If field is indexed, this optimization could make the difference
> between an index lookup and a full table scan.


Thank you very much for your answers.
Now I have some queries to change..

--
My Webcomic: www.geeksworld.org -+- All my websites: manaworld.free.fr
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting integers to datetime Peter Database 3 07-01-2007 6:25 PM
Converting integers to datetime Peter Database 1 05-31-2007 8:46 PM
MSN Optimisation Tips hirenseo MSN questions 8 07-15-2006 4:25 PM


Featured Websites




All times are GMT +1. The time now is 4:59 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98