Evaluate replacing MPTT with PostgreSQL ltree #7466

Closed
opened 2025-12-29 20:23:44 +01:00 by adam · 1 comment
Owner

Originally created by @arthanson on GitHub (Jan 6, 2023).

Proposed Changes

The recent loss of maintainership for django-mptt, has precipitated discussion on evaluating a replacement for our usage of MPTT for hierarchical models with an alternate solution. CTE has been discussed, see #6587

Author of django-tree-queries lists his reasons here: https://406.ch/writing/django-tree-queries/. He notes potential issues he doesn't like with PostgreSQL ltree, however this is probably still a viable alternative. See https://github.com/mariocesar/django-ltree and https://github.com/peopledoc/django-ltree-demo (the ltree-demo could just be pulled into the app and updated, i.e. not use any library). Potentially easier to implement the equivalent of add_related_count()...

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). There are also a handful of issues blocked by us making a decision on this issue.

Originally created by @arthanson on GitHub (Jan 6, 2023). ### Proposed Changes The recent loss of maintainership for [django-mptt](https://github.com/netbox-community/netbox/issues/6587), has precipitated discussion on evaluating a replacement for our usage of MPTT for hierarchical models with an alternate solution. CTE has been discussed, see #6587 Author of django-tree-queries lists his reasons here: https://406.ch/writing/django-tree-queries/. He notes potential issues he doesn't like with PostgreSQL ltree, however this is probably still a viable alternative. See https://github.com/mariocesar/django-ltree and https://github.com/peopledoc/django-ltree-demo (the ltree-demo could just be pulled into the app and updated, i.e. not use any library). Potentially easier to implement the equivalent of add_related_count()... ### 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). There are also a handful of issues blocked by us making a decision on this issue.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:23:44 +01:00
adam closed this issue 2025-12-29 20:23:44 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 10, 2023):

Wrapping this into #12552.

@jeremystretch commented on GitHub (May 10, 2023): Wrapping this into #12552.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7466