Solved

MySQL Index

Posted on 2013-12-02
1
478 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Creating and Managing Databases with phpMyAdmin in cPanel.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now