🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #678

Re: Birthdate Query

#678
From: Martijn Tonies
Date: Tue, 30 Oct 2007 18:28
51 lines
3096 bytes
> > 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.

Mind you, an index on "month" wouldn't be much good on this number of
rows, cause it's but 12 different values. "Day" would be slightly better,
but
nothing much really.

Perhaps a string value "month-day" and a query of
WHERE MONTH_DAY BETWEEN '01-01' AND '04-01' would be better?

Oh heck, I don't know, just saying it's not an ideal candidate for an index
:-)

-- 
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
Technical Details
Message-ID: <472777c9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com> <4726efdc$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
From: "Martijn Tonies" <m.tonies@upscene.removethis.com>
Newsgroups: borland.public.interbase.sql
References: <4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com> <4726efdc$1@newsgroups.borland.com>
Subject: Re: Birthdate Query
Date: Tue, 30 Oct 2007 19:28:43 +0100
Lines: 53
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1914
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1914
NNTP-Posting-Host: 212.238.159.172
Message-ID: <472777c9$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1193768905 212.238.159.172 (30 Oct 2007 11:28:25 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail