Skip to content

sql: add hint injection #153633

@michae2

Description

@michae2

Inline hints are a simple way to directly influence the optimizer. But the fact that hints must be added to the statement text makes them difficult to use, especially when it's not possible to modify the application sending the statement.

This issue is about building a way to inject hints without changing the statements being hinted. A rough idea of the capability is something like:

SELECT crdb_internal.inject_hints(
  'SELECT name, age FROM cat WHERE breed = _ ORDER BY age DESC LIMIT _',
  'SELECT name, age FROM cat@cat_age_idx WHERE breed = _ ORDER BY age DESC LIMIT _'
);

Which will force the following query to use index cat_age_idx:

SELECT name, age
FROM cat
WHERE breed = 'shorthair'
ORDER BY age DESC
LIMIT 1;

Jira issue: CRDB-54520

Metadata

Metadata

Assignees

Labels

C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries Teambranch-release-25.4Used to mark GA and release blockers and technical advisories for 25.4

Projects

Status

26.1 Release

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions