Article View: borland.public.interbase.sql
Article #677Re: Birthdate Query
From: Thomas Steinmaurer
Date: Tue, 30 Oct 2007 08:49
Date: Tue, 30 Oct 2007 08:49
40 lines
2576 bytes
2576 bytes
Hi, > I think I may have found a solution. I have stumbled across a function, > EXTRACT. > > select * from CONTACTS where EXTRACT (DAY from CBIRTHDAY) > 1 > select * from CONTACTS where EXTRACT (MONTH from CBIRTHDAY) > 1 > select * from CONTACTS where EXTRACT (YEAR from CBIRTHDAY) > 1950 > > What worries me though is execution time. If I had say 500,000 contacts > in this table, would it have to brute-force (for-loop) its way through > all these records extracting the month and day from each Contact's > birthdate? > > If I created seperate fields BirthMonth and BirthDay (Integers) I could > index on them, and make sure execution time is fast. If I have the the > Contact's Birthday field (CBIRTHDAY) indexed, will execution time be > fast? (I'm under the impression that Date fields are stored as > Double/Floating point numbers, and indexing them puts them in order by > linear time. I don't see how these queries (listed above) could > extract the Month or Day values from the date field without looking at > each individual Birthdate, each and every time this query runs... I > don't think we want to do that.) The optimizer won't be able to use an index on CBIRTHDAY when using EXTRACT. You have to use seperate indexed fields as you have pointed out, where the content of the field could be maintained via triggers at the server-side. -- Best Regards, Thomas Steinmaurer LogManager Series - Logging/Auditing Suites supporting InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2 Upscene Productions http://www.upscene.com
Technical Details
Message-ID:
<4726efdc$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,d9969aee39c0cba7 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 30 Oct 2007 09:49:26 +0100 From: Thomas Steinmaurer <t.steinmaurer_dontbugmewithspam@upscene.com> User-Agent: Thunderbird 1.5.0.13 (Windows/20070809) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: Birthdate Query References: <4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com> In-Reply-To: <4726b05b$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 193.186.164.88 Message-ID: <4726efdc$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1193734108 193.186.164.88 (30 Oct 2007 01:48:28 -0700) Lines: 40 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail