1
1
<sect1 id="pg-hint-plan">
2
- <title>pg_hint_plan 1.1.3 </title>
2
+ <title>pg_hint_plan</title>
3
3
<sect2 id="pg-hint-plan-name">
4
4
<title>Name</title>
5
5
<para>
10
10
<sect2 id="pg-hint-plan-synopsis">
11
11
<title>Synopsis</title>
12
12
<para>
13
- PostgreSQL uses cost based optimizer, which utilizes data
13
+ PostgreSQL uses cost- based optimizer, which utilizes data
14
14
statistics, not static rules. The planner (optimizer) esitimates
15
15
costs of each possible execution plans for a SQL statement then
16
16
the execution plan with the lowest cost finally be executed. The
17
- planner does its best to select the best best execution plan, but
17
+ planner does its best to select the best execution plan, but
18
18
not perfect, since it doesn't count some properties of the data,
19
19
for example, correlation between columns.
20
20
</para>
32
32
pg_hint_plan reads hinting phrases in a comment of special form
33
33
given with the target SQL statement. The special form is
34
34
beginning by the character sequence <quote>/*+</quote> and ends
35
- with <quote>*/</quote>. Hint phrases are consists of hint name
35
+ with <quote>*/</quote>. Hint phrases consist of hint name
36
36
and following parameters enclosed by parentheses and delimited
37
37
by spaces. Each hinting phrases can be delimited by new lines
38
38
for readability.
39
39
</para>
40
40
<para>
41
- In the example below , hash join is selected as the joning
41
+ In the example below, hash join is selected as the joining
42
42
method and scanning pgbench_accounts by sequential scan method.
43
43
</para>
44
44
<programlisting>
@@ -67,8 +67,8 @@ postgres=#
67
67
<sect3 id="pg-hint-plan-hint-group">
68
68
<title>The types of hints</title>
69
69
<para>
70
- Hinting phrases are classified into four types based on what
71
- kind of object they can affect. Scaning methods, join methods,
70
+ Hinting phrases are classified into five types based on what
71
+ kind of object they can affect: scanning methods, join methods,
72
72
joining order, row number correction and GUC setting. You will
73
73
see the lists of hint phrases of each type in Hint list (See <xref linkend="pg-hint-plan-hint-list">).
74
74
</para>
@@ -77,15 +77,15 @@ postgres=#
77
77
<para>
78
78
Scan method hints enforce the scanning method on the table
79
79
specified as parameter. pg_hint_plan recognizes the target
80
- table by alias names if any. They are <quote>SeqScan</quote> ,
80
+ table by alias names if any. They are <quote>SeqScan</quote>,
81
81
<quote>IndexScan</quote> and so on.
82
82
</para>
83
83
<para>
84
84
Scan hints are effective on ordinary tables, inheritance
85
85
tables, UNLOGGED tables, temporary tables and system catalogs.
86
86
It cannot be applicable on external(foreign) tables, table
87
- functions, VALUES command results, CTEs, Views and
88
- Sub-enquiries .
87
+ functions, VALUES command results, CTEs, views and
88
+ subqueries .
89
89
</para>
90
90
</sect4>
91
91
<sect4>
@@ -98,7 +98,7 @@ postgres=#
98
98
Ordinary tables, inheritance tables, UNLOGGED tables,
99
99
temporary tables, external (foreign) tables, system catalogs,
100
100
table functions, VALUES command results and CTEs are allowed
101
- to be in the parameter list. But views and sub query are not.
101
+ to be in the parameter list. But views and subqueries are not.
102
102
</para>
103
103
</sect4>
104
104
<sect4>
@@ -121,9 +121,8 @@ postgres=#
121
121
<title>GUC parameters temporarily setting</title>
122
122
<para>
123
123
<quote>Set</quote> hint changes GUC parameters just while
124
- planning. GUC parameter shown in
125
- <ulink url="http://www.postgresql.org/docs/current/static/runtime-config-query.html">Query
126
- Planning</ulink> can have the expected effects on planning
124
+ planning. GUC parameter shown in <xref linkend="runtime-config-query-constants">
125
+ can have the expected effects on planning
127
126
unless any other hint conflicts with the planner method
128
127
configuration parameters. The last one among hints on the same
129
128
GUC parameter makes effect. GUC parameters for pg_hint_plan are also settable by this
@@ -136,22 +135,22 @@ postgres=#
136
135
<title>GUC parameters for pg_hint_plan</title>
137
136
<para>
138
137
GUC parameters below affect the behavior of
139
- pg_hint_planpg_hint_plan .
138
+ pg_hint_plan .
140
139
</para>
141
140
<para>
142
141
Parameter name
143
142
</para>
144
143
<para>
145
- discription
144
+ Description
146
145
</para>
147
146
<para>
148
- Default
147
+ Default value
149
148
</para>
150
149
<para>
151
150
pg_hint_plan.enable_hint
152
151
</para>
153
152
<para>
154
- Enbles or disables the function of pg_hint_plan.
153
+ Enables or disables the function of pg_hint_plan.
155
154
</para>
156
155
<para>
157
156
on
@@ -179,8 +178,7 @@ postgres=#
179
178
</para>
180
179
<para>
181
180
PostgreSQL 9.1 requires a custom variable class to be defined
182
- for those GUC parameters. See
183
- <ulink url="http://www.postgresql.org/docs/9.1/static/runtime-config-custom.html#GUC-CUSTOM-VARIABLE-CLASSES">custom_variable_classes</ulink>
181
+ for those GUC parameters. See <xref linkend="runtime-config-custom">
184
182
for details.
185
183
</para>
186
184
</sect3>
@@ -191,9 +189,9 @@ postgres=#
191
189
This section describes the installation steps.
192
190
</para>
193
191
<sect3 id="pg-hint-plan-build">
194
- <title>building binary module</title>
192
+ <title>Building binary module</title>
195
193
<para>
196
- Simplly run <quote>make</quote> in the top of the source tree,
194
+ Simply run <quote>make</quote> in the top of the source tree,
197
195
then <quote>make install</quote> as appropriate user. The PATH
198
196
environment variable should be set properly for the target
199
197
PostgreSQL for this process.
@@ -207,10 +205,10 @@ $ su
207
205
</programlisting>
208
206
</sect3>
209
207
<sect3 id="pg-hint-plan-hint-load">
210
- <title>Loding pg_hint_plan</title>
208
+ <title>Loading pg_hint_plan</title>
211
209
<para>
212
210
Basically pg_hint_plan does not requires CREATE EXTENSION.
213
- Simplly loading it by LOAD command will activate it and of
211
+ Simply loading it by LOAD command will activate it and of
214
212
course you can load it globally by setting
215
213
shared_preload_libraries in postgresql.conf. Or you might be
216
214
interested in ALTER USER SET/ALTER DATABASE SET for automatic
@@ -222,13 +220,13 @@ LOAD
222
220
postgres=#
223
221
</programlisting>
224
222
<para>
225
- Do CREATE EXTENSION and SET pg_hint_plan.enable_hint_tables TO
226
- on if you are planning to hint tables .
223
+ Do CREATE EXTENSION and SET pg_hint_plan.enable_hint_table TO
224
+ <literal>on</literal> if you are planning to use hint table .
227
225
</para>
228
226
</sect3>
229
227
</sect2>
230
228
<sect2 id="pg-hint-plan-uninstall">
231
- <title>Unistallation </title>
229
+ <title>Uninstallation </title>
232
230
<para>
233
231
<quote>make uninstall</quote> in the top directory of source tree
234
232
will uninstall the installed files if you installed from the
249
247
<title>Scan method hints</title>
250
248
<para>
251
249
Scan hints have basically has one parameter to specify the
252
- target object. This additional parameter for scans using indexes
250
+ target object. The additional parameter for scans using indexes
253
251
is preferable index name. The target object should be specified
254
252
by its alias name if any. In the following example, table1 is
255
253
scanned by sequential scan and table2 is scanned using the
@@ -270,7 +268,7 @@ postgres-# SELECT * FROM table1 t1 JOIN table table2 t2 ON (t1.key = t2.key);
270
268
parameters. If three objects are specified, the hint will be
271
269
applied when joining any one of them after joining other two
272
270
objects. In the following example, table1 and table2 are joined
273
- fisrt using nested loop and the result is joined against table3
271
+ first using nested loop and the result is joined against table3
274
272
using merge join.
275
273
</para>
276
274
<programlisting>
@@ -287,11 +285,11 @@ postgres-# JOIN table table3 t3 ON (t2.key = t3.key);
287
285
<sect3>
288
286
<title>Joining order hints</title>
289
287
<para>
290
- Although there might be the case that table2 and 3 are joined
288
+ Although there might be the case that table2 and table3 are joined
291
289
first and table1 after that and the NestLoop hint won't be in
292
290
effect after all. <quote>Leading</quote> hint enforces the
293
291
joining order for the cases. The Leading hint in the above
294
- example enforces the joining order to table1, 2, 3 then both
292
+ example enforces the joining order to table1, table2, table3 then both
295
293
join method hints will be effective.
296
294
</para>
297
295
<para>
@@ -380,11 +378,11 @@ postgres=#
380
378
</programlisting>
381
379
</sect3>
382
380
<sect3>
383
- <title>Escaping special chacaters in object names</title>
381
+ <title>Escaping special characters in object names</title>
384
382
<para>
385
383
The objects as the hint parameter should be enclosed by double
386
384
quotes if they includes parentheses, double quotes and white
387
- spaces. The escaping rule is the same as PostgreSQL .
385
+ spaces. The escaping rule is the same as <productname>&productname;</productname> .
388
386
</para>
389
387
</sect3>
390
388
<sect3>
@@ -450,20 +448,20 @@ postgres=#
450
448
<sect3>
451
449
<title>Hinting on inheritance children</title>
452
450
<para>
453
- Inheritnce children cannot be hinted individually. They share
451
+ Inheritance children cannot be hinted individually. They share
454
452
the same hints on their parent.
455
453
</para>
456
454
</sect3>
457
455
<sect3>
458
456
<title>Setting pg_hint_plan parameters by Set hints</title>
459
457
<para>
460
- pg_hint_plan paramters changes the behavior of itself so some
458
+ pg_hint_plan parameters changes the behavior of itself so some
461
459
parameters doesn't work as expected.
462
460
</para>
463
461
<itemizedlist spacing="compact">
464
462
<listitem>
465
463
<para>
466
- Hints to change enable_hint, enable_hint_tables are ignored,
464
+ Hints to change enable_hint, enable_hint_table are ignored,
467
465
but they are reported as <quote>used hints</quote> in debug
468
466
logs.
469
467
</para>
@@ -480,11 +478,11 @@ postgres=#
480
478
<sect2 id="pg-hint-plan-technics">
481
479
<title>Technics to hint on desired targets</title>
482
480
<sect3>
483
- <title>Hinting on objecects implicitly used in the target
481
+ <title>Hinting on objects implicitly used in the target
484
482
query</title>
485
483
<para>
486
484
Hints are effective on any objects with the target name even if
487
- they aren't aparent in the query, specifically objects in views.
485
+ they aren't apparent in the query, specifically objects in views.
488
486
For that reason, you should create different views in which
489
487
targetted objects have distinct aliases if you want to hint them
490
488
differently from the first view.
@@ -493,11 +491,11 @@ postgres=#
493
491
In the following examples, the first query is assigning the same
494
492
name <quote>t1</quote> on the two occurrences of the table1 so
495
493
the hint SeqScan(t1) affects both scans. On the other hand the
496
- second assignes the different name <quote>t3</quote> on the one
494
+ second query assigns the different name <quote>t3</quote> on the one
497
495
of them so the hint affects only on the rest one.
498
496
</para>
499
497
<para>
500
- This mechanism also applies on rewritten queries by rules.
498
+ This mechanism also applies on queries rewritten by rules.
501
499
</para>
502
500
<programlisting>
503
501
postgres=# CREATE VIEW view1 AS SELECT * FROM table1 t1;
@@ -526,19 +524,19 @@ postgres=# EXPLAIN SELECT * FROM table1 t3 JOIN view1 t2 ON (t1.key = t2.key) WH
526
524
</programlisting>
527
525
</sect3>
528
526
<sect3>
529
- <title>Hinting on the hinheritance children</title>
527
+ <title>Hinting on the inheritance children</title>
530
528
<para>
531
529
Hints targeted on inheritance parents automatically affect on
532
530
all their own children. Child tables cannot have their own hint
533
531
specified.
534
532
</para>
535
533
</sect3>
536
534
<sect3>
537
- <title>Scope of hints on multistatement </title>
535
+ <title>Scope of hints on multi-statement </title>
538
536
<para>
539
- One multistatement description can have exactly one hint comment
537
+ One multi-statement description can have exactly one hint comment
540
538
and the hints affects all of the individual statement in the
541
- multistatement . Notice that the seemingly multistatement on the
539
+ multi-statement . Notice that the seemingly multi-statement on the
542
540
interactive interface of psql is internally a sequence of single
543
541
statements so hints affects only on the statement just
544
542
following. Conversely, every single statement have their own
@@ -548,7 +546,7 @@ postgres=# EXPLAIN SELECT * FROM table1 t3 JOIN view1 t2 ON (t1.key = t2.key) WH
548
546
<sect3>
549
547
<title>Subqueries in some contexts</title>
550
548
<para>
551
- Subqueries in the following context also can be hinted.
549
+ Subqueries in the following contexts also can be hinted.
552
550
</para>
553
551
<programlisting>
554
552
IN (SELECT ... {LIMIT | OFFSET ...} ...)
@@ -581,7 +579,7 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
581
579
<sect3>
582
580
<title>Using IndexOnlyScan hint (PostgreSQL 9.2 and later)</title>
583
581
<para>
584
- You shoud explicitly specify an index that can perform index
582
+ You should explicitly specify an index that can perform index
585
583
only scan if you put IndexOnlyScan hint on a table that have
586
584
other indexes that cannot perform index only scan. Or
587
585
pg_hint_plan may select them.
@@ -591,7 +589,7 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
591
589
<title>Precaution points for NoIndexScan hint (PostgreSQL 9.2 and
592
590
later)</title>
593
591
<para>
594
- NoIndexScan hint involes NoIndexOnlyScan.
592
+ NoIndexScan hint involves NoIndexOnlyScan.
595
593
</para>
596
594
</sect3>
597
595
</sect2>
@@ -631,8 +629,8 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
631
629
<title>Nested comments</title>
632
630
<para>
633
631
Hint comment cannot include another block comment within. If
634
- pg_hint_plan finds it, differently from other erros , it stops
635
- parsing and abandans all hints already parsed. This kind of
632
+ pg_hint_plan finds it, differently from other errors , it stops
633
+ parsing and abandons all hints already parsed. This kind of
636
634
error is reported in the same manner as other errors.
637
635
</para>
638
636
</sect3>
@@ -683,10 +681,10 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
683
681
<sect3>
684
682
<title>Effects on query fingerprints</title>
685
683
<para>
686
- The same queries with different commnets yields the same
684
+ The same queries with different comments yields the same
687
685
fingerprint by pg_stat_statements on PostgreSQL 9.2 and later,
688
686
but they yield different fingerprints on 9.1 and earlier, so the
689
- same queires with different hints are summerized as separate
687
+ same queries with different hints are summarized as separate
690
688
queries on such versions.
691
689
</para>
692
690
</sect3>
@@ -730,11 +728,11 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
730
728
<para>IndexScan(table[ index...])</para>
731
729
<para>Forces index scan on the table. Restricts to specified indexes if any.</para>
732
730
<para>IndexOnlyScan(table[ index...])</para>
733
- <para>Forces index only scan on the table. Rstricts to specfied indexes
731
+ <para>Forces index only scan on the table. Restricts to specfied indexes
734
732
if any. Index scan may be used if index only scan is not
735
733
available. Available for PostgreSQL 9.2 and later.</para>
736
734
<para>BitmapScan(table[ index...])</para>
737
- <para>Forces bitmap scan on the table. Restoricts to specfied indexes if any.</para>
735
+ <para>Forces bitmap scan on the table. Restricts to specfied indexes if any.</para>
738
736
<para>NoSeqScan(table)</para>
739
737
<para>Forces not to do sequential scan on the table.</para>
740
738
<para>NoTidScan(table)</para>
@@ -772,8 +770,8 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
772
770
<para>Rows(table table[ table...] correction)</para>
773
771
<para>Corrects row number of a result of the joins consist of the
774
772
specfied tables. The available correction methods are absolute
775
- (#&ltn >), addition (+&ltn >), subtract
776
- (-&ltn >) and multiplication (*&ltn >). &ltn >
773
+ (#<n >), addition (+<n >), subtract
774
+ (-<n >) and multiplication (*<n >). <n >
777
775
should be a string that strtod() can read.</para>
778
776
<para>GUC</para>
779
777
<para>Set(GUC-param value)</para>
0 commit comments