Skip to content

Commit

Permalink
[#24055] YSQL: fix pg_hint_plan regression with executing prepared st…
Browse files Browse the repository at this point in the history
…atement

Summary:
Fix a regression introduced in 5523770 where the hints were missed out when the query was recompiled without going through semantic analysis again.

Move the query string - query tree consistency check to the hint_table specific code.  In the other case, the hints are directly taken from the query string without using the location info in the query tree hence the mismatch is harmless.

**pg15: there's nothing to merge/port to the pg15 branch.**
Jira: DB-12947

Test Plan:
  ./yb_build.sh --java-test 'org.yb.pgsql.TestPgMisc#testPgHintPlanExtendedQuery'
  ./yb_build.sh --java-test 'org.yb.pgsql.TestYbBackup#testPgHintPlan'
  ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressThirdPartyExtensionsPgHintPlan'

Jenkins: test regex: .*PgHintPlan.*

Reviewers: tnayak

Reviewed By: tnayak

Subscribers: smishra, yql

Differential Revision: https://phorge.dev.yugabyte.com/D38265
  • Loading branch information
mtakahar committed Sep 23, 2024
1 parent cc6d2d1 commit ed153dc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/postgres/third-party-extensions/pg_hint_plan/pg_hint_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,12 +1931,6 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
else if (!jumblequery && pstate && pstate->p_sourcetext != p &&
strcmp(pstate->p_sourcetext, p) != 0)
p = NULL;
/*
* YB note: don't assume it is the top-level query when pstate is NULL and
* the query tree does not have the source location.
*/
else if (!pstate && query->stmt_location <= 0 && query->stmt_len <= 0)
p = NULL;

return p;
}
Expand Down Expand Up @@ -2901,6 +2895,14 @@ get_current_hint_string(ParseState *pstate, Query *query)

query_str = get_query_string(pstate, query, &jumblequery);

/*
* YB note: don't assume it is the top-level query when pstate is NULL
* and the query tree does not have the source location.
*/
if (!pstate && query->stmt_location <= 0 && query->stmt_len <= 0 &&
query_str == debug_query_string)
query_str = NULL;

/* If this query is not for hint, just return */
if (!query_str)
return;
Expand Down

0 comments on commit ed153dc

Please sign in to comment.