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 > indexes - doubts

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-09, 03:43
Danmln Danmln is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
indexes - doubts

Hi experts,

I have a table with primary key formed by two fields:
VENDOR & MANUFACTURER_PART_NUMBER

This table has more than 2 million records.

If i search a particular MANUFACTURER_PART_NUMBER it takes about 5-6 seconds.

My question is: in my situation , if MANUFACTURER_PART_NUMBER field is part of primary key, it's necessary or it's OK to create index on this field?

if MANUFACTURER_PART_NUMBER field is part of primary key, it's indexed,right? ... so, why a simple query takes so long?

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 09-22-09, 04:24
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Imagine looking up a word in the dictionary, if you know the first few letters then it's easy and quick. Now imagine looking up a word where the only letter you don't know is the the first letter - it's impossible as you'll have to look through all the words in the dictionary.

It's the same thing when looking for a record in a table using a composite index but not knowing the first field in the composite index - you can only table scan the all the records.

I'm not sure what you're current index is but either MANUFACTURER_PART_NUMBER should be the first field in the composite index or there should be another index on the table just on this field.
Reply With Quote
  #3 (permalink)  
Old 09-23-09, 02:30
Danmln Danmln is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
Thanks Mike,

another questions in topic subject:

it's OK to create index on fields which types are date?
Reply With Quote
  #4 (permalink)  
Old 09-23-09, 03:04
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
yes, no problem there.
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