Open utterances-bot opened 3 years ago
Thank you!
Could you please describe in more details why ltree does not seem to be a good solution?
@Mogost There are a few downsides which make me doubt whether ltree would be better* than recursive CTEs:
parent
foreign key there's no way around denormalizing your database.ltree
fields. I don't think there's a way around rewriting all ltree
values in the subtree.These two points mean that you need a bit of code to manage the tree and keep all those values in sync. Exactly the thing which made me leave django-mptt behind because of recurring problems with broken trees.
You should only denormalize data when you have to, e.g. because your app would perform really badly without denormalization. I think adjacency lists and recursive CTEs hit the sweet spot for a lot of use cases – no denormalization and (better than) adequate performance.
Finally, ltree is (obviously) PostgreSQL-only, and while that wouldn't be a big problem for me it's nice that recursive CTEs work well on a number of databases. (django-tree-queries' initial releases only supported PostgreSQL).
* Better for my use case.
@matthiask Thank you very much for your detailed explanation.
OK, I have just set an alarm:
Every time I struggle whether to use or not a multi-thousand line application I will visit your profile, searching for a similar solution "in the hundreds".
django-tree-queries - Matthias Kestenholz
https://406.ch/writing/django-tree-queries/