Solved

Question regarding mysql index

Posted on 2014-02-14
2
481 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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