1

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

1
  • 3
    I don't think any of the statistics options will help you. You would need something like cross-table statistics (or maybe cross table CHECK-like constraints) , which currently are unimplemented.
    – jjanes
    Jan 17 at 21:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.