If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > index

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-17-10, 07:10
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
Smile index

hi,
I have a sql on a table like below

select field1, field2 from table1
where field3 = ?
and filed4 = ?

I have just created a composite index on the filed3&field4

Will that do? or should i add the fields in select clause also to this?

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-19-10, 06:08
Luis Santos Luis Santos is offline
Registered User
 
Join Date: Jun 2009
Location: Lisboa, Portugal
Posts: 51
I donīt understand the question. You don't need any index to do that query, you can create an index to make it quiker or for other proposes. What is your problem?
__________________
LS
Reply With Quote
  #3 (permalink)  
Old 09-20-10, 04:52
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
Exclamation

Quote:
Originally Posted by Luis Santos View Post
I donīt understand the question. You don't need any index to do that query, you can create an index to make it quiker or for other proposes. What is your problem?
My question is, how to pick the columns for the index and on which order?

for instance, in the below query-
select
from a, b, c
where a.a1 = b.b1
and b.b1 = c.c1
and c.c2 = "AB"

so, in this case, which is the efficient way of indexing, shoul i go for composite indices?
Reply With Quote
  #4 (permalink)  
Old 09-21-10, 09:02
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
The first column in a composite index should be the one you use most frequently.

For example you often join the table with c1 but you dont have c2 in the where condition all the time:
CREATE INDEX idx_c_c1_c2 ON c (c1, c2);

But I would prefer two Indexes:
CREATE INDEX idx_c_c1 ON c (c1);
CREATE INDEX idx_c_c2 ON c (c2);
Reply With Quote
  #5 (permalink)  
Old 09-21-10, 11:11
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
Quote:
Originally Posted by InformixWilli View Post
The first column in a composite index should be the one you use most frequently.

For example you often join the table with c1 but you dont have c2 in the where condition all the time:
CREATE INDEX idx_c_c1_c2 ON c (c1, c2);

But I would prefer two Indexes:
CREATE INDEX idx_c_c1 ON c (c1);
CREATE INDEX idx_c_c2 ON c (c2);
Thanks for the info!
I just have another doubt on ordering the columns for my index.

For example, i have a join as below
WHERE c1.c = c2.c
AND c1.d = ?

In table c1, field c has the most distinct count when compared to field d.
so the index should be like idx_c1(c,d).

But since my query gets the field 'd' value as i/p, will changing the order as (d,c) helps me.

Thanks
Reply With Quote
  #6 (permalink)  
Old 09-21-10, 12:18
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Is your table so big that this is important?

Check the time your query runs without an index, create one, check again, create another one and check again.
Reply With Quote
  #7 (permalink)  
Old 09-21-10, 12:33
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
Quote:
Originally Posted by InformixWilli View Post
Is your table so big that this is important?

Check the time your query runs without an index, create one, check again, create another one and check again.
Thats a good apprach!! My table is huge than you think, it has millions, thats why i'm concentrating more on this.

Have you tried SET EXPLAIN ON in isql, I tried that but i couldn't find the out file, i guess it should go to the current directory, but it doesn't.

Could you please help me on this?

Many Thanks!!!
Reply With Quote
  #8 (permalink)  
Old 09-21-10, 13:20
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Try "set explain file to '/tmp/explain';"

Are there a lot of different querys on this table or only one or two?
Reply With Quote
  #9 (permalink)  
Old 09-21-10, 13:28
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
Quote:
Originally Posted by InformixWilli View Post
Try "set explain file to '/tmp/explain';"

Are there a lot of different querys on this table or only one or two?
"set explain file to '/tmp/explain';" fails!!!
I'm getting syntax error.

I'm using isql version -7.30.HC6

Are there a lot of different querys on this table or only one or two?

YES, there are different query's with differenct WHERE criteria's.

Cheers!
Reply With Quote
  #10 (permalink)  
Old 09-21-10, 14:34
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Okay, I use DBAccess with IDS 11.50.UC6DE.

Take a look in the INFORMIXDIR, I remind that there was something but its also possible that I was there when I started dbaccess.

When there are a lot of different kind of querys, I would not create special composite indices but indices on single columns.

If a lot of querys use the same columns in the where condition then you can create a composite on it.

With IDS 11.50 a composite index can be used better.
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On