I did a test here and saw that the query is doing select_full_join, ie this giving select in the entire table p/ generate this query, what I did is the one of the execution plan that Mr. Jorge Campos this referring.
Possible solutions:
1 - Write your query in order not to do the full scan, how? change these left Join.
select
a.id AS aspecto_id,
a.name,
group_concat(ap.name order by ap.name ASC separator '||') AS aplicacao
from aspecto a, aspecto_aplicacao aa, aplicacao ap
where
aa.aspecto_id = a.id and
ap.id = aa.aplicacao_id
group by a.id , a.name
order by a.name;
only that it will fetch full results, without any null, if you need the null results just a scramble there in the query.
Possible solution 2:
Do a stored Process for this query, this will arise gain in queries in 99.9% of cases, but of course, if you keep doing the full scan, maybe this will only remedy for now, and it will cost you memory and processing to continue with good performance.
Conclusion, I suggest you make the necessary adjustments in the query, and if it still gets slow, it sends p/Procedure so you will be using both solutions, but I tell you keep the focus on the way you write the conditions, always use pk, fk or indexes, and how you are doing ordering by "name" can make an index in this attribute ai also p/ win in performance. (index type fulltext)
You can take the execution plan of your query and post here please?
– Jorge Campos
@Jorgecampos did not understand what you meant, will the link to the squema itself serve?
– Marcelo Diniz
Have a look at this link: http://dev.mysql.com/doc/refman/5.5/en/execution-plan-information.html and more specifically: http://dev.mysql.com/docrefman/5.5/en/explain-output.html
– Jorge Campos
I imagine that the link http://sqlfiddle.com/#! 2/06bb38/1/0 has this that you asked for.
– Marcelo Diniz
No, you don’t have to. The execution plan is an analysis that the database makes in its query indicating which indexes and how the engine is processing the data. For example, if you have a NAME field in the table and that name is not using an index means that in a query with a Where in the NAME field there will be a 'full table scan' which means that the engine will check all records to select only those that meet the condition. Look at this execution here. That’s what you need to run on your bank. Then post the result here. http://sqlfiddle.com/#! 2/06bb38/17
– Jorge Campos
From what I understand is what’s at the bottom of the page. Other than that I have nothing. But I’m already changing some parts of this system to eliminate this middle table. Valew
– Marcelo Diniz
http://sqlfiddle.com/#! 2/06bb38/18
– bfavaretto
Use the explain command before the select command for you to see, in the application table and in the table aspect your query is doing full scan, and this will always increase the query return time conforms to the records increase.
– SneepS NinjA