Solved

MYSQL query not using multiple column index

Posted on 2014-02-14
4
426 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
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I've got it working now. I'll give you the points for answering.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 …
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now