Solved

MySQL Index

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Have issues with Query MySQL 9 72
problems with mysql ODBC Connector and vbscript 4 39
myqsl update statement on phpMyAdmin 8 37
simple shopping cart database structure 5 73
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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