Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
Screen Shot 2021-11-30 at 3.21.09 pm.png | 685.18 KB | sime |
Comments
Comment #2
larowlanI think the schema comes from the nested set library
Comment #3
simeSorry i forgot to link back to the PR https://github.com/previousnext/nested-set/pull/28
Comment #4
simeThese performance issues come through Views only, so I think it's good to have the main ticket here.
Comment #5
nterbogt CreditAttribution: nterbogt as a volunteer commentedI think this is fine. I couldn't see any performance difference extending the key.
Comment #6
larowlanThere's no patch here, the issue is against the library