Mysql – Hierarchical queries without CTEs

hierarchyMySQL

I'm new to MySQL. The GetFamilyTree(id) function that Rolando suggested in the Find highest level of a hierarchical field: with vs without CTEs question was great but when the id is greater than 999 it hangs.

Is there a solution that works with larger ids?

Best Answer

There are several things you can do

THING #1

Expand all VARCHAR(1024) to VARCHAR(10240) in all Stored Procedures. This will accommodate longer Family Tree Listings. This is vital because queue_children can grow longer and longer if you have a lopsided tree structure. It also possible that when queue_children was 1024 in length and did not delimit properly, it probably went into some infinite loop trying to terminate properly and never reached the condition when the LENGTH(queue_children) would be 0.

THING #2

GROUP_CONCAT()'s maximum length is limited by group_concat_max_len (default is 1024). Try expanding group_concat_max_len to something ridiculously large (5000000000).

THING #3

Increase your thread_stack, perhaps 512K or 1M. This is needed for Stored Procedures with either recursive operations or, in this case, longer local variables to make room for.