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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:13:45+00:00 2026-06-09T21:13:45+00:00

You will notice the primary query is NOT using an index on school_id, when

  • 0

You will notice the primary query is NOT using an index on school_id, when there is an index. If I remove the subquery and use a hardcoded list, it will use an index.

mysql> explain SELECT year, race, CONCAT(percent,'%') as percent
    -> FROM school_data_race_ethnicity as school_data_race_ethnicity_outer
    -> WHERE school_id IN(
    -> SELECT field_school_id_value 
    -> FROM field_data_field_school_id 
    -> WHERE entity_id IN (SELECT entity_id 
    -> FROM field_data_field_district 
    -> WHERE field_district_nid = 
    -> (SELECT entity_id FROM field_data_field_district_id
    -> WHERE `field_district_id_value` = 26130106 LIMIT 1))
    -> ) ORDER BY year DESC, race;
+----+--------------------+----------------------------------+----------------+------------------------------+-----------+---------+------+-------+-----------------------------+
| id | select_type        | table                            | type           | possible_keys                | key       | key_len | ref  | rows  | Extra                       |
+----+--------------------+----------------------------------+----------------+------------------------------+-----------+---------+------+-------+-----------------------------+
|  1 | PRIMARY            | school_data_race_ethnicity_outer | ALL            | NULL                         | NULL      | NULL    | NULL | 97116 | Using where; Using filesort |
|  2 | DEPENDENT SUBQUERY | field_data_field_school_id       | ALL            | NULL                         | NULL      | NULL    | NULL |  5325 | Using where                 |
|  3 | DEPENDENT SUBQUERY | field_data_field_district        | index_subquery | entity_id,field_district_nid | entity_id | 4       | func |     1 | Using where                 |
|  4 | SUBQUERY           | field_data_field_district_id     | ALL            | NULL                         | NULL      | NULL    | NULL |   685 | Using where                 |
+----+--------------------+----------------------------------+----------------+------------------------------+-----------+---------+------+-------+-----------------------------+
4 rows in set (0.00 sec)

mysql> describe school_data_race_ethnicity
    -> ;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| school_id | varchar(255) | NO   | MUL | NULL    |                |
| year      | int(11)      | NO   | MUL | NULL    |                |
| race      | varchar(255) | NO   |     | NULL    |                |
| percent   | decimal(5,2) | NO   |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> 
  • 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-09T21:13:47+00:00Added an answer on June 9, 2026 at 9:13 pm

    use INNER JOIN instead of subquery with IN clause:

    explain SELECT year, race, CONCAT(percent,'%') as percent
    FROM school_data_race_ethnicity a
        INNER JOIN(
        SELECT field_school_id_value
        FROM field_data_field_school_id b
             INNER JOIN (SELECT entity_id
                         FROM field_data_field_district
                         WHERE field_district_nid =
                        (SELECT entity_id FROM field_data_field_district_id
                        WHERE `field_district_id_value` = 26130106 LIMIT 1)) c
             ON b. entity_id = c.entity_id
         ) d
        ON a.school_id = d.field_school_id_value
    ORDER BY year DESC, race;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

THere is a oracle query that I am trying to recreate using OpenJPA. I
I'm experiencing a problem with MySQL's GROUP_CONCAT function. I will illustrate my problem using
I have a web.py project with a notice module - the system will notice
Example: http://soundcloud.com/torsmusic/emancipator-siren-tor-remix You will notice that if you click play, the favicon dynamically displays
I have the following XML code. You will notice the tag Description is repeated,
I have the following connection string, and you will notice Provider's.Tests, notice the single
I notice on bad quality websites with ads a piece of the site will
Notice while on Google's homepage, with no focus on any element, pressing BACKSPACE will
I've noticed that many operations on lists that modify the list's contents will return
I'm using LinqToSql to query a small, simple SQL Server CE database. I've noticed

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.