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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:37:18+00:00 2026-05-19T09:37:18+00:00

This query takes about 5 – 10 seconds to run which is unacceptable for

  • 0

This query takes about 5 – 10 seconds to run which is unacceptable for rendering a web page:

SELECT part . * , brand . * 
FROM  `part` ,  `model2year2part` ,  `brand2subcategory2part` ,  `brand2subcategory` ,  `brand` 
WHERE  `model2year2part`.`model2year_id` =  '9521'
AND  `model2year2part`.`part_id` =  `part`.`id` 
AND  `brand2subcategory`.`subcategory_id` =  '1'
AND  `brand2subcategory2part`.`brand2subcategory_id` =  `brand2subcategory`.`id` 
AND  `brand2subcategory2part`.`part_id` =  `part`.`id` 
AND  `brand`.`id` =  `part`.`brand_id` 

ANSIfied:

SELECT p.*, 
       b.* 
  FROM PART p
  JOIN brand b ON b.id = p.brand_id
  JOIN model2year2part m ON m.part_id = p.id
  JOIN brand2subcategory2part b2p ON b2p.part_id = p.id 
  JOIN brand2subcategory b2 ON b2.id = b2.brand2subcategory_id
 WHERE m.model2year_id = '9521'
   AND b2.subcategory_id = '1'

No matter what you feed to model2year2part.model2year_id and brand2subcategory.subcategory_id as input.

EXPLAIN results of the query: https://i.stack.imgur.com/aYtXl.jpg

I have done all possible indexing / unique indexing for all the 5 tables.

  • part: https://i.stack.imgur.com/9z2Mm.jpg
  • model2year2part: https://i.stack.imgur.com/jeLMY.jpg
  • brand2subcategory2part: https://i.stack.imgur.com/ZkI5n.jpg
  • brand2subcategory: https://i.stack.imgur.com/fbygX.jpg
  • brand: https://i.stack.imgur.com/pfO33.jpg

The number of total records in each table:

  • part: 728,534
  • model2year2part: 15,012,595 (is this the culprit?)
  • brand2subcategory2part: 729,030
  • brand2subcategory: 8,111
  • brand: 875

What may be the culprit? Is there any way to optimize this query other than a hardware upgrade?

  • 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-19T09:37:19+00:00Added an answer on May 19, 2026 at 9:37 am

    First, I noticed what looks like a mistake in your fourth Join clause:

    ON b2.id = b2.brand2subcategory_id

    I’m assuming this should be:

    ON b2.id = b2p.brand2subcategory_id

    Second, you might try breaking out the filtering joins from the ones needed for the output. That allows you to do a Explain on just the subquery by itself to see what might be causing the issue:

    Select P.*, B.*
    From Part As P
        Join Brand As B
            On B.Id = P.brand_Id
    Where P.part_id In  (
                            Select M1.part_Id
                            From mode2year2part As M1
                                    Join brand2subcategory2part As B2P
                                        On B2P.part_id = M1.part_id
                                    Join brand2subcategory As B2
                                        On B2.Id = B2P.brand2subcategory_id
                            Where m1.model2year_id = '9521'
                                And B2.subcategory_id = '1'
                            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that takes about 5 minutes to run in Oracle: select
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
This is related to my previous thread: SQL Query takes about 10 - 20
select top 1 col1 from table1 order by CreatedOn desc This query takes 6
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
In SQL server 2005 this query select len(cast('the quick brown fox jumped over the
This query pops up in my slow query logs: SELECT COUNT(*) AS ordersCount, SUM(ItemsPrice
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
This query is related to this one I asked yesterday. I have a radio
this query will just one row as a result myDataContext db = new myDataContext();

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.