Jump to content

Slow SQL query


stubarny

Recommended Posts

Hello,

 

I have the following code which is running very slowly (about 6 full seconds). Currently it is joining on millions of rows and then limiting to 100 rows at the end which seems a waste of resources?

 

Please could you show me how rewrite the query so that does it starts with the "ORDER BY" and "DESC LIMIT" operations and only then does the LEFT OUTER JOIN operation.

 

$query ="SELECT * FROM research_job_searches_results LEFT OUTER JOIN research_job_searches ON research_job_searches.research_job_search_index = research_job_searches_results.research_job_searches_results_research_job_search_index WHERE (research_job_searches.research_job_search_keyphrase_1 = '$mysql_real_escape_string_q_job_category_with_spaces') ORDER BY research_job_searches_results.research_job_searches_results_index DESC LIMIT 0, $sql_number_of_records_limit";

 

Many thanks for your help,

 

Stu

Link to comment
Share on other sites

Please could you show me how rewrite the query so that does it starts with the "ORDER BY" and "DESC LIMIT" operations and only then does the LEFT OUTER JOIN operation.

 

there is not such thing.

 

what the EXPLAIN of that sentence shows?

 

are there indexes defined for both tables?... which ones?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.