BertrandBordage / django-tree

Fast and easy tree structures.
BSD 3-Clause "New" or "Revised" License
88 stars 13 forks source link

Use Postgres ltree ? #8

Closed jacobjove closed 9 months ago

jacobjove commented 9 months ago

Could it be beneficial for performance to (optionally?) use the native Postgress ltree data type?

BertrandBordage commented 9 months ago

It was actually written using ltree in the past ;) I also assumed it would be the best, but in practice ltree is kind of neglected compared to other data types, so it did not benefit from better performance than just text. And recently I found out that it is actually a lot faster and more powerful to use arrays of decimals, as we can insert new nodes between existing nodes without having to modify those nodes. And thanks to decimals, we can predict when we have no space left between nodes, unlike floats.

I'm actually curious to see if anybody came up with the same strategy, as it simplifies a lot the algorithm.

BertrandBordage commented 9 months ago

Oh, forgot to paste a reference to when it was using ltree: https://github.com/BertrandBordage/django-tree/commit/c662be56f104c70d3edebd53fb7bd2be8a71ac21