Peter Grman <peter.gr...@gmail.com> writes: > our ORM with tenant separation enabled is creating the following query:
Ugh. By my count there are nine joined tables in that query, which means you're hitting the default join_collapse_limit. Increasing that setting might improve matters somewhat, though it won't fix the bad rowcount estimate per se. regards, tom lane