Closed elonzh closed 6 months ago
Maybe django-cte has a solution? https://github.com/dimagi/django-cte/blob/master/tests/test_recursive.py
I think there's some hope to avoid the optimization fence in PostgreSQL in the future and allow pushing down predicates into the CTE – avoiding this performance problem in the database engine itself isn't impossible but I think PostgreSQL still doesn't support it. I don't know about other database engines.
I'm not sure but I think that django-tree-queries isn't well suited when it comes to extending or customizing the CTE itself. The implementation of django-cte is probably a better fit when it comes to supporting more elaborate queries, I'm not sure.
Fixed by #66
Currently the CTE query build tree in table scope and this make a huge performance impact when table is big.
In my situation, we seprate the records by user id which means the performance overhead will be reduced if we can build tree at the user level.