There is loose index scan recursive query in postgresql https://wiki.postgresql.org/wiki/Loose_indexscan. I have similar query, which I need to write in sqlalchemy.
Postg