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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:25:18+00:00 2026-06-07T13:25:18+00:00

I have this query: SELECT COUNT(*) AS `numrows` FROM (`tbl_A`) JOIN `tbl_B` ON `tbl_A`.`B_id`

  • 0

I have this query:

SELECT 
    COUNT(*) AS `numrows` 
FROM (`tbl_A`) 
JOIN `tbl_B` ON `tbl_A`.`B_id` = `tbl_B`.`id` 
WHERE 
    `tbl_B`.`boolean_value` <> 1;

I added three indexes for tbl_A.B_id, tbl_B.id and tbl_B.boolean_value but mysql still says it doesn’t use indexes (in queries not using indexes log) and it examine whole of tables to retrieve the result.

I need to know what I should do to optimize this query.

EDIT:

Explain output:

id  select_type table  type  possible_keys          key   key_len  ref      rows  Extra 
1    SIMPLE     tbl_B  ALL   PRIMARY,boolean_value  NULL  NULL     NULL     5049  Using where
1    SIMPLE     tbl_A  ref   B_id                   B_id  9        tbl_B.id 9     Using where; Using index
  • 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-07T13:25:21+00:00Added an answer on June 7, 2026 at 1:25 pm

    The explain show us that an index is used to make the join to tbl_B but no index is used to filter tbl_A on the boolean value.

    An index was available but the engine choose not to use it. Why it happen:

    • maybe 5049 rows is not a big deal and the engine saw that using the index to filter something like 10% of the rows using the index would be as fast as doing it without using it.
    • Booleans takes only 3 values: 1, 0 or NULL. So the cardinality of the index will always be very low (3 max). Low cardinality index are usually dropped by the query analyser (which is quite right usually thinking this index won’t help him a lot)

    It would be interesting to see if the query analyser behaves the same way when you have a 50/50 repartition of true and false value for this boolean, or when you have just a few False.

    Now usually boolean fields are useful only on indexes containing multiple keys, so that if your queries use all the fields of the index (in where or order by) the query analyser will trust that index to be really a good tool.

    Note that indexes are slowing down your writes and takes extra-spaces, do not add useless indexes. Using logt-query-not-using-indexes is a good thing, but you should compensate that log information with the slow queries log.If the query is fast it’s not a problem.

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

Sidebar

Related Questions

I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id
i have this simple query : SELECT YEAR(P.DateCreated) ,MONTH(P.DateCreated) ,COUNT(*) AS cnt FROM tbl1,
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have an sql query like this: SELECT IF( (SELECT COUNT(*) FROM `test_table2` WHERE
I have a very simply query like this: SELECT users.id, COUNT(others.id) as c FROM
I have this query in my sql if (select count(*) from sys.columns where object_id
I have this query: SELECT count(member_id) FROM member_favorite_business WHERE business_id=3912 AND member_id=413 When I
So far I have this query SELECT COUNT(f.code_id) as item_count, f.code_desc FROM foo f
I have this query: SELECT foo.*, COUNT(archive.pkey) as archivedCount FROM ( SELECT type, count(active.pkey)

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.