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 > MySQL > can I increase performance with another index?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-29-04, 21:22
gomer gomer is offline
Registered User
 
Join Date: Jan 2004
Posts: 2
can I increase performance with another index?

I have a table with a composite primary key - for example the primary key consists of column_1 and column_2.

If I am doing a select using only one of the columns, do I need a another index (in addition to the one for the primary key) to attain the maximum speed in a query such as the following:

"SELECT FROM table WHERE column_2 = "x" ;"

Will the index created for the primary key be sufficient to give me the best performance or can I increase the speed of the query by adding a separate index on column_2.

Thanks.
-gomer
Reply With Quote
  #2 (permalink)  
Old 01-29-04, 21:31
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
MySQL can't use a partial index if the columns don't form a leftmost prefix of the index. Suppose you have the SELECT statements shown here:

mysql> SELECT * FROM tbl_name WHERE col1=val1;
mysql> SELECT * FROM tbl_name WHERE col2=val2;
mysql> SELECT * FROM tbl_name WHERE col2=val2 AND col3=val3;

If an index exists on (col1, col2, col3), only the first of the preceding queries uses the index. The second and third queries do involve indexed columns, but (col2) and (col2, col3) are not leftmost prefixes of (col1, col2, col3).

-- http://www.mysql.com/doc/en/MySQL_indexes.html
so declare a separate index on column_2
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-29-04, 23:02
gomer gomer is offline
Registered User
 
Join Date: Jan 2004
Posts: 2
r937, thanks so much for a clear answer, it is very much appreciated!

-gomer
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