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 8819239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:18:23+00:00 2026-06-14T05:18:23+00:00

Currently I am creating indexes as I need them for a particular sql query.

  • 0

Currently I am creating indexes as I need them for a particular sql query.
But they are starting to overlap each other.

Is there any rule to define them effectively?

For example:

  • If I have two indexes for column1 and column2, does the composite index by column1, column2 improve select by both columns?
  • What is there any difference between an index by column1 and column2 over index by column2 and column1?
  • 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-14T05:18:25+00:00Added an answer on June 14, 2026 at 5:18 am

    Q: If I have two indexes for column1 and column2, does the composite index by column1, column2 improve select by both columns?

    Yes then composite Index is better.

    From Mysql

    “mysql> SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2;

    If a multiple-column index exists on col1 and col2, the appropriate rows can be fetched directly. If separate single-column indexes exist on col1 and col2, the optimizer attempts to use the Index Merge optimization (see Section 8.3.1.4, “Index Merge Optimization”), or attempts to find the most restrictive index by deciding which index excludes more rows and using that index to fetch the rows.”

    Q: What is there any difference between an index by column1 and column2 over index by column2 and column1?

    Yes it will make difference. It depends on how you form your query.

    From the Mysql docs:

    Example If you have index like below on table :

    INDEX name (last_name,first_name)

    “The name index is an index over the last_name and first_name columns. The index can be used for lookups in queries that specify values in a known range for combinations of last_name and first_name values. It can also be used for queries that specify just a last_name value because that column is a leftmost prefix of the index.”

    You will get advantage of index for below query:

    SELECT * FROM test WHERE last_name=’Widenius’;

    But index is not used for lookups in the following queries:

    SELECT * FROM test WHERE first_name=’Michael’;

    Hope this will help !!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to optimize a SQL Query by creating indexes to have the best
I'm currently creating a iOS 5 iPad app where there will be heavy network
(I know there's some close duplicates out there, but none of them were able
Currently creating a VOIP application for Android and I was wondering is there any
For a 2d top down tiles-based game I am currently creating, I need to
I'm currently creating an application for a customer that will allow them to automatically
im currently creating a graph for an app, using coreplot and have a problem
I am currently creating an application for compiling multiple java projects in one go
I'm currently creating a payment SDK for android, as such I want to send
I'm currently creating an iPhone app (Xcode 4.3.1, IOS 5) that could use Bluetooth

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.