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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:48:33+00:00 2026-05-23T18:48:33+00:00

I’ve a large database which is being used to record all the events occurring.

  • 0

I’ve a large database which is being used to record all the events occurring. It’s like an ticketing system. Now, since I stored data with different status to know the action on the certain ticket in same column I’ve to use multiple ‘or’ in an statement to know the current status in the ticket.

For example: 1 is for a ticket opened, 2 for acknowledgement, 3 for event closed. Now the query to select all events with 1,2,3 would be:

SELECT * 
  FROM tbl_name 
 WHERE status IN (1, 2, 3) 
   AND event_id = 1;

I’ve created indexes for the id field, and another index event_status for event_id and status field.

Now, when I run EXPLAIN on this query it doesn’t use event_status index rather it uses other existing index like event_status_dept which consist of event_id, status and department.

If I use only two fields in IN i.e 'IN (1,2)' statement, it uses the event_status index otherwise it uses the other index i.e event_status_dept. I don’t know what is wrong with my statement.

  • 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-23T18:48:34+00:00Added an answer on May 23, 2026 at 6:48 pm

    I don’t think anything is wrong with your query.
    The optimizer uses the best index it can find according to the conditions in the query and the statistics it holds.
    An index is not effective if more than a certain percent of the records satisfy the condition.

    Example:
    If the optimizer’s statistics say that only 5% of the events in the table are of the types 1,2, this would be an effective index and it will use it.
    But if 70% of the events are of types 1,2,3, this index is not effective and the optimizer may use another index or no index at all.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I used javascript for loading a picture on my website depending on which small
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.