In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `category` ADD INDEX `category_idx_name_lft` (`name`,`lft`);
SELECT
child.name,
(COUNT(parent.name) - (parentDepth.depth + 1)) AS depth
FROM
category AS child,
category AS parent,
category AS sub_parent,
(SELECT
child.name,
(count(parent.name) - 1) AS depth
FROM
category AS child,
category AS parent
WHERE
child.lft BETWEEN parent.lft AND parent.rgt
AND child.name = 'ELECTRONICS') AS parentDepth
WHERE
child.lft BETWEEN parent.lft AND parent.rgt
AND child.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.name = parentDepth.name
GROUP BY
child.name
HAVING
depth > 0
ORDER BY
child.lft