Re:Hierarchical Structures in PostgreSQL (2020)
by zozbot234 on Saturday June 26, 2021 @03:18AM
(#27639864)
> They're the database equivalent of pointer-chasing in code.
That's the general case, but more specific CTE queries can be optimized, e.g. by adding database indexes. Recent versions of Postgres have greatly improved wrt. not making CTE's overly inefficient.
I like paths for representing hierarchy, but closure tables can also be a good idea, depending on what you're modelling and how you query it.