Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writing/django-tree-queries/ #2

Open
utterances-bot opened this issue Nov 20, 2020 · 5 comments
Open

writing/django-tree-queries/ #2

utterances-bot opened this issue Nov 20, 2020 · 5 comments

Comments

@utterances-bot
Copy link

django-tree-queries - Matthias Kestenholz

https://406.ch/writing/django-tree-queries/

Copy link

guettli commented Nov 20, 2020

Thank you!

Copy link

Mogost commented Mar 13, 2021

Could you please describe in more details why ltree does not seem to be a good solution?

@matthiask
Copy link
Owner

@Mogost There are a few downsides which make me doubt whether ltree would be better* than recursive CTEs:

  • If you want a standard Django parent foreign key there's no way around denormalizing your database.
  • I'm not sure whether it's easy to reorder siblings when using 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.

@Mogost
Copy link

Mogost commented Mar 13, 2021

@matthiask Thank you very much for your detailed explanation.

Copy link

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants