In clause_is_computable_at(), test required_relids for clone clauses.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 21 May 2023 19:25:43 +0000 (15:25 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 21 May 2023 19:25:52 +0000 (15:25 -0400)
commitb9c755a2f625b7dca6323804b140b016d95a0b1d
treeb9f1b0863a826daf1f0dc13527f424b7bdf30bd8
parenteabb22525efc40ce0d83580584094a0248ac0682
In clause_is_computable_at(), test required_relids for clone clauses.

Use the clause's required_relids not clause_relids for testing
whether it is computable at the current join level, if it is a
clone clause generated by deconstruct_distribute_oj_quals().

Arguably, this is more correct and we should do it for all clauses;
that would at least remove the handwavy claim that we are doing
it to save cycles compared to inspecting Vars individually.
However, attempting to do that exposes that we are not being careful
to compute an accurate value for required_relids in all cases.
I'm unsure whether it's a good idea to attempt to do that for v16,
or leave it as future clean-up.  In the meantime, this quick hack
demonstrably fixes some cases, so let's squeeze it in for beta1.

Patch by me, but great thanks to Richard Guo for investigation
and testing.  The new test cases are all modeled on his examples.

Discussion: https://postgr.es/m/CAMbWs4-_vwkBij4XOQ5ukxUvLgwTm0kS5_DO9CicUeKbEfKjUw@mail.gmail.com
src/backend/optimizer/util/restrictinfo.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql