Problem/Motivation

This subquery is generated when you use a relationship to the Root node in a view. It has performance issues resolved by adding an index on depth. EXPLAIN.

SELECT eh_child.id AS eh_child_id, eh_child.revision_id AS eh_child_revision_id, eh_parent.id AS nid
FROM
nested_set_field_parent_node eh_child
INNER JOIN nested_set_field_parent_node eh_parent ON (eh_child.left_pos BETWEEN eh_parent.left_pos AND eh_parent.right_pos) AND eh_parent.depth = 0

Steps to reproduce

* Create a big tree of nodes
* Create a view on the nodes, and add a relationship to Root/Top node.
* Analyse the performance of the resulting query

Proposed resolution

Add an index on depth.

CommentFileSizeAuthor
Screen Shot 2021-11-30 at 3.21.09 pm.png685.18 KBsime
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sime created an issue. See original summary.

larowlan’s picture

I think the schema comes from the nested set library

sime’s picture

Status: Active » Needs review

Sorry i forgot to link back to the PR https://github.com/previousnext/nested-set/pull/28

sime’s picture

These performance issues come through Views only, so I think it's good to have the main ticket here.

nterbogt’s picture

Status: Needs review » Reviewed & tested by the community

I think this is fine. I couldn't see any performance difference extending the key.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

There's no patch here, the issue is against the library