MySQL GROUP BY performance issue -


This is the query that I am performing (without something that is not relevant):

< Pre> select a. *, A B.I.G. from CD.I.D. = B.id_anunciante Join the left otier CID = Aid by B.ID./Rboro Group is connected to "B" from 1 to 5 rows of each row "A"

.

The problem is that there are performance problems in Group B (it does not use 10x or more using Group B). I need to get only one line of each member in "A".

How can I do it fast?

EDIT: I should be able to filter by AID / OR CID. The "valid" member of the result "a" I get is only 1 per line, which means that the rows that match the barriers that do not match the filter should not be returned. In my original query, this will be done like this:

  SELECT a. *, Join a left over from C.id at a.id = b.id_anunciante LEFT OUTER JOIN C ON .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 are all indexes.

  SELECT a. *, (Select from c.id b Join C.id = b.id_rubro WHERE b.id_anunciante = a.id - To determine which line will be selected, add the order ORDER BY LIMIT 1) A < Index from   

b (id_anunciante) is fast to work for it.

Update:

You do not need OUTER JOHNS here

Rewrite your query in this form:

  SELECT a. *, From C.id to b, add b.id_anunciante = a.id in C. BID = BIDRABRO WHERE a.id = 1 Union All SEL ECT One *, From 1 where one is present (select from B to B.id_rubro = c.id WHERE c.id = 1 and b.id_anunciante = a.id)  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -