Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos 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 support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Index Performance?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-08, 04:33
kfc@vd.dk kfc@vd.dk is offline
Registered User
 
Join Date: Jun 2003
Posts: 58
Index Performance?

I have to large tables, A and B with the common columns c and d
I make a select statement

select * from A,B
where A.c=B.c and A.d=B.d;

Should my indexes on the two columns be common indexes or single indexes?

create index INDX1 on A(c);
create index INDX2 on A(d);
create index INDX3 on B(c);
create index INDX4 on B(d);

or

create index INDX5 on A(c,d);
create index INDX6 on B(c,d);
Reply With Quote
  #2 (permalink)  
Old 10-13-08, 04:56
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
For the given example, use the second alternative and put that column to the front which gives a higher selectivity (i.e. which returns less rows when queried with a specific value)
Reply With Quote
  #3 (permalink)  
Old 10-13-08, 05:10
kfc@vd.dk kfc@vd.dk is offline
Registered User
 
Join Date: Jun 2003
Posts: 58
To front?

I am not sure, that I understand. What do you mean when you say, that I should bring til columns to the front?
Reply With Quote
  #4 (permalink)  
Old 10-13-08, 06:43
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
Quote:
Originally Posted by kfc@vd.dk
I am not sure, that I understand. What do you mean when you say, that I should bring til columns to the front?
There is a difference between

create index INDX5 on A(c,d);

and

create index INDX5 on A(d,c);

the first column in the index definition should be that column, which reduces the number of rows more than the other.

If a select * from a where c = 5 returns 100 rows and a select * from a where d = 14 returns 50000 rows, then c should be the first column.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On