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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:42:34+00:00 2026-06-15T23:42:34+00:00

I have a couple queries which I created 2 separate indexes for, and I

  • 0

I have a couple queries which I created 2 separate indexes for, and I understand at the moment it doesn’t really need to use them as the table doesn’t contain that many rows; however they aren’t even listed as a possible key when I use an EXPLAIN.

An example query is:

SELECT 
    id,eventname,details,datestart,dateend,smallimage
FROM
    `events`
WHERE
    CAST(dateend AS DATE) >= CURDATE()
AND
    (state='VIC' OR state = 'ALL')
AND
    STATUS = 1
ORDER BY
    datestart ASC;

The alternate query just adds another AND clause before the state, an example being:

 AND eventcat = 15

Now, I have added the following two indexes:

KEY `NewIndex4` (`dateend`,`state`,`status`,`datestart`),
KEY `NewIndex5` (`dateend`,`eventcat`,`state`,`status`,`datestart`)

However, MySQL only shows the below index as a possible key:

KEY `NewIndex1` (`state`,`status`,`frontpage`,`image`)

Are my indexes wrong!? Why does it do this?

  • 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-15T23:42:34+00:00Added an answer on June 15, 2026 at 11:42 pm

    The problem is that you are doing a CAST on the dateend field. When you perform a function on a field it will not use the index for that field. If possible I would recommend converting this field to a DATE data type. And if the first field in an index is not used, the index will be ignored.

    If the field is a DATETIME field, you do not use the CAST function. Simply remove it and leave it as:

    WHERE
        dateend >= CURDATE()
    

    Any datetime value that is for today will match. You do not need to remove the time. For example. 2012-12-14 01:00:00 will be greater than or equal to 2012-12-14 (which the CURDATE function will return).

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

Sidebar

Related Questions

I have a couple of queries which pull data for use in a graph.
i have a couple of linq queries which I wanted to join var IDs
I have a couple of queries that I need to run one to a
I have a couple of applications which do long queries in an OLTP database.
I have a couple of LINQ to SQL queries that I feel take a
I have couple of dozen pieces of data that I need to save and
ok I have couple of .NET classes that I want to use in VBA.
I'm using a LINQ to Entities, and I have a couple of queries for
I have a couple of databases containing simple data which needs to be imported
We have a project using LINQ to SQL, for which I need to rewrite

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.