SELECT p.permission_name
FROM tb_user u
JOIN tb_role r ON JSON_CONTAINS(u.role, CAST(r.id AS CHAR))
JOIN tb_permission p ON JSON_CONTAINS(r.permissions, CAST(p.id AS CHAR))
WHERE u.id = 用户ID AND u.status = 1;
先做表连接再查询是否会影响性能,还是说mysql会自动优化
SELECT p.permission_name
FROM (select *from tb_user WHERE id = 用户ID AND status = 1) u
JOIN tb_role r ON JSON_CONTAINS(u.role, CAST(r.id AS CHAR))
JOIN tb_permission p ON JSON_CONTAINS(r.permissions, CAST(p.id AS CHAR));我表述有点问题,想问的是先用子查询生成一个临时表,再进行表连接,在性能上会不会有差别