Solved

MySQL Index

Posted on 2013-12-02
1
495 Views
Last Modified: 2013-12-02
Hi Experts,

I have question about index in database. I've read some website that I can have composite indices which MySQL will know when to use it. I've also noticed that some page said if I have a composite index, if my query doesn't use the first index column from composite index, it will not be used.

My question will be:

1. If I declared index like this: INDEX(col1, col2, col3), does it mean that I don't need to create additional index for col2 and col3 (INDEX(col2), INDEX(col3)) separately? From what I've read that if my query doesn't use the col1 but instead used col2, INDEX(col1, col2, col3) will not be used. If I don't have INDEX(col2), then I will have a slow query because there is no index for col2. Is this true?

2. Lately I tried to run mysqlindexcheck as one of the utility command from MySQL workbench. After I ran this command, I found some possible redundant indices. For example I declared INDEX(col1, col2) and I create INDEX(col1), INDEX(col2) again, it showed that I have redundant indices. For this case should I simply remove the INDEX(col1), not INDEX(col2)?
0
Comment
Question by:kisegi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 39691406
1. Yes. Think of an index like the phone book. The phone book is organized by last name, first name. So if you search for someone by the full name, you will find it very quickly but if you search for someone only by the first name you will have to read the entire phone book (if for example you know the first name and phone number and you are trying to find the last name).
2. yes. Since COL1 is the first column in the composite index, you don't need to have another index that only has COL1.
Same goes for more than one column. If you have an index on C1,C2,C3, an index on C1,C2 will be redundant (but an index on C1,C3 will not)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question