Skip to content

[MySQL, Oracle] Parse optimizer hints#2162

Merged
iffyio merged 13 commits intoapache:mainfrom
xitep:optimizer-hints
Jan 29, 2026
Merged

[MySQL, Oracle] Parse optimizer hints#2162
iffyio merged 13 commits intoapache:mainfrom
xitep:optimizer-hints

Conversation

@xitep
Copy link
Copy Markdown
Contributor

@xitep xitep commented Jan 14, 2026

this should resolve #1995

@iffyio
Copy link
Copy Markdown
Contributor

iffyio commented Jan 22, 2026

@xitep wondering would it not make more sense to support features like these via the new parse_sql_with_comments API?

@xitep
Copy link
Copy Markdown
Contributor Author

xitep commented Jan 22, 2026

surely it would be one way. (the only premise for that would to be have the next non-comment token after the corresponding keywords covered with a span, like suggested in #2099.) however, when processing such statements, these hints are something you generally don't want to leave out, even when parsing without comments. hence this proposal to embed it directly into the AST.

Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
@xitep xitep requested a review from iffyio January 26, 2026 10:55
Copy link
Copy Markdown
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @xitep!

@iffyio iffyio added this pull request to the merge queue Jan 29, 2026
Merged via the queue into apache:main with commit be460b2 Jan 29, 2026
10 checks passed
@xitep xitep deleted the optimizer-hints branch January 30, 2026 13:01
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Feb 3, 2026
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
fmguerreiro pushed a commit to fmguerreiro/datafusion-sqlparser-rs that referenced this pull request Feb 20, 2026
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
altmannmarcelo added a commit to readysettech/datafusion-sqlparser-rs that referenced this pull request Apr 23, 2026
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.
altmannmarcelo added a commit to readysettech/datafusion-sqlparser-rs that referenced this pull request Apr 23, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Associate multi-line comments with their query blocks for implementing Optimizer Hints

2 participants