Unix Technical Forum

which column type char,varchar2 is better for index?

This is a discussion on which column type char,varchar2 is better for index? within the Oracle Database forums, part of the Database Server Software category; --> hi there, if there are two columns A and B, A is defined as char(10), B is defined as ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-23-2008, 10:04 AM
Jaguk Ku
 
Posts: n/a
Default which column type char,varchar2 is better for index?

hi there,

if there are two columns A and B, A is defined as char(10), B is defined as
varchar2(10)
if when i create indexes for both of them. which one has better performance,
and why?

I think it's not much different, if the index is made with b-tree algorithm.

Would anyone teach me what is different and which one is better and why?

Thanks in advance,

Jaguk Ku


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-23-2008, 10:04 AM
Daniel Morgan
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

Jaguk Ku wrote:

> hi there,
>
> if there are two columns A and B, A is defined as char(10), B is defined as
> varchar2(10)
> if when i create indexes for both of them. which one has better performance,
> and why?
>
> I think it's not much different, if the index is made with b-tree algorithm.
>
> Would anyone teach me what is different and which one is better and why?
>
> Thanks in advance,
>
> Jaguk Ku


This is school work and your instructor expects you to build two
tables, create a loop, and test this out and learn from what you
observe.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-23-2008, 10:05 AM
Jaguk Ku
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

This is not the school work, i just curious about it.
i can make table and index as you wish, and i might find out the
differences, and the index structure algorithm from oracle documents.
i think everyone can do this, what the newsgroup is for?
if you don't want to answer the question. just ignore it. don't post the
reply like this.

Jaguk Ku


"Daniel Morgan" <damorgan@x.washington.edu> wrote in message
news:1086915921.985866@yasure...
> Jaguk Ku wrote:
>
> > hi there,
> >
> > if there are two columns A and B, A is defined as char(10), B is defined

as
> > varchar2(10)
> > if when i create indexes for both of them. which one has better

performance,
> > and why?
> >
> > I think it's not much different, if the index is made with b-tree

algorithm.
> >
> > Would anyone teach me what is different and which one is better and why?
> >
> > Thanks in advance,
> >
> > Jaguk Ku

>
> This is school work and your instructor expects you to build two
> tables, create a loop, and test this out and learn from what you
> observe.
>
> --
> Daniel Morgan
> http://www.outreach.washington.edu/e...ad/oad_crs.asp
> http://www.outreach.washington.edu/e...oa/aoa_crs.asp
> damorgan@x.washington.edu
> (replace 'x' with a 'u' to reply)
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-23-2008, 10:05 AM
Daniel Morgan
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

Jaguk Ku wrote:

> This is not the school work, i just curious about it.
> i can make table and index as you wish, and i might find out the
> differences, and the index structure algorithm from oracle documents.
> i think everyone can do this, what the newsgroup is for?
> if you don't want to answer the question. just ignore it. don't post the
> reply like this.
>
> Jaguk Ku
>
>
> "Daniel Morgan" <damorgan@x.washington.edu> wrote in message
> news:1086915921.985866@yasure...
>
>>Jaguk Ku wrote:
>>
>>
>>>hi there,
>>>
>>>if there are two columns A and B, A is defined as char(10), B is defined

>
> as
>
>>>varchar2(10)
>>>if when i create indexes for both of them. which one has better

>
> performance,
>
>>>and why?
>>>
>>>I think it's not much different, if the index is made with b-tree

>
> algorithm.
>
>>>Would anyone teach me what is different and which one is better and why?
>>>
>>>Thanks in advance,
>>>
>>>Jaguk Ku

>>
>>This is school work and your instructor expects you to build two
>>tables, create a loop, and test this out and learn from what you
>>observe.
>>
>>--
>>Daniel Morgan
>>http://www.outreach.washington.edu/e...ad/oad_crs.asp
>>http://www.outreach.washington.edu/e...oa/aoa_crs.asp
>>damorgan@x.washington.edu
>>(replace 'x' with a 'u' to reply)


Well then let me say that this is exactly the type of exercise I
give my students ... and I would suggest that you learn this the
same way they do rather than asking the question.

But as I doubt you will let me give you the answer ... there is not
a single valid reason I can think of in Oracle to ever use a CHAR
column. And performance is only a small part of the reason.

Perhaps you can do some research and learn the rest of them.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-23-2008, 10:05 AM
Noel
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?


> This is not the school work, i just curious about it.
> i can make table and index as you wish, and i might find out the
> differences, and the index structure algorithm from oracle documents.
> i think everyone can do this, what the newsgroup is for?
> if you don't want to answer the question. just ignore it. don't post the
> reply like this.


Main different between char(x) and varchar2(x) is that
value inserted into char(x) has always length x (padded with spaces).

Secondly, char(x) could be soon skipped in new version of Oracle DB.
--
TomekB



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-23-2008, 10:06 AM
Mark D Powell
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

Daniel Morgan <damorgan@x.washington.edu> wrote in message news:<1086927757.540852@yasure>...
> Jaguk Ku wrote:
>
> > This is not the school work, i just curious about it.
> > i can make table and index as you wish, and i might find out the
> > differences, and the index structure algorithm from oracle documents.
> > i think everyone can do this, what the newsgroup is for?
> > if you don't want to answer the question. just ignore it. don't post the
> > reply like this.
> >
> > Jaguk Ku
> >
> >
> > "Daniel Morgan" <damorgan@x.washington.edu> wrote in message
> > news:1086915921.985866@yasure...
> >
> >>Jaguk Ku wrote:
> >>
> >>
> >>>hi there,
> >>>
> >>>if there are two columns A and B, A is defined as char(10), B is defined

> >
> > as
> >
> >>>varchar2(10)
> >>>if when i create indexes for both of them. which one has better

> >
> > performance,
> >
> >>>and why?
> >>>
> >>>I think it's not much different, if the index is made with b-tree

> >
> > algorithm.
> >
> >>>Would anyone teach me what is different and which one is better and why?
> >>>
> >>>Thanks in advance,
> >>>
> >>>Jaguk Ku
> >>
> >>This is school work and your instructor expects you to build two
> >>tables, create a loop, and test this out and learn from what you
> >>observe.
> >>
> >>--
> >>Daniel Morgan
> >>http://www.outreach.washington.edu/e...ad/oad_crs.asp
> >>http://www.outreach.washington.edu/e...oa/aoa_crs.asp
> >>damorgan@x.washington.edu
> >>(replace 'x' with a 'u' to reply)

>
> Well then let me say that this is exactly the type of exercise I
> give my students ... and I would suggest that you learn this the
> same way they do rather than asking the question.
>
> But as I doubt you will let me give you the answer ... there is not
> a single valid reason I can think of in Oracle to ever use a CHAR
> column. And performance is only a small part of the reason.
>
> Perhaps you can do some research and learn the rest of them.


I agree with Daniel on the use of varchar2 over char every time.

Daniel also has a good point on running your own test. The test of
char vs varchar2 in an index should be fairly easy to construct and
while you are at it you should try number verse varchar2.

You might want to try your char verse varchar2 test under two
different runs: where both indexes are built on data that is exactly
the specified size and where the data is of variable length within the
specified char field length.

When you test number verse varchar2 you should find very little
practical difference though numeric key access should prove to be a
little faster. At least it did when an Oracle support analyst posted
some test results a couple years back.

HTH -- Mark D Powell --
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-23-2008, 10:06 AM
Alan
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

> But as I doubt you will let me give you the answer ... there is not
> a single valid reason I can think of in Oracle to ever use a CHAR
> column. And performance is only a small part of the reason.
>


This is not a valid reason, but I use CHAR(1) in place of the non-existant
Boolean (no, I don't want to argue about the need for Boolean data), or
maybe for a flag. Just for ease when scanning designs and so on.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-23-2008, 10:07 AM
Jonathan Lewis
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?


Note in-line

--
Regards

Jonathan Lewis

http://www.jlcomp.demon.co.uk

http://www.jlcomp.demon.co.uk/faq/ind_faq.html
The Co-operative Oracle Users' FAQ

http://www.jlcomp.demon.co.uk/seminar.html
Optimising Oracle Seminar - schedule updated May 1st


"Mark D Powell" <Mark.Powell@eds.com> wrote in message
news:2687bb95.0406110545.e66f62f@posting.google.co m...
>
> When you test number verse varchar2 you should find very little
> practical difference though numeric key access should prove to be a
> little faster. At least it did when an Oracle support analyst posted
> some test results a couple years back.
>


There are two different scenarios, though.

The speed of accessing a given amount of data, and
the estimated cardinality for the where clause that
is supposed to identify the data.

Representing numeric (or date) information as
character columns can cause the optimiser to
get wildly inaccurate estimates of cardinality
and therefore choose the wrong execution
path. (Which brings you back to the performance
question from a different direction).



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-23-2008, 10:07 AM
Daniel Morgan
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?

Alan wrote:

>>But as I doubt you will let me give you the answer ... there is not
>>a single valid reason I can think of in Oracle to ever use a CHAR
>>column. And performance is only a small part of the reason.
>>

>
>
> This is not a valid reason, but I use CHAR(1) in place of the non-existant
> Boolean (no, I don't want to argue about the need for Boolean data), or
> maybe for a flag. Just for ease when scanning designs and so on.


But do keep in mind that 0 and 1 would be more efficient for that purpose.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
http://www.outreach.washington.edu/e...oa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-23-2008, 10:08 AM
Jonathan Lewis
 
Posts: n/a
Default Re: which column type char,varchar2 is better for index?


Note in-line.

--
Regards

Jonathan Lewis

http://www.jlcomp.demon.co.uk

http://www.jlcomp.demon.co.uk/faq/ind_faq.html
The Co-operative Oracle Users' FAQ

http://www.jlcomp.demon.co.uk/seminar.html
Optimising Oracle Seminar - schedule updated May 1st


"Daniel Morgan" <damorgan@x.washington.edu> wrote in message
news:1087071115.755274@yasure...
>
> > This is not a valid reason, but I use CHAR(1) in place of the

non-existant
> > Boolean (no, I don't want to argue about the need for Boolean data), or
> > maybe for a flag. Just for ease when scanning designs and so on.

>

It sounds like a perfectly valid reason to me.
Standards that do no harm and add clarity to
structure and code are always valid.

> But do keep in mind that 0 and 1 would be more efficient for that purpose.
>


Depends where you want the efficiency - from an Oracle
viewpoint,
0 is stored as 0x1 0x80
1 is stored as 0x2 0xC1 0x02
which is arguably less efficient than the character equivalent.


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 11:20 PM.


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