ossc-db / pg_hint_plan

Extension adding support for optimizer hints in PostgreSQL
Other
696 stars 103 forks source link

Fix issue with ignoring prepared statements that have array parameters (because of square brackets []) #98

Closed WinterUnicorn closed 1 year ago

WinterUnicorn commented 2 years ago

We have an issues with prepared statements that use arrays as arguments. In this case pg_hint_plan don't pass preceding sql check.

Example:

prepare test_query(numeric[]) as /*+ MergeJoin(t1 t2) */ with test as (select 1 as x) select t1.* from test t1, test t2 where t1.x=any($1) and t1.x = t2.x;

explain execute test_query(array[1,2,3]); 
-- MergeJoin hint will be ignored because of numeric[] parameter

deallocate test_query;

This request to add the '[', ']' symbols into the white list.

michaelpq commented 1 year ago

I am not completely sure of this consequences that this change has, but shouldn't we have at least a regression test to track this behavior? A backpatch could create a change of behavior for existing users, as well.

horiguti commented 1 year ago

I tried the repro with master (PG15) branch but failed. Error-return from nested planner is checked in ut-A but actually error-case is not tested (ut-A). (opposed to my memory)

So, +1 for adding the test for that case. That part is repeatedly rewrote seeking more stable behavior but..

MasahikoSawada commented 1 year ago

+1 for adding test cases. We also need to update the documentation.

Adding '[' and ']' to the white list seems reasonable to me since these characters can also be used as data types in PREPARE statement. But it would change the existing behavior so not sure we should back-patch it.

michaelpq commented 1 year ago

And so, I have added a regression test and applied that on HEAD as of 7c03155 with no backpatch involved so this will be available in the next versions compatible with Postgres 15~.