Solved

Question regarding mysql index

Posted on 2014-02-14
2
479 Views
Last Modified: 2014-02-14
Hello,

I have a table with the following structure:

id (int, auto increment), text1, lang

I also have created an index on text1,lang.

When I run the following query:

select * from mytable where name like 'cre%' I get 2500 records back.

and when I run

select * from mytable where name like 'cre%' and lang='en' I get 25 records back.

However if I run:
explain select * from mytable where name like 'cre%' and lang='en' I see that 2500 records are scanned.

Is that correct, since I have created the index on those two columns? My assumption was that only 25 records should be scanned.

Thanks a lot!
0
Comment
Question by:infodigger
[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
2 Comments
 
LVL 19

Accepted Solution

by:
regmigrant earned 500 total points
ID: 39858935
Are there separate indexes on Text1 and lang or a single multicolumn index?

 As I understand it a multi-column index will only be used if the where clause is against the left most column of the index - in your example the Lang part is not available to the optimizer if its the second column of the index - you may get a better result with separate indices on each.

This link shows some useful hints :
https://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39858957
What output do you get from your EXPLAIN statement
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

697 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