Skip to content

Commit

Permalink
Fix query hint retrieval with utilities
Browse files Browse the repository at this point in the history
Query jumbling is possible in PostgreSQL 16 for utilities, generating a
JumbleState that could involve a query normalization.  This would break
the retrieval of query hints for quite a few scenarios, we we should try
to get the hints from the query planned, mostly around EXPLAIN:
- EXPLAIN EXECUTE
- EXPLAIN CTAS

This commit patches the post parse-analyze hook to ignore entirely
utility queries, unbreaking all the remaining regression tests.

At this point, the regression tests are stable with PostgreSQL 16.

Per pull request #130.
  • Loading branch information
michaelpq committed Apr 20, 2023
1 parent da28ef7 commit a03bbdb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pg_hint_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,17 @@ pg_hint_plan_post_parse_analyze(ParseState *pstate, Query *query,
if (plpgsql_recurse_level == 0)
current_hint_retrieved = false;

/*
* Query jumbling is possible with utility queries in PostgreSQL 16 and
* newer versions, hence just leave in this case. There could be a point
* in providing hints for some cases, like a CTAS or a matview creation,
* but that should not matter much in practice compared to SELECT and DML
* queries, and nobody has made a case for these now. So let's just
* ignore the case entirely for now.
*/
if (query->utilityStmt)
return;

/*
* Jumble state is required when hint table is used. This is the only
* chance to have one already generated in-core. If it's not the case, no
Expand Down

0 comments on commit a03bbdb

Please sign in to comment.