Evaluate replacing django-mptt with CTE
See original GitHub issueProposed Changes
With the upcoming v3.0 release and the recent loss of maintainership for django-mptt, this is a good time to evaluate replacing our usage of MPTT for hierarchical models with an alternate solution, namely PostgreSQL common table expressions (CTE).
When working on #6087 I came across django-tree-queries, which seems like a neat, lightweight implementation of CTE for Django. We should look into using it, or at replicating its approach within NetBox.
Justification
MPTT has serves us pretty well, however it comes with some limitations, notably the need to consistently rebuild the tree with every change. This imposes some additional overhead around things like bulk updates. MPTT also requires a set of database fields to maintain the tree: tree_id
, level
, lft
(left), and rght
(right).
A CTE-based approach to conveying recursively hierarchies does not impose this requirement, as the hierarchy is built at query time rather than at write time. It remains to be seen, however, what sort of performance penalty this imposes.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
@jeremystretch came across this post via a google search. were there any pitfalls to switching from mptt to cte, if you went through with doing so?
I’m going to tag this to revisit for v3.2.