pg_hint_plan
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_hint_plan | 1.8.1 | FEAT | BSD-3-Clause | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2780 | pg_hint_plan | No | Yes | Yes | Yes | No | No | hint_plan |
| Related | hypopg online_advisor pg_qualstats index_advisor pg_stat_plans plan_filter pg_strom pg_orca pg_regresql pg_track_optimizer |
|---|
PG14-18 RPM: 1.4.5/1.5.4/1.6.3/1.7.2/1.8.1; PG18 DEB 1.8.0; 1.9.0 is PG19-only.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.8.1 | 1817161514 | pg_hint_plan | - |
| RPM | PGDG | 1.8.1 | 1817161514 | pg_hint_plan_$v | - |
| DEB | PGDG | 1.8.0 | 1817161514 | postgresql-$v-pg-hint-plan | - |
Install
You can install pg_hint_plan directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
Usage
Sources:
- README.md
- pg_hint_plan.control
- docs/hint_list.md
- docs/installation.md
- docs/requirements.md
- docs/functional_limitations.md
pg_hint_plan overrides the PostgreSQL query planner’s decisions using SQL comment hints, allowing you to force specific scan methods, join strategies, and join orders.
Hint Syntax
Hints are embedded in SQL comments prefixed with /*+ and closed with */:
Scan Method Hints
| Hint | Description |
|---|---|
SeqScan(table) | Force sequential scan |
IndexScan(table [index...]) | Force index scan (optionally restrict to specific indexes) |
IndexOnlyScan(table [index...]) | Force index-only scan |
BitmapScan(table [index...]) | Force bitmap scan |
TidScan(table) | Force TID scan |
NoSeqScan(table) | Prevent sequential scan |
NoIndexScan(table) | Prevent index scan and index-only scan |
NoIndexOnlyScan(table) | Prevent index-only scan |
NoBitmapScan(table) | Prevent bitmap scan |
NoTidScan(table) | Prevent TID scan |
IndexScanRegexp(table [regexp...]) | Force index scan with regex-matched index names |
DisableIndex(table index...) | Disable specific indexes during planning |
Join Method Hints
| Hint | Description |
|---|---|
NestLoop(t1 t2 [t3...]) | Force nested loop join |
HashJoin(t1 t2 [t3...]) | Force hash join |
MergeJoin(t1 t2 [t3...]) | Force merge join |
NoNestLoop(t1 t2 [t3...]) | Prevent nested loop join |
NoHashJoin(t1 t2 [t3...]) | Prevent hash join |
NoMergeJoin(t1 t2 [t3...]) | Prevent merge join |
Memoize(t1 t2 [t3...]) | Allow memoization of inner result |
NoMemoize(t1 t2 [t3...]) | Prevent memoization |
Join Order Hints
Row Number Correction
Parallel Query Control
GUC Parameter Override
GUC Configuration
| Parameter | Description | Default |
|---|---|---|
pg_hint_plan.enable_hint | Enable or disable hints globally | on |
pg_hint_plan.enable_hint_table | Enable hint table for query-based hints | off |
pg_hint_plan.debug_print | Print debug info for applied hints | off |
pg_hint_plan.parse_messages | Log level for hint parsing messages | INFO |
pg_hint_plan.message_level | Log level for debug messages | LOG |
Loading and PostgreSQL Version Branches
Version 1.9.0 requires PostgreSQL 19. Use 1.8.1 for PG18, 1.7.2 for PG17, 1.6.3 for PG16, 1.5.4 for PG15 or 1.4.5 for PG14; do not install the PG19 build on an older server.
LOAD 'pg_hint_plan' activates hints in the current session without CREATE EXTENSION. Global preload requires a restart. To use the hint table, additionally run CREATE EXTENSION pg_hint_plan and enable pg_hint_plan.enable_hint_table. Hints cannot force a non-executable plan and query IDs ignore hint comments; verify actual plans with EXPLAIN. The current releases fix parser-loop, interrupt and planner error-path handling.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)