MySQL Forums :: Performance :: Very slow query when too many joins


Advanced Search

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 742 As Os 06/05/2016 09:17AM
Re: Very slow query when too many joins 411 As Os 06/05/2016 09:27AM
Re: Very slow query when too many joins 364 Peter Brawley 06/05/2016 10:14AM
Re: Very slow query when too many joins 344 As Os 06/05/2016 10:48AM
Re: Very slow query when too many joins 343 Peter Brawley 06/05/2016 10:56AM
Re: Very slow query when too many joins 316 As Os 06/05/2016 03:33PM
Re: Very slow query when too many joins 341 Peter Brawley 06/05/2016 03:41PM
Re: Very slow query when too many joins 364 Rick James 06/05/2016 05:36PM
Re: Very slow query when too many joins 316 As Os 06/06/2016 02:23AM
Re: Very slow query when too many joins 338 As Os 06/06/2016 03:33AM
Re: Very slow query when too many joins 337 As Os 06/06/2016 08:36AM
Re: Very slow query when too many joins 295 Peter Brawley 06/06/2016 08:52AM
Re: Very slow query when too many joins 354 As Os 06/06/2016 09:02AM
Re: Very slow query when too many joins 309 Peter Brawley 06/06/2016 11:16AM
Re: Very slow query when too many joins 353 Peter Brawley 06/06/2016 08:29AM
Re: Very slow query when too many joins 334 As Os 06/06/2016 11:30AM
Re: Very slow query when too many joins 343 Peter Brawley 06/06/2016 12:08PM
Re: Very slow query when too many joins 327 As Os 06/06/2016 02:11PM
Re: Very slow query when too many joins 363 Rick James 06/07/2016 03:40PM
Re: Very slow query when too many joins 272 james wang 07/20/2016 05:34AM
Re: Very slow query when too many joins 285 Rick James 07/20/2016 09:37AM
Re: Very slow query when too many joins 299 james wang 07/21/2016 04:43AM
Re: Very slow query when too many joins 266 Rick James 07/22/2016 10:59PM


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.