Skip to content
Advertisement

Optimize GROUP_CONCAT in SQL on MySQL

Is there a way to get the following SQL optimized so it would run faster?

I encountered the bottleneck are the GROUP_CONCAT’s but I couldn’t find a way by using an alternative or optimizing the query so it would run faster. At the moment the query needs about 3.2s on 2700 entries (mysql database 5.1.73, mysqli). All tables have indices set on the important columns.

So after implementing some LEFT JOINS my query looks the following:

Advertisement

Answer

I think you can avoid the subqueries (that are done for every row) by grouping the artName values first and then joining them:

old query:

Should be something like this:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement