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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:36:36+00:00 2026-05-27T06:36:36+00:00

Suppose I have simple table like this: ID (PRIMARY) time (INT) stage (TINYINT) other

  • 0

Suppose I have simple table like this:

ID (PRIMARY)
time (INT)
stage (TINYINT)
other fields...

I have to do range search on time while normally selecting stage. With SQL query example:

SELECT * FROM table WHERE time>10000 AND (stage=1 OR stage=3 OR stage=4)

VERY IMPORTANT: There are a lot of rows with stage = 2, let’s say 99% of the table. There are only 5 distinct stage values.

What would be the propper indexing of this table?

  • 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-27T06:36:37+00:00Added an answer on May 27, 2026 at 6:36 am

    It depends on the distribution of the values in the different columns.
    If you have very few possible stage values you will probably have the best performance with either a separate index on time and one on stage or with a combined index time, stage.

    But if you have lots of distinct stage values it might be faster to order the index the other way around: stage, time.

    But using OR makes the stage search more fragmented compared to an AND search. Therefore I would try to have time first in the index.

    The only way to know for sure on your specific set of data is to try and measure, but above three mentioned candidates are my top candidates for indexes.

    Edit
    You might want to create a clustered index on time, possibly time, stage if most of your queries search by time range. This way you minimize lookup in the table once you found the correct rows in the index.
    Beware that this can create a fragmented dataspace if time is strictly increasing when you insert new records.

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

Sidebar

Related Questions

Suppose I have a simple table, like this: Smith | Select Jones | Select
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
Suppose I have a 2 column table like this: | user_id | int(11) |
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
So I have this simple PHP loop that is generating html table data with
Suppose we have a table which holds information about person. Columns like NAME or
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
Suppose I have the following (trivially simple) base class: public class Simple { public
Lets suppose that I have the following simple query var q = from p
I have a simple question. Is there a way ( using reflections I suppose

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.