Skip to content

Extend use_index hint with table/column-aware format#227

Open
KirillKurdyukov wants to merge 5 commits into
mainfrom
feature/index-hint-table-column
Open

Extend use_index hint with table/column-aware format#227
KirillKurdyukov wants to merge 5 commits into
mainfrom
feature/index-hint-table-column

Conversation

@KirillKurdyukov

Copy link
Copy Markdown
Collaborator

No description provided.

@KirillKurdyukov KirillKurdyukov requested a review from alex268 June 22, 2026 10:26
@KirillKurdyukov KirillKurdyukov force-pushed the feature/index-hint-table-column branch from 0d8374e to d942ba9 Compare June 23, 2026 07:42
Extend the use_index hint with a table- and column-aware format
`use_index:<index>:<table>(<col>[,<col>...])` so the same table joined
several times under different aliases can be pinned to different secondary
indexes via VIEW. For each FROM/JOIN of the table the index is applied only
when every listed column is referenced by that alias in the relevant scope
(ON for a JOIN, WHERE for the FROM table); when several hints fully match,
the most specific one (most columns) wins.

Also:
- SqlTopLevelClauseScanner: single-pass clause lexer (string literals, comments,
  parenthesis nesting) in the same style as YdbQueryParser — replaces regex
  clause splitting for correct top-level FROM/JOIN detection.
- YdbDialect: pass all hints of a handler in a single batch for the
  HINT_COMMENT path, so best-match-wins behaves the same as via
  Query#addQueryHint.
- IndexQueryHintHandler: document regexes, fix IDENT grouping for quoted
  FROM tables, keep v6/v7 in sync.
- Add JaCoCo to both modules.
- Tests: unit cases (two joins, best-match, partial composite, lexer edge
  cases) and integration tests (BankDocument model) asserting rewritten SQL
  via StatementInspector through addQueryHint and HINT_COMMENT paths.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@KirillKurdyukov KirillKurdyukov force-pushed the feature/index-hint-table-column branch from 447a6e6 to 4a6780f Compare June 23, 2026 10:46
KirillKurdyukov and others added 4 commits June 23, 2026 15:11
Co-authored-by: Cursor <cursoragent@cursor.com>
Detect Hibernate-generated SQL by numbered aliases (e.g. a1_0) and
skip hint handlers for native queries where VIEW can be written explicitly.
Add integration test for addQueryHint and HINT_COMMENT on native SQL.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant