Skip to content

feat: complete SQL Server OPTION query hint support - #2486

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:feat/option-hints-followup
Aug 19, 2026
Merged

feat: complete SQL Server OPTION query hint support#2486
manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:feat/option-hints-followup

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

Completes two SQL Server OPTION follow-ups from #2472:

  1. Parse, retain, validate and deparse OPTION (...) after MERGE, including after OUTPUT.
  2. Parse OPTIMIZE FOR (@variable UNKNOWN) as an existing table-less Column, avoiding a new expression type and Visitor methods.

Also reject OPTION after standalone VALUES, including INSERT ... VALUES, because SQL Server permits query hints on INSERT only in its nested SELECT. INSERT ... SELECT ... OPTION remains supported.

Testing

OptionClauseTest: 19/19 passed. New cases cover MERGE, OUTPUT, OPTIMIZE FOR, invalid INSERT ... VALUES and valid INSERT ... SELECT forms.

Performance

JSQLParserBenchmark.parseSQLStatements on performance.sql, version=latest, JDK 17.0.20, 10 forks x (3 warmup + 10 measurement iterations), 100 samples per run, two interleaved runs per build on a 32-thread Intel Core i9-13900KS host:

build run 1 (ms/op) run 2 (ms/op)
base 7013909 3.724 ± 0.026 3.717 ± 0.023
this PR bf17921 3.714 ± 0.022 3.738 ± 0.025

Mean delta: +0.15%. All confidence intervals overlap -> no regression.

* <a href="https://learn.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query">Hints
* (Transact-SQL) - Query Hints</a>.
*/
public class UnknownVariable extends ASTNodeAccessImpl implements Expression {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need an extra class for this? Why not just carry a normal "Identifier" or "String" along? I would love to avoid especially the extra methods in the Visitors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced UnknownVariable with a table-less Column and removed the class plus every Visitor addition. Column#getColumnName() retains @p UNKNOWN.

Comment thread src/test/java/net/sf/jsqlparser/statement/select/OptionClauseTest.java Outdated
@fudianchn
fudianchn marked this pull request as draft August 19, 2026 07:14
Attach OPTION to MERGE statements and validate and deparse its parameters. Parse OPTIMIZE FOR (@variable UNKNOWN) as a table-less Column, reusing the existing expression visitor contract.

Reject OPTION after standalone VALUES, including INSERT ... VALUES, because SQL Server allows query hints on INSERT only in a nested SELECT. Preserve exact spacing when MERGE combines OUTPUT and OPTION.

Signed-off-by: 付典 <fudianchn@gmail.com>
@fudianchn
fudianchn force-pushed the feat/option-hints-followup branch from 1157f74 to bf17921 Compare August 19, 2026 07:42
@fudianchn fudianchn changed the title feat: support OPTION hints after MERGE and INSERT ... VALUES, and the OPTIMIZE FOR (@var UNKNOWN) parameter form feat: complete SQL Server OPTION query hint support Aug 19, 2026
@fudianchn
fudianchn marked this pull request as ready for review August 19, 2026 07:44
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you, I like this more.

@manticore-projects
manticore-projects merged commit 4c6a4fb into JSQLParser:master Aug 19, 2026
7 checks passed
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.

2 participants