mybatis查询树形菜单sql效率低

<resultMap id="menuQuery" type="com.wlpy.common.entity.Menu">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="parentId" jdbcType="VARCHAR" property="parentId" />
    <result column="menuName" jdbcType="VARCHAR" property="menuName" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="perms" jdbcType="VARCHAR" property="perms" />
    <collection property="menuList" select="lowMenu" column="id" ofType="com.wlpy.common.entity.Menu">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="parentId" jdbcType="VARCHAR" property="parentId" />
        <result column="menuName" jdbcType="VARCHAR" property="menuName" />
        <result column="url" jdbcType="VARCHAR" property="url" />
        <result column="type" jdbcType="VARCHAR" property="type" />
        <result column="perms" jdbcType="VARCHAR" property="perms" />
    </collection>
</resultMap>

<select id="findAllMenu" parameterType="java.util.Map" resultMap="menuQuery">
    SELECT
    m.id,
    m.parent_id AS parentId,
    m.menu_name AS menuName,
    m.url,
    m.type,
    m.perms
    FROM
    menu AS m
    WHERE
    m.available = 1
    AND m.parent_id = 0
</select>

<select id="lowMenu" parameterType="java.util.Map" resultMap="menuQuery">
      SELECT
      m.id,
      m.parent_id AS parentId,
      m.menu_name AS menuName,
      m.url,
      m.type,
      m.perms
      FROM
      menu AS m
      WHERE
      m.available = 1
      AND m.parent_id = #{id} 父级ID
</select>

我看sql也不复杂,是查询慢吗,看下索引使用情况。
执行计划:explain sql语句

可以换一种方法设计表,把主键设置为varchar类型,第一级用2位(如11),第二级4位(如1101),依次类推,查询的时候模糊查询条件实现。

sql没什么问题,也没有优化的地方了,输出一下执行sql查询需要多久,如过是sql问题影响时间只能添加索引了。
你的树有几层 为何重复调用menuQuery

楼上那个表设计你可以参考下,插叙效率起飞,直接从递归变成like

你可以看看这个,【子父级关系的系统设计】
子父级关系的系统设计 - 技术交流 - SpringBoot中文社区 子父级关系的系统设计 群里屡次的遇到探讨过这个问题。我想写一下,我在在子级别的系统中遇到的一些问题。以及处理方案。 一个场景 一个用户系统,用户可以自己注册,也可以通过别人的邀请注册。如果是通过别人邀请注册,那么注册用户就作为别人的一… https://springboot.io/t/topic/656