with recursive test_paths(id, path) as
(
select id, name
from test
where parent_id is null # 溢出条件
union all
select tp.id, concat(tp.path, '/', t.name)
from test_paths tp join test t on tp.id = t.parent_id # 关联条件
)
select * from test_paths; # 可以只查询需要的字段