I have a table foo
, with an association table foo_associations
with columns foo_parent
and foo_child
. foo
has an column called department_id
. Any association made through foo_associations
is guaranteed to only connect foos
that have the same department_id
Due to the way a framework is set up, when you do a join foo <-> foo_associations <-> foo
, it adds an department_id = $1
condition for foo_1.department_id
and for foo_2.department_id
, respectively. Both of these values get applied twice in the estimation calculation, reducing the estimated amount of rows significantly. This causes bad plans in some circumstances.
I'm a bit short on luck in regard to adjusting the framework and I couldn't find a specific entry that would help me on the statistics in the documentation. Is there a way that I can help the planner out here and tell him that the second condition will not filter out any rows?
Note: Simplified Toy Example, which is reduced to the problem and may not necessarily reflect all design decisions