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

The Archive Base Latest Questions

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

So I was on tech support with our host provider about slow database response

  • 0

So I was on tech support with our host provider about slow database response that I’d been experiencing on a crucial search page and after some investigating he told me that the query that I’m using was checking 67,998,176 rows. Now the largest table that appears on this query has at most 116 rows and the rest of them have an average of 25 rows each.

Here’s the SQL of my query

 SELECT COUNT( DISTINCT `A`.`id`) AS `total_num_resource_rows`
 FROM `admin_site_resources` AS `A`
 LEFT JOIN `admin_site_organization_resource` AS `B` ON `B`.`res_id`=`A`.`id`
 LEFT JOIN `admin_site_organizations` AS `C` ON `B`.`org_id`=`C`.`id`
 LEFT JOIN `admin_site_resource_res_topic` AS `D` ON `D`.`resource_id`=`A`.`id` 
 LEFT JOIN `admin_site_resource_topics` AS `E` ON `E`.`id`=`D`.`res_topic_id`
 LEFT JOIN `admin_site_resource_audience` AS `F` ON `F`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_audiences` AS `G` ON `G`.`id`=`F`.`audience_id`
 LEFT JOIN `admin_site_resource_curriculum_topic` AS `H` ON `H`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_curriculum_topics` AS `I` ON `I`.`id`=`H`.`curriculum_topic_id`
 LEFT JOIN `admin_site_resource_curriculum_grade` AS `J` ON `J`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_curriculum_grades` AS `K` ON `K`.`id`=`J`.`curriculum_grade_id`
 LEFT JOIN `admin_site_resource_curriculum_subject` AS `L` ON `L`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_curriculum_subjects` AS `M` ON `M`.`id`=`L`.`curriculum_subject_id` 
 LEFT JOIN `admin_site_resource_res_type` AS `N` ON `N`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_resource_types` AS `O` ON `O`.`id`=`N`.`res_type_id` 
 LEFT JOIN `admin_site_resource_res_area_location` AS `P` ON `P`.`resource_id`=`A`.`id`
 LEFT JOIN `admin_site_resource_area_locations` AS `Q` ON `Q`.`id`=`P`.`res_area_location_id` 

 WHERE `A`.`post_status`='approved' AND (
`A`.`resource_name` LIKE '%alpha%'
OR `A`.`aliases` LIKE '%alpha%' 
OR `A`.`short_desc` LIKE '%alpha%' 
OR `A`.`resource_url` LIKE '%alpha%' 
OR `A`.`other_resource_type` LIKE '%alpha%' 
OR `C`.`org_name` LIKE '%alpha%' 
OR `E`.`topic_label` LIKE '%alpha%' 
OR `G`.`audience_label` LIKE '%alpha%' 
OR `I`.`topic_label` LIKE '%alpha%' 
OR `K`.`grade_label` LIKE '%alpha%' 
OR `M`.`subject_label` LIKE '%alpha%' 
OR `O`.`type_label` LIKE '%alpha%' 
OR `Q`.`area_location_label` LIKE '%alpha%' );

Yes, I understand this query is pretty long and ugly but I guess it’s a result of all the normalization that had to be done for it. What I can’t understand is how a few rows suddenly turned to almost 68 million rows. Are the LEFT JOINS to blame for this?

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

    Rewrite it as:

     SELECT COUNT(*) AS `total_num_resource_rows`
     FROM `admin_site_resources` AS `A`
     WHERE `A`.`post_status`='approved' AND
       ( `A`.`resource_name` LIKE '%alpha%'
      OR `A`.`aliases` LIKE '%alpha%' 
      OR `A`.`short_desc` LIKE '%alpha%' 
      OR `A`.`resource_url` LIKE '%alpha%' 
      OR `A`.`other_resource_type` LIKE '%alpha%' 
      OR EXISTS ( SELECT * 
                  FROM `admin_site_organization_resource` AS `B` 
                    JOIN `admin_site_organizations` AS `C`
                      ON `B`.`org_id`=`C`.`id`
                  WHERE `B`.`res_id`=`A`.`id`
                    AND `C`.`org_name` LIKE '%alpha%' 
                )
      OR EXISTS ( 
                 ...
                )
      OR EXISTS ( 
                 ...
                )
      ...
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a tech support website/database at work that we use to record our
I read some articles about Comet tech. All of them mentioned that the long-life
I have tried contacting tech support with this question, but it has been over
Assumption: live/production web app suppresses errors being shown to end-users. Suppose your tech support
I have a PHP site with a mySQL database that I'm working on. I'm
I am re-writing an app that sits over a legacy database. I'm using NHibernate
I was speaking with Rackspace tech support today looking for a simple solution to
Our organization provides a variety of services to our clients (e.g., web hosting, tech
I'm the primary tech guy for an e-commerce site that gets 700k pageviews/mo. and
I just had a very long tech support call because a customer didn't have

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.