Fix SEGV caused by duplicate memoize hints HintTypeName was missing the item for the Memoize hint. This causes SEGV or "(null)" printing by printf on erroring of duplicate memoize hints. Add the missing item and a static assertion to check the same kind of fault. Reported by ShangBenX <https://github.com/ShangBenX>
Properly free all elements in a list HintStateDelete tried to free the elements of hstate->all_hints[] but actually it only freed part of them. Correct the code as it intended. Some other palloced blocks are being hanged under the struct but we don't bother trying to be perfect at cleaning up the whole struct since it will be freed up at query end.
Allow hints to be placed anywhere in query Hints description is restriected to be placed before certain characters. That is effectively at the beginning of a query, or after EXPLAIN or PREPARE. This commit adds a new setting parameter pg_hint_plan.hints_anywhere, which gets rid of that restriction. When it is on, pg_hint_plan ignores SQL syntax at all while reading hints so there's no restricion on where hint string is placed in a query string. On the other hand it may lead to false reads from a non-hint strings.
Followup change to support PG14 One improvement and on fix. Ressurect post_parse_analysys_hook function to avoid redandunt computation of jumble state if it is generated in-core. Properly handle the case where compute_query_id is turned off while pg_hint_plan.enable_hint_talbe is on. This operation lead to a crash.
Allow run make check of PostgreSQL with loading pg_hint.plan Automatically switch environment when pg_hint_plan is installed as a part of "make check" of PostgreSQL. That test is executed with the following command line in the top directory of PostgreSQL tree. make check EXTRA_INSTALL=<this directory> EXTRA_REGRESS_OPTS="--temp-config <this directory>/pg_hint_plan.conf" make check-world fails for test that requires extra modules.
Support "Memoize" Hint. PostgreSQL 14 introduced the new optimization item "memoize", which allows a join to memoize the inner result. Add a hint to control this feature.
Support PostgreSQL 14 In PostgreSQL 14, planner was restructured in regard to query string passing. This change allows us to remove fair amount of lines and complexity that had been added as a struggle for retrieving proper query string. Two callbacks, post_parse_analyze_hook and ProcessUtility_hook are no longer used. get_query_string is removed altogether. Also current_hint_retrieved juggling, which was complex and fragile, disappears. Now pg_hint_plan_planner alone can retrieve hint string by looking into the given string. In PostgreSQL 14, a new optimization item "memoize" is added. It is not handled in this commit and leave it for a later commit.