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

  • Home
  • SEARCH
  • 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 6348277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:23:18+00:00 2026-05-24T21:23:18+00:00

Do you have any idea why this request could be slow (1.7 s on

  • 0

Do you have any idea why this request could be slow (1.7 s on a otherwise fast MySQL server):

SELECT DISTINCT TABLE_A.keyA 
FROM TABLE_A,TABLE_B 
WHERE TABLE_A.keyB= TABLE_B.keyB 
AND TABLE_A.fieldC in (0,2,5,7,8) LIMIT 20;

With this execution plan given by EXPLAIN:

id    select_type table       type    possible_keys         key                   key_len   ref     rows     Extra 
1     SIMPLE      TABLE_B     index   PRIMARY               PRIMARY               8     NULL      10     Using index; Using temporary
1     SIMPLE      TABLE_A     ref     IDX_TABLE_A_KEY_B     IDX_TABLE_A_KEY_B     8     TABLE_B.keyB     25455     Using where

Other elements :

  • the table TABLE_A has 300 000 lines
  • TABLE_A.keyA is the primary key of TABLE_A
  • TABLE_A.keyB is a foreign key towards the primary key keyB of TABLE_B ;
    the table TABLE_B has 10 lines ;
  • 99 % of TABLE_A has fieldC=1 and 1 % of the table has fieldC in (0,2,5,7,8) (that is why this field is not indexed ; EDIT this clause is not problematic because a SELECT with the same clause but no join with TABLE_B is fast) ;
  • it seems to me that it is the JOIN that is guilty, because a simple SELECT on the table is fast ;
  • a join with another table TABLE_C is also very slow ;
  • MySQL version : 5.1.23a-maria-alpha

Do you have any idea?

  • 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-24T21:23:20+00:00Added an answer on May 24, 2026 at 9:23 pm

    99 % of TABLE_A has fieldC=1 and 1 % of the table has fieldC in (0,2,5,7,8) (that is why this field is not indexed

    That would be an excellent reason to index the column.
    Your query only wants less than 1% of the table, so an index would be very selective.

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

Sidebar

Related Questions

Does anyone have any idea what is wrong with this create statement for mysql?
Does any one have any idea why this would be happening? This is some
Does anyone have any idea what this jQuery selector will do? object.find('td:eq(1) div div');
I don't have any idea how to use this class in .net. Anyone wants
does anybody have any idea what's does this mean: onLoad=MyOnLoad? thanks
Any idea why this is popping up :( ? You have an error in
I have searched the Web for this, but with no luck. Any idea? Thanks.
I have a string stack+ovrflow*newyork; i have to split this stack,overflow,newyork any idea??
Does anybody have any idea why I am getting this error when I try
Anyone have any idea how to get the value of Language for Non-Unicode Programs

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.