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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:09:56+00:00 2026-05-31T14:09:56+00:00

I have a database I’m working on that has some queries showing up in

  • 0

I have a database I’m working on that has some queries showing up in the slow query log.

There are 2 tables:

table1 is a table of businesses with standard info: name, phone, address, city, state, zip, etc. There is also a field for category. There are millions and millions of rows in this table.

table2 is a table of categories. There are only a couple of hundred rows.

The query in question is below:

# Query_time: 20.446852  Lock_time: 0.000044 Rows_sent: 20  Rows_examined: 11410654
use my_database;
SET timestamp=1331074576;
SELECT table1.id, name, phone, address, city, state, zip 
FROM table1 
INNER JOIN table2 ON table2.label=table1.category 
WHERE state = 'tx' and city = 'San Antonio' 
and category.label LIKE 'Health Care & Medical%' group by table1.id limit 0,20;

An EXTENDED EXPLAIN on the query looks like this:

id  select_type     table   type    possible_keys   key     key_len     ref     rows    filtered    Extra
1   SIMPLE  table1  index   indx_state,indx_city,index_category,cat_keywords    PRIMARY     4   NULL    5465    946.92  Using where
1   SIMPLE  table2  ref     category_label  category_label  602     my_table.table1.category    1   100.00  Using where; Using index

Here’s the problem: This query is taking 20 seconds to run, showing in the slow query log and takes forever to load the html page.

The total records in table1 are over 10 million records, but ‘San Antonio’ only has 70,000 records. The total records matching the query (ignoring the limit) is only a couple of thousand. Indexes are set up on everything and the EXPLAIN appears to reflect this fact.

Why are the rows examined showing 11 million?

I feel this must be part of the reason the query is dragging so much.

Thanks as always….

  • 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-31T14:09:57+00:00Added an answer on May 31, 2026 at 2:09 pm

    I did follow some advice on this post and create an index on city,state. It didn’t help my performance really, but another thing ended up helping. Quite possibly the fix I found would also have been more effective by putting an index on both columns.

    The solution however, was to add the USE INDEX:

    http://dev.mysql.com/doc/refman/5.1/en/index-hints.html

    By defining which index to use, the query time was reduced from 30 seconds to 1.5 seconds.

    I don’t know why it worked, but it did.

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

Sidebar

Related Questions

Suppose I have database table TABLE1 and there is Column COLUMN1 . The variable
I Have Database that contains 4 tables TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more
I have database project in visual studio 2010. It has tables views stored procedures
I have database that has multiple schemas and objects under them. I want to
I have database tables that look like this: A Task can be mapped to
I have database, and in one the tables I need change the values of
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
that my problem: I have database table like that: id (AI) market_id 1 6
I have a Database that contains data about articles , structures and manufacturers .
I have a database that I have created using SQL Server Developer 2008. I

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.