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 > how to put indexes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-09, 09:11
Zamolxe Zamolxe is offline
Registered User
 
Join Date: Feb 2004
Location: Bucharest
Posts: 37
Post how to put indexes

Here is the following problem:

email
------
id
email

list
------
id
name

email_to_list
------
email_id
list_id

On `email_to_list` what is your recommendation on how to put indexes. I need to put an UNIQUE on (email_id, list_id). Do i also need to put INDEX on email_id and list_id separately? Presuming i make a lot of JOIN queries on these keys.

Thanks
Reply With Quote
  #2 (permalink)  
Old 08-19-09, 12:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by Zamolxe
I need to put an UNIQUE on (email_id, list_id).
i would just make them the primary key instead

Quote:
Originally Posted by Zamolxe
Do i also need to put INDEX on email_id and list_id separately?
no!!

primary keys get a unique index by default

but you might add an index on ( list_id , email_id )

this index, along with the primary key index, ensure that all queries will use one or the other index, and both of them are likely to be a covering index
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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