ossc-db / pg_hint_plan

Extension adding support for optimizer hints in PostgreSQL
Other
674 stars 101 forks source link

[Poc] Fix handling of joinrelids #139 #147

Closed mikecaat closed 10 months ago

mikecaat commented 11 months ago

find_join_hint() calculates the join level using joinrelids which is a bitmapset of relations within the join with the assumption that the relids has only base relations.

But, relids became to have outer-join relids with PostgreSQL commit (2489d76c). So, the calculation logic became wrong and crash on some condition.

The commit fixes the logic to calculate joinrelids to consider only base relations.

This patch is for PoC. I think we need to think the following.

michaelpq commented 10 months ago

I have spent a few hours on that, and applied the fix down to 16. Nice investigation overall, it seems, now I am not the best planner specialist on this planner, either. Still I understand the concepts behind the relids involved in the Planner states and its surroundings.

The change in transform_join_hints() does not seem necessary to me as long as OuterInnerJoinCreate() applies a filter to remove any outer-join relids that we have. Even in the latter case, the list of relids comes from the hint itself, so this is not strongly mandatory either. I do agree that it feels much safer in the long-term, though.