Encounter problems:
There is a demand for the project, MySQL is stored in the tree data. Now given a node, all nodes need to remove this node from Mysql database. Using MySQL function.
Function is as follows:
CREATE DEFINER=`root`@`%` FUNCTION `getMemberChildList`(rootId BIGINT) RETURNS mediumtext CHARSET utf8 BEGIN DECLARE str VARCHAR(60000) ; DECLARE cid VARCHAR(60000) ; SET GLOBAL group_concat_max_len=15120; SET SESSION group_concat_max_len=15120; SET str = ''; SET cid =cast(rootId as CHAR); WHILE cid is not null DO SET str= concat(str,',',cid); SELECT group_concat(member_id) INTO cid from mall.ums_member_grade where FIND_IN_SET(parent_id,cid) > 0; END WHILE; RETURN str; END
Start, less data when there is no problem, as the amount of data increases, there have been cases query results are truncated, resulting in the project being given.
solution:
After investigation, it was found group_concat () function has a default value.
About group_concat function:
1, a small amount of data when group_concat no problem, but when the amount of data to play there will be problems
2, group_concat: default length is connectable 1024; If you have set the maximum length, this length will be taken over to the length;
After 3, in the query (select) statements, using group_concat, limit will fail;
group_concat_max_len = 5120
Two ways to solve:
1 , modify the MySQL configuration file:
# Length to be set group_concat_max_len = 5120
2, can also be used to set sql statement:
SET GLOBAL group_concat_max_len=5120; SET SESSION group_concat_max_len=5120;
At last:
Fundamentals still not so strong, it was just a lot of functions in the understanding stage. We should pay close attention to the basics of catching up. Or else having problems can only be a time of trial and error, or ask someone else.
Reference blog:
https://www.cnblogs.com/Steven-shi/p/7106495.html?utm_source=itdadao&utm_medium=referral。