This is the query that I execute (without some links that don't matter):
SELECT a.*, c.id FROM a LEFT OUTER JOIN b ON a.id = b.id_anunciante LEFT OUTER JOIN c ON c.id = b.id_rubro GROUP BY a.id
Each line "a" is associated with 1 to 5 lines in "b".
The problem is that GROUP BY has performance issues (it takes 10 or more times using GROUP BY rather than using it). I need to get only one line of each element in "a".
How can I do it faster?
edit: I need to be able to filter through a.id AND / OR c.id. The result I should get is only 1 line per "valid" member "a", which means lines that meet the constraints. Rows that do not match filters should not be returned. In my initial request, this will be done as follows:
SELECT a.*, c.id FROM a LEFT OUTER JOIN b ON a.id = b.id_anunciante LEFT OUTER JOIN c ON c.id = b.id_rubro WHERE c.id = 1 OR a.id = 1 GROUP BY a.id
a.id, b.id_anunciante, b.id_rubro, c.id - all indexes.
source share