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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:41:14+00:00 2026-05-30T01:41:14+00:00

In other words, let’s say this is my table: tbl_rel id groupID created Index

  • 0

In other words, let’s say this is my table:

tbl_rel

  • id
  • groupID
  • created

Index 1 on id

Index 2 on groupID

OR

Index 1 on id and groupID

I want to know if those are equivalent for any query involving the keys (see the queries below):

SELECT * FROM tbl_rel WHERE id = 1

Does this use indexes in either of the index cases above?

SELECT * FROM tbl_rel WHERE id = 1 AND groupID = 5

Does this use indexes in either of the index cases above?

Thanks all, it’s been hard to find an answer on this. I hope my question makes sense.

  • 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-05-30T01:41:16+00:00Added an answer on May 30, 2026 at 1:41 am

    Typically, btree indexes typically work left to right against the list of columns that make up that index to determine if they can be used by a query; so an index on id and groupid is an index first on the id, and then on the groupid. If the query doesn’t use id in a query, then it won’t be used because it can’t work against the first column defined in the index.

    SELECT * FROM tbl_rel WHERE id = 1 
    

    Will use an index on id; or an index on id and groupid (if there isn’t any index just on the id) even though groupid is included in the index but isn’t part of the query; but won’t even look at any index on just groupid.

    SELECT * FROM tbl_rel WHERE id = 1 AND groupID = 5 
    

    Will use an index on id and groupid if it exists (because both id and groupid are part of the WHERE clause); or an index on id (if there isn’t any index on id and groupid); or will use an index on groupid if there is no index on id, and no index on id and groupid.

    SELECT * FROM tbl_rel WHERE groupID = 5 
    

    Will not use an index on id; or an index on id and groupid, because id is not part of the WHERE clause; but will use an index on groupid if it exists.

    If there are several indexes that can be used for the query, then the database engine will normall try to identify the most appropriate index to use based on a set of “efficiency” rules… a reasonably good description is given in this post

    MySQL supports either btree or hash indexes. It’s worthwhile to read up on the differences between the two, and the situations where it is appropriate to use the different types. I don’t believe MySQL supports binary indexes (even in its latest versions)

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

Sidebar

Related Questions

I have a list of n words (let's say 26). Now I want to
In other words, let's say I have a bunch of divs and they're all
Let's say I have a table which can contains data like this: id name
In other words, let's say there is a form to ask how many brother
Is releasing objects on a programs exit/close needed? In other words, let us say
Let's say I have a table like this: name | score_a | score_b -----+---------+--------
Or, in other words, how to make this work: function foo(){} //do something that
in other words, suppose I want to send data, like text, programmatically from a
Let's say I have this grammar: A: ε | B 'a' B: ε |
Let's say I have this graph always a full graph one start node -

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.