Commit 1bba19a
committed
feat(transactsql): support final OPTION (query_hint, ...) clause
SQL Server accepts an optional `OPTION (query_hint [, ...])` clause at the
end of SELECT, UPDATE, DELETE and MERGE statements. Previously this clause
caused a parse failure in the `transactsql` dialect.
This extends `select_stmt_nake` to accept the optional query hints clause
after `FOR XML/JSON`, adds dedicated grammar rules for the hints, and
round-trips them back to SQL preserving canonical upper-case form.
Covered hints in this initial pass:
- no-argument: RECOMPILE, FORCE ORDER, LOOP JOIN, HASH JOIN, MERGE JOIN,
KEEP PLAN, KEEPFIXED PLAN, OPTIMIZE FOR UNKNOWN
- numeric-argument: MAXDOP n, MAXRECURSION n, FAST n
More complex hints like `OPTIMIZE FOR (@p = value)` and `USE HINT('...')`
are intentionally left out of this first round and can be added as a
follow-up.
Also refines the T-SQL `alias_clause` with a negative lookahead so that
`SELECT col FROM t OPTION (...)` is not mis-parsed with `OPTION` as an
implicit table alias.
- pegjs/transactsql.pegjs: extended `select_stmt_nake`; added
`tsql_query_hints` and `tsql_query_hint`; refined `alias_clause` to
exclude `OPTION (` as a candidate implicit alias.
- src/select.js: added `queryHintsToSQL`; destructured `query_hints` and
emitted the OPTION clause at the end of SELECT.
- test/transactsql.spec.js: added round-trip tests covering every hint
variant and a combined case with TOP + ORDER BY + OPTION.
Reference: https://learn.microsoft.com/sql/t-sql/queries/option-clause-transact-sql1 parent 23f817f commit 1bba19a
3 files changed
Lines changed: 95 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1344 | 1344 | | |
1345 | 1345 | | |
1346 | 1346 | | |
1347 | | - | |
| 1347 | + | |
| 1348 | + | |
1348 | 1349 | | |
1349 | 1350 | | |
1350 | 1351 | | |
| |||
1363 | 1364 | | |
1364 | 1365 | | |
1365 | 1366 | | |
1366 | | - | |
| 1367 | + | |
| 1368 | + | |
1367 | 1369 | | |
1368 | 1370 | | |
1369 | 1371 | | |
| |||
1382 | 1384 | | |
1383 | 1385 | | |
1384 | 1386 | | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
1385 | 1416 | | |
1386 | 1417 | | |
1387 | 1418 | | |
| |||
1446 | 1477 | | |
1447 | 1478 | | |
1448 | 1479 | | |
1449 | | - | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
1450 | 1484 | | |
1451 | 1485 | | |
1452 | 1486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
57 | 69 | | |
58 | 70 | | |
59 | 71 | | |
| |||
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
| 88 | + | |
76 | 89 | | |
77 | 90 | | |
78 | 91 | | |
| |||
105 | 118 | | |
106 | 119 | | |
107 | 120 | | |
| 121 | + | |
108 | 122 | | |
109 | 123 | | |
110 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
30 | 74 | | |
31 | 75 | | |
32 | 76 | | |
| |||
0 commit comments