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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:30:31+00:00 2026-05-20T14:30:31+00:00

In a follow up on seperate question / answer : I’m running into the

  • 0

In a follow up on seperate question / answer: I’m running into the issue that from the thousands of records a correct index cant really be used.

I came up with the provided answer some time ago by myself and have it implemented for a while now. Now there are several thousand events in a database (seperate indexes on startdatetime and enddatetime columns) but the mysql interperter cant really use them because of the query itself:

SELECT * FROM table WHERE start_date <= end_of_range
                      AND stop_date  >= start_of_range

Am i correct in thinking this cant easily be optimized further? (having to look trough 40K records just to know which events occur today (or any other range for that matter)

My question: how do the bigger applications solve this issue?

More information after the comments below:
Query:

EXPLAIN SELECT id
FROM event
WHERE startDatetime <= '2011-03-31 23:59:59'
AND endDatetime >= '2011-03-01 00:00:00'

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  event   ALL startDatetime,endDatetime   NULL    NULL    NULL    58331   Using where

In other words: the entire table? Now just to be clear: the query isnt by definition slow, but it doesnt use any index either… ?

  • 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-20T14:30:31+00:00Added an answer on May 20, 2026 at 2:30 pm

    You are probably describing a non problem.

    In your test query mysql is considering to use 2 indexes (and that’s all you can ask of it): it uses none because statistics tell it that table scan will be more efficient compared to index.

    I assume that in your example your test query is not selective enough to trigger the use of the indexes (your test case deals with 1 month range of data – what is the percentage of data that satisfy the condition? according to each of the indexes?).

    The only thing that you can improve is to create a composite index, as I think that in your example mysql’s index merge will not be able to help you. So, do realize that it is a different situation to have

    • 2 indexes, one on startDateTime and on on endDateTime

    compared to

    • 1 composite index on (startDateTime, endDateTime)

    This index should be most useful for events that start within a range and apply additional criteria on endDateTime.

    You might also consider having another index: (endDateTime, startDateTime) (this one should help the most for queries that look for events that end within the range and apply additional criteria on startDateTime).

    You might also read up on table scans and see how forcing an index or modifying some server side variables might effect your performance.

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

Sidebar

Related Questions

No related questions found

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.