Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:01:20+00:00 2026-06-13T13:01:20+00:00

In MySQL, how to build index to speed up this query? SELECT c1, c2

  • 0

In MySQL, how to build index to speed up this query?

SELECT c1, c2 FROM t WHERE c3='foobar';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:01:21+00:00Added an answer on June 13, 2026 at 1:01 pm

    To really give a answer it would be useful to see if you have existing indexes already, but…

    All this is assuming table ‘t’ exists and you need to add an index and you only currently have a single index on your primary key or no indexes at all.

    A covering index for the query will give best performance for your needs, but with any index you sacrifice some insertion speed. How much that sacrifice matters depends on your application’s profile. If you read mostly from the table it won’t matter much. If you only have a few indexes, even a moderate write load won’t matter. Limited storage space for your tables may also come into play… You need to make the final evaluation of the tradeoff and if it is noticable. The good thing is it’s fairly a constant hit. Typically, adding an index doesn’t slow your inserts exponentially, just linearly.

    Regardless, here are your options for best select performance:

    1. If c3 is your primary key for table t, you can’t do anything better in the query to make it faster with an index.
    2. Assuming c1 is your primary key t:

      ALTER TABLE t ADD INDEX covering_index (c3,c2);  
      
    3. If c1 is not your pk (and neither is c2), use this:

      ALTER TABLE t ADD INDEX covering_index (c3,c2,c1);  
      
    4. If c2 is your PK use this:

      ALTER TABLE t ADD INDEX covering_index (c3,c1);  
      
    5. If space on disk or insert speed is an issue, you may choose to do a point index. You’ll sacrifice some performance, but if you’re insert heavy it might the right option:

      ALTER TABLE t ADD INDEX a_point_index (c3);  
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on to build a query in MYSQL by which I can
I pull markers' data from a MYSQL database using SQL and build up an
Currently using MySQL version 5.1.6 This is my first real world build and so
I'm a little unsure of how to build the following query for a MySQL
Using MySQL and PHP; I'm trying to build an index that contains the averages
I have a select field. I must fill with options taken from a mysql
This method takes search a search keyword and parsed mysql query, and rewrites the
I am trying to build mysql-5.0.33 client library with SSL support. For which I
First I wanted to build the DBD::mysql package. That kept failing because whatever make
I'm trying to build out a mysql database design for a project. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.