Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Index

Posted on 2013-12-02
1
Medium Priority
?
503 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

704 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