Unix Technical Forum

IS IT FASTER TO SELECT RECORDS BY CHARACTER OR BY DATE?

This is a discussion on IS IT FASTER TO SELECT RECORDS BY CHARACTER OR BY DATE? within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Suppose I have 2 tables. Both have exactly the same data. The only difference is just the data type ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 09:29 AM
chrischee18
 
Posts: n/a
Default IS IT FASTER TO SELECT RECORDS BY CHARACTER OR BY DATE?

Suppose I have 2 tables. Both have exactly the same data. The only
difference
is just the data type for 'period' is different. Table A data type for
'period'
is character. Table B data type for 'period' is date.

Which one is faster?

select * from Table A where period > '20060420' and period < '20060517'

OR

select * from Table B where period > to_date(20060420) and period <
to_date(20060517)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 09:29 AM
Jim Kennedy
 
Posts: n/a
Default Re: IS IT FASTER TO SELECT RECORDS BY CHARACTER OR BY DATE?


"chrischee18" <chrischee18@gmail.com> wrote in message
news:1147835931.121667.82690@i40g2000cwc.googlegro ups.com...
> Suppose I have 2 tables. Both have exactly the same data. The only
> difference
> is just the data type for 'period' is different. Table A data type for
> 'period'
> is character. Table B data type for 'period' is date.
>
> Which one is faster?
>
> select * from Table A where period > '20060420' and period < '20060517'
>
> OR
>
> select * from Table B where period > to_date(20060420) and period <
> to_date(20060517)
>

So for the character it is 8 bytes and for the date is is 7 bytes. SO the
date index is smaller and thus could be more effecient.(also you should
specify the date format and not rely on implicit conversion, eg
to_date('20060420,'yyyymmdd') ) You should NOT store dates in character
fields! You store characters in character fields, numbers in number fields,
dates in date fields. If you store dates in character fields how many days
are between the strings '20060420' and '20060519'? The optimizer can't use
the information if you store dates as strings. (poor design)
Jim


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 09:29 AM
chrischee18
 
Posts: n/a
Default Re: IS IT FASTER TO SELECT RECORDS BY CHARACTER OR BY DATE?

Jim, thanks for your time and info.
I'll work on it.

Chris.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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
Forum Jump


All times are GMT. The time now is 09:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com