?
Solved

MYSQL query not using multiple column index

Posted on 2014-02-14
4
Medium Priority
?
440 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…

752 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