MySQL Forums
Forum List  »  Newbie

left join optimization
Posted by: webmaster
Date: September 02, 2004 02:54PM

I am having a strange problem understanding an optimization issue.

I have a query that runs:

SELECT p.id as id
FROM table1 as m
LEFT JOIN table2 AS p ON m.id=p.table1_id
LEFT JOIN table3 as f ON m.id=f.table1_id

This takes upwards of 150 seconds to run on the webserver in my PHP page, and seems to timeout in phpmyadmin.

if I limit this statement to:


SELECT p.id as id
FROM table1 as m
LEFT JOIN table2 AS p ON m.id=p.table1_id

I get a rapid response time like:
Showing rows 0 - 29 (53346 total, Query took 0.0035 sec)

even if I get everything at once, the response is similar to:

Showing rows 0 - 53345 (53346 total, Query took 12.2941 sec)

Initially, table3.table1_id did not have an index set on it, and I added one via phpmyadmin.

table3 only has 400 records and I cannot understand this large jump in execution time.


This is running MySQL 3.23.49.


Does anyone have any suggestions?

As a side note, I have worked with SQL structure quite a bit, but as for mySQL and query optimization I could use some suggestions on good books and reference material.


Thanks everyone



Options: ReplyQuote


Subject
Written By
Posted
left join optimization
September 02, 2004 02:54PM
September 03, 2004 02:20AM
September 05, 2004 05:50PM
September 06, 2004 02:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.