MySQL Forums
Forum List  »  Performance

Very slow query when too many joins
Posted by: As Os
Date: June 05, 2016 09:17AM

In my db I have 2 tables:
1.table 'fields_values' with fields: id,field_id(FK to fields table), ads_id(FK to ads table), value.
2.table 'ads' with fields: id,field_id (which actually is in a json format field).

My query is like this:



SELECT DISTINCT a.*,b.value
FROM ads as a

LEFT JOIN fields_values AS b
ON (`b`.`ads_id` = `a`.`id` AND `b`.field_id="183")

LEFT JOIN fields_values AS c
ON (`c`.`ads_id` = `a`.`id` AND `c`.field_id="183")

Up to 25 joins, it's ok.
But on 26, 27 joins it slows down.
On more joins, it slows down dramatically.

How can I fix this?
(I tried to post the EXPLAIN from phpmyadmin but I failed)

Options: ReplyQuote


Subject
Views
Written By
Posted
Very slow query when too many joins
4682
June 05, 2016 09:17AM
1770
June 05, 2016 09:27AM
1395
June 05, 2016 10:48AM
1453
June 05, 2016 03:33PM
1220
June 06, 2016 02:23AM
1184
June 06, 2016 03:33AM
1049
June 06, 2016 08:36AM
1244
June 06, 2016 09:02AM
1124
June 06, 2016 11:30AM
1152
June 06, 2016 02:11PM


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.