Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJS = \

HINTPLANVER = 1.9.0

REGRESS = init base_plan pg_hint_plan ut-init ut-A ut-S ut-J ut-L ut-G ut-R \
REGRESS = init base_plan pg_hint_plan ut-init ut-A ut-AS ut-S ut-J ut-L ut-G ut-R \
ut-fdw ut-W ut-T ut-fini plpgsql hint_table disable_index \
query_parser oldextversions
REGRESS_OPTS = --encoding=UTF8
Expand Down
1 change: 1 addition & 0 deletions docs/hint_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ The available hints are listed below.
| Behavior control on Join | `Memoize(table table[ table...])` | Allows the topmost join of a join among the specified tables to Memoize the inner result. Not enforced. |
| | `NoMemoize(table table[ table...])` | Inhibits the topmost join of a join among the specified tables from Memoizing the inner result. |
| Row number correction | `Rows(table table[ table...] correction)` | Corrects row number of a result of the joins on the tables specified. The available correction methods are absolute (#<n>), addition (+<n>), subtract (-<n>) and multiplication (*<n>). <n> should be a string that strtod() can understand. |
| | `ArrayRows(table[ qualifier] correction)` | Adjusts row estimation for array predicates on the tables specified. Targets array operators (`&&`, `@>`, `<@`) and scalar-array comparisons (`<cmp> ANY/ALL (array)`). The correction is absolute (#<n>), addition (+<n>), subtraction (-<n>) or multiplication (*<n>). `qualifier` is optional and can be an operator (`&&`, `@>`, `<@`), a quantifier (`ANY`, `ALL`) or a comparison+quantifier (e.g. `= ANY`, `<> ALL`). |
| Parallel query configuration | `Parallel(table <# of workers> [soft\|hard])` | Enforces or inhibits parallel execution of the specified table. <# of workers> is the desired number of parallel workers, where zero means inhibiting parallel execution. If the third parameter is soft (default), it just changes max\_parallel\_workers\_per\_gather and leaves everything else to the planner. Hard enforces the specified number of workers. |
| GUC | `Set(GUC-param value)` | Sets GUC parameter to the value defined while planner is running. |
39 changes: 39 additions & 0 deletions docs/hint_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,45 @@ from restrictions in the planner. For example:
=# /*+ Rows(a b *10) */ SELECT... ; Makes the number 10 times larger.
```

### Hints for ArrayRows (array predicate row corrections)

This hint, named `ArrayRows`, adjusts row estimation for array-related
predicates. It can be useful when PostgreSQL's default estimate is too crude
(especially when the array expression is not a constant).

`ArrayRows` targets:

- Array operators: `&&`, `@>`, `<@`
- Scalar-array comparisons: `<cmp> ANY (array)` and `<cmp> ALL (array)`

`<cmp>` can be `=`, `<>` (or `!=`), `<`, `<=`, `>` and `>=`.

The last argument is the correction term:

- `#<n>` sets the estimated number of rows produced by the matching predicate(s)
- `+<n>` increases the estimated rows by the given amount
- `-<n>` decreases the estimated rows by the given amount
- `*<n>` scales the matching predicate(s) by the given factor

The optional `qualifier` can narrow the hint down to only a specific operator
or quantifier, for example `&&`, `ANY`, or `= ANY`. If multiple matching
predicates exist for the same relation set, the correction is distributed
evenly across them.

If multiple `ArrayRows` hints match the same predicate, the most specific
qualifier wins (comparison+quantifier like `= ANY` is preferred over `ANY`/`ALL`
or an array operator like `&&`, which are preferred over no qualifier).

For inheritance/partitioned tables, it is usually best to target the parent
relation name/alias; child rels may appear in `EXPLAIN` with planner-generated
aliases like `parent_1`, `parent_2`, but the parent hint still applies.

```sql
=# /*+ ArrayRows(t && #10) */ EXPLAIN SELECT * FROM t WHERE t.tags && some_array();
=# /*+ ArrayRows(t = ANY #100) */ EXPLAIN SELECT * FROM t WHERE t.id = ANY(some_array());
=# /*+ ArrayRows(t ANY *0.1) */ EXPLAIN SELECT * FROM t WHERE t.id < ANY(some_array());
```

### Hints for parallel plans

This hint, named `Parallel`, enforces parallel execution configuration
Expand Down
Loading