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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:06:15+00:00 2026-05-19T06:06:15+00:00

Trying to run the following query on a mysql table that has over 3

  • 0

Trying to run the following query on a mysql table that has over 3 million rows. Its very slow to the point it pretty much hangs until the script times out. Below is the query and the explain from that query, any suggestions?

SELECT SQL_CALC_FOUND_ROWS
listing_track.listingid,
listing_track.commid,
listing.listingname,
listing_package.packagename,
listing.active,
community.commname,
SUM( listing_track.impression ) AS listing_impressions,
SUM( listing_track.view ) AS listing_views,
SUM( listing_track.phone ) AS listing_phones,
SUM( listing_track.forward ) AS listing_forward,
SUM( listing_track.coupon ) AS listing_coupons,
SUM( listing_track.email ) AS listing_emails
FROM listing_track
INNER JOIN listing ON listing_track.listingid = listing.id
INNER JOIN community ON listing_track.commid = community.id
INNER JOIN listing_package ON listing.packageid = listing_package.id
WHERE listing_track.commid =2
GROUP BY listing_track.commid, listing_track.listingid, listing_track.trackip
LIMIT 0 , 25

Here is the explain:
alt text

  • 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-19T06:06:16+00:00Added an answer on May 19, 2026 at 6:06 am

    The problem here is that the LIMIT is applied at the end of the query, after all the costly table scans are complete. The cost is not from returning lots of rows, but instead from scanning lots of rows.

    The easiest way to speed up queries like this is with a covering index. This will allow you to scan through the rows you want, but require fewer bytes of I/O per row (since you’re only scanning a portion of each row’s data, not the entire row). Furthermore, if your index is sorted in the same way that your query is, you can avoid the cost of a sort and can scan vastly fewer rows.

    Your index should have these columns below. The first three columns must be in the same order as your GROUP BY– this allows your GROUP BY and WHERE to be vastly cheaper to execute. The second line allows the index to “cover” the query, which means that MySQL will be able to satisfy the entire listing_track part of the query from the index alone:

    CREATE INDEX ix_listing_track_covering ON listing_track (
        commid, listingid, trackip, 
        listing_impression, listing_view, listing_phone, listing_forward, listing_coupon, listing_email);
    

    With this index in place, you should be able to run the exact same query but see vastly better performance.

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

Sidebar

Related Questions

I'm trying to run the following query using phpMyAdmin: UPDATE TABLE x SET `number`
I'm trying to run the following MySQL query: SELECT * FROM user u JOIN
I'm trying to run the following MySQL query: mysql> SELECT num.value, agro.mean, agro.dev ->
I'm trying to run the following query, and I'm having trouble with the wildcard.
I'm recieving the following error on trying to run an append query in access.
I am trying to pull data using an mysql query that requires that I
I am trying to run the following query, but am getting a sql syntax
I'm trying to run a simple query with an ORM that is built on
Hello I am trying to test the following mySql query within phpmyadmin before using
I was trying to run the following query UPDATE blog_post SET `thumbnail_present`=0, `thumbnail_size`=0, `thumbnail_data`=''

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.