[root@moodle ~]# mysqldumpslow -s r -t 1 /var/lib/mysql/mysql.slow.log SELECT ctx.path, rc.capability, rc.permission FROM context ctx JOIN role_capabilities rc ON rc.contextid = ctx.id LEFT JOIN context cctx ON (cctx.contextlevel = 50 AND ctx.path LIKE CONCAT(cctx.path, '/%')) WHERE rc.roleid = '6' AND cctx.id IS NULL;