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

x
?
Solved

MYSQL query not using multiple column index

Posted on 2014-02-14
4
Medium Priority
?
444 Views
Last Modified: 2014-02-14
I have a multiple column index on a mysql table. Let's say the index is (first, second, third). When I run this query

SELECT first, second, third
FROM table

EXPLAIN shows me it is using the index. But if I run the following query

SELECT first, second, third, fourth
FROM table

it is not using the index.

Do I need all the columns that I am selecting to be in the index?
0
Comment
Question by:spectrumcare
[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
  • 3
4 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 900 total points
ID: 39859955
No but there is no reason to use the index to just SELECT fields.  If you use ORDER BY the indexed fields, then it should use the index.
0
 

Author Comment

by:spectrumcare
ID: 39859968
Sorry, I am using  order by FIRST. But for whatever reason, it is not using the index if I try to query a field that is not included in the index. I've even tried forcing the index.
0
 

Author Comment

by:spectrumcare
ID: 39860097
Could the issue be that I have an autonumber column that is forced to have a primary index on it?
0
 

Author Comment

by:spectrumcare
ID: 39860255
I've got it working now. I'll give you the points for answering.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

609 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