Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Question regarding mysql index

Posted on 2014-02-14
2
Medium Priority
?
484 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 2000 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 44

Expert Comment

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 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