Skip to content

add select hints for postgresql#643

Open
yy-at-here wants to merge 1 commit intostephenafamo:mainfrom
yy-at-here:feat/psql-select-hints
Open

add select hints for postgresql#643
yy-at-here wants to merge 1 commit intostephenafamo:mainfrom
yy-at-here:feat/psql-select-hints

Conversation

@yy-at-here
Copy link
Copy Markdown

@yy-at-here yy-at-here commented Mar 29, 2026

this PR is related to the isse: #641.

Summary

  • Add support for pg_hint_plan optimizer hints in PostgreSQL SELECT queries
  • Hints are rendered as /*+ ... */ comments before the SELECT clause
  • Supported hint categories:
    • Scan hints: SeqScan, NoSeqScan, IndexScan, NoIndexScan, IndexOnlyScan, NoIndexOnlyScan, BitmapScan, NoBitmapScan, TidScan, NoTidScan
    • Join hints: NestLoop, NoNestLoop, HashJoin, NoHashJoin, MergeJoin, NoMergeJoin
    • Join order: Leading
    • Row estimation: Rows
    • Parallel: Parallel
    • GUC: Set

Example

psql.Select(
    sm.SeqScan("t1"),
    sm.NestLoop("t1", "t2"),
    sm.Columns("id", "name"),                                                                                                                                                                                                                                                            
    sm.From("t1"),
    sm.InnerJoin("t2").On(psql.Quote("t1", "id").EQ(psql.Quote("t2", "id"))),                                                                                                                                                                                                            
)                                                                                                                                                                                                                                                                                        
// => /*+ SeqScan(t1) NestLoop(t1 t2) */ SELECT id, name FROM t1 INNER JOIN t2 ON ("t1"."id" = "t2"."id")

How to test

  • Unit tests added in TestSelectHints covering single hint, multiple hints, index scan with multiple indexes, leading hint, and set hint

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