PostgreSQL: Parse optimizer hints in leading comments#3
Merged
altmannmarcelo merged 1 commit intoreadyset-patchedfrom Apr 23, 2026
Merged
PostgreSQL: Parse optimizer hints in leading comments#3altmannmarcelo merged 1 commit intoreadyset-patchedfrom
altmannmarcelo merged 1 commit intoreadyset-patchedfrom
Conversation
Enable comment-based optimizer hint parsing for the PostgreSQL dialect by overriding `supports_comment_optimizer_hint` to return `true`. PostgreSQL itself does not ship a built-in hint system, but the widely used `pg_hint_plan` extension (https://github.com/ossc-db/pg_hint_plan) introduces hints using the exact same `/*+ ... */` block-comment and `--+ ...` single-line-comment syntax already supported for MySQL and Oracle (apache#2162). Without this flag, parsing a `pg_hint_plan` statement such as: SELECT /*+ SeqScan(t) */ * FROM t; discards the hint as an ordinary comment, making it impossible for downstream tools (query rewriters, proxies, planners) built on `sqlparser-rs` to preserve or act on hints when targeting PostgreSQL. The parser side already handles this via `maybe_parse_optimizer_hint` across SELECT / INSERT / UPDATE / DELETE / MERGE, so no parser or AST changes are required — this is purely a dialect opt-in. The default remains `false`, so no other dialect is affected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable comment-based optimizer hint parsing for the PostgreSQL dialect by overriding
supports_comment_optimizer_hintto returntrue.PostgreSQL itself does not ship a built-in hint system, but the widely used
pg_hint_planextension (https://github.com/ossc-db/pg_hint_plan) introduces hints using the exact same/*+ ... */block-comment and--+ ...single-line-comment syntax already supported for MySQL and Oracle (apache#2162). Without this flag, parsing apg_hint_planstatement such as:discards the hint as an ordinary comment, making it impossible for downstream tools (query rewriters, proxies, planners) built on
sqlparser-rsto preserve or act on hints when targeting PostgreSQL.The parser side already handles this via
maybe_parse_optimizer_hintacross SELECT / INSERT / UPDATE / DELETE / MERGE, so no parser or AST changes are required — this is purely a dialect opt-in. The default remainsfalse, so no other dialect is affected.