MySQL – Using GROUP_CONCAT for Better Query Performance

MySQLperformancequery-performance

As far as I understand, using or should be avoided as much as possible as rule of thumb in query.

I have two tables having one-to-many relationship.

And I have joined two tables like below.

SELECT A.*, group_concat(B.info separator ','), group_concat(B.info2 separator ',')
FROM A
JOIN B
ON A.id = B.a_id
GROUP BY A.id;

Does using GROUP_CONCAT affect the performance like or does in MySQL? If it does, what would be the efficient way to join those tables?

Any suggestion or advice would be appreciated. Thank you.

Best Answer

So, the GROUP_CONCAT is an additional work for the MySQL involving strings, so you should expect some slow down, but rest assured it will not kill the performance of the MySQL.

To join those tables, you can use those JOINS commands that the MySQL had. Like INNER JOIN, FULL JOIN, etc. Take a look at this https://www.tutorialspoint.com/mysql/mysql-using-joins.htm