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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:08:19+00:00 2026-06-06T20:08:19+00:00

Suppose I have a table events {id, userid, create_time, country, type, page, browser} I

  • 0

Suppose I have a table events {id, userid, create_time, country, type, page, browser}

I have indexes on all the columns.
If I do a query

select count(*) from events where id > ? and id < ? and userid>? and userid<? and create_time>? and create_time<? and browser=? and country=? and page=?

I have following questions:

  1. Will all my indices be used? If not, How to achieve that.
  2. Will it be better to have multiple column index?
  3. If I have a multiple column index on (id,userid,page), will it be used? If so will other indexes will also be used?
  4. If I have a multiple column index including all the columns but my query does not include all columns, then will that index be used?
  • 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-06T20:08:20+00:00Added an answer on June 6, 2026 at 8:08 pm

    Q: Will all my indices be used?

    A: Very unlikely. It’s more likely that MySQL will choose a single index, one that has the highest selectivity (eliminates the most rows), and then access the data pages from the index reference.

    It’s possible that MySQL would do an index merge operation, but that would be the rare exception. You’d really need to do an EXPLAIN to see if that’s happening, and do some work to develop a case in which MySQL sees that as the optimal plan. (Someone has likely done the work, and has such a test case.)

    Q: If not, How to achieve that.

    A: You don’t want to achieve that. What you want MySQL to do is generate an optimal plan. An index merge plan is most likely NOT the optimal plan for your query. Such an operation requires MySQL to “match” all of those indexes together, and that’s a lot of heavy lifting to do.

    Q: Will it be better to have multiple column index?

    A: Yes. The best possible index for your particular query is a covering index, one that includes ALL the columns referenced in your query. Typically, you would want the column with the most selectivity and highest cardinality first. Your query appears to be doing range scans rather than equality tests, you’d want the column with the narrowest range of values in your predicate, compared to the entire set of values for the column, first in the index.

    Q: If I have a multiple column index on (id,userid,page), will it be used?

    A: Possibly. You have range scan predicates on two of the leading columns in that index, so it definitely looks like a candidate. If those are the only columns referenced in your query, then it makes it much more likely that index will be used.

    There seems to be a malformed reference to create_time in your query text. It looks like you meant to have some sort of predicate on that column. If that’s the case, then an index on (id, userid, create_time) would be a better candidate, because then the query could be satisfied from the index without referencing the data pages.

    On the other hand, a full scan of the data pages might be a more optimal plan.

    Q: If so will other indexes will also be used?

    A: Very unlikely. The idea that MySQL will use “multiple” indexes on a table is a common misconception about how MySQL uses indexes. It’s not out of the question, but it’s very unlikely that an INDEX MERGE operation is the optimal plan.

    Q: If I have a multiple column index including all the columns but my query does not include all columns, then will that index be used?

    A: It’s possible. If MySQL determines using that index is the optimal plan, then it will be used. The more likely index to be used (if available) would be a covering index that contains only the columns referenced in your query.

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

Sidebar

Related Questions

Suppose we have a table Users that has only one column UserId which is
Suppose I have a table TABLE with two columns COL_1 and COL_2 . I
Let's assume we have MySQL table events from which we'll select a data. Now
Suppose I have table with two columns. I can center this table by using:
Suppose I have table A with a field that can be either 1 or
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose I have a table Item (Id int Primary Key, Number INT) having records
Suppose I have this table parent | child 1 2 1 3 2 4
Suppose I have a table, the first column is an identity. I thought that
Suppose I have this table: id | name | city ------------------ 1 | n1

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.