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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:32:36+00:00 2026-05-18T11:32:36+00:00

I’m trying to optimize this mysql query using EXPLAIN. Can somebody please help me

  • 0

I’m trying to optimize this mysql query using EXPLAIN. Can somebody please help me out over here?

EXPLAIN SELECT * FROM keyword
WHERE keyword LIKE "panasonic%"
AND keyword != "panasonic"
AND price < 3230 AND price > 3370
ORDER BY price DESC
LIMIT 99

Basically I want to find out the keywords which start with “some keyword” but don’t exactly match it, and whose price is not in some particular range. And oh, I have to get them in descending order of price (which is causing the problem here).

Explain Output:

id: 1
select_type: SIMPLE
table: keyword
type: range
possible_keys: PRIMARY, keyword_price, price_keyword
key: keyword_price
key_len: 765
ref: NULL
rows: 24
Extra: Using where; Using filesort

Indexes
Key_name : column_names

PRIMARY: keyword
keyword_price: keyword, price
price_keyword: price, keyword

Now if I give the hint to use index, and change the query to

EXPLAIN SELECT * FROM keyword USE INDEX (price_keyword)
WHERE keyword LIKE "panasonic%"
AND keyword != "panasonic"
AND price < 3230 AND price > 3370
ORDER BY price DESC
LIMIT 99

Explain Output changes to

id: 1
select_type: SIMPLE
table: keyword
type: index
possible_keys: price_keyword
key: price_keyword
key_len: 790
ref: NULL
rows: 1043044 (WHAT THE ????)
Extra: Using where

The explain output shows the number of rows has increased exponentially but the “Using filesort” has gone.

Which query is better in this case? Can that “rows examined” column be deceptive?

Regards

  • 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-18T11:32:36+00:00Added an answer on May 18, 2026 at 11:32 am

    Which query is better in this case?

    In this specific case, I expect the first query to be better.

    Option A) Pull the ~24 rows that start with the indicated keyword and sorting them by price (note that filesort is an algorithm, and doesn’t indicate that the sort is done on disk),

    Option B) Pull ~1 million rows in order of price and checking them all to see if they meet the keyword constraint (until you get 99 of them).

    Having said that, if your keyword was 's', or your data is not uniform, the better option could reverse. At any rate, I imagine that for most applications, Option A) is the winner.

    Can that “rows examined” column be deceptive?

    Definitely. The rows examined in the EXPLAIN is an estimate. Best to check the output of something like

    SHOW SESSION STATUS LIKE 'handler_%'

    to see how many rows you are actually pulling.

    • 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.