question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Evaluate replacing django-mptt with CTE

See original GitHub issue

Proposed 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pfcodescommented, Nov 30, 2022

@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?

1reaction
jeremystretchcommented, Oct 11, 2021

I’m going to tag this to revisit for v3.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django-mptt: Utilities for implementing Modified Preorder Tree ...
In this tutorial, we will share a repository of Django-mptt: Utilities for ... for an implementation using recursive Common Table Expressions (CTE).
Read more >
Getting django-mptt to play nice with django-reversion
Well, I found a way to get this to work. Instead of simply deleting the MPTT node, I move it so that it's...
Read more >
Release 3.11.0 Divio AG and contributors
images in different sizes; Django MPTT manages the tree structure of the ... replacing django-treebeard with custom CTE queries (https:.
Read more >
Simple index - piwheels
... kfij odoo-addon-purchase-order-qty-change-no-recompute area-detector-handlers ... sentence-embedding-evaluation-german django-braintree django-columns ...
Read more >
django-mptt - PyPI
Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found