4

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?

Bikram DG
  • 41
  • 2

2 Answers2

1

When I changed the part "FORMAT(queue,0)" into simply "queue", GetFamilyTree worked for IDs over 999. This is because FORMAT(9999,0) = "9,999" in my system at least.

I also added a unique index under id and a non-unique index under parent_id and the code works well on a dataset with 230k rows. I also changed VARCHAR(1024) to TEXT.

MDCCL
  • 8,530
  • 3
  • 32
  • 63
jpenston
  • 11
  • 1
1

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.

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536