• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

firtst release


Commit MetaInfo

修訂b9e6db788e1beccc171d690fb83477ea5a820149 (tree)
時間2014-12-19 15:55:10
作者Kyotaro Horiguchi <horiguchi.kyotaro@lab....>
CommiterKyotaro Horiguchi

Log Message

Added English documentation.

Change Summary

差異

--- /dev/null
+++ b/doc/hint_list.html
@@ -0,0 +1,103 @@
1+<!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+<html>
3+<head>
4+<title>Appendix A. Hints list</title>
5+<!-- Uncoment after the tool has been hosted somewhere.
6+<link rel="home" title="pg_hint_plan" href="index.html">
7+-->
8+<link rel="stylesheet" type="text/css" href="style.css">
9+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10+</head>
11+
12+<body>
13+<h1 id="pg_hint_plan">pg_hint_plan 1.1 Appendices</h1>
14+<div class="navigation">
15+ <a href="pg_hint_plan-ja.html">pg_hint_plan</a> &gt;
16+ <a href="hint_list-ja.html">Appendix A. Hints list</a>
17+</div>
18+<hr>
19+
20+<h2 id="hint-list">Appendix A. Hints list</h2>
21+<p>The available hints are listed below.</p>
22+<table>
23+<thead>
24+<tr>
25+<tr><th>Group</th><th>Format</th><th>Description</th></tr>
26+</tr>
27+</thead>
28+<tbody>
29+<tr><td rowspan="10" nowrap>Scan method</td>
30+ <td nowrap>SeqScan(table)</td>
31+ <td>Forces sequential scan on the table</td></tr>
32+<tr><td>TidScan(table)</td>
33+ <td>Forces TID scan on the table.</td></tr>
34+<tr><td nowrap>IndexScan(table[ index...])</td>
35+ <td>Forces index scan on the table. Restricts to specified indexes if any. </td></tr>
36+<tr><td nowrap>IndexOnlyScan(table[ index...])</td>
37+ <td>Forces index only scan on the table. Rstricts to specfied indexes if any. Index scan may be used if index only scan is not available. Available for PostgreSQL 9.2 and later.</td></tr>
38+<tr><td nowrap>BitmapScan(table[ index...])</td>
39+ <td>Forces bitmap scan on the table. Restoricts to specfied indexes if any.</td></tr>
40+<tr><td nowrap>NoSeqScan(table)</td>
41+ <td>Forces not to do sequential scan on the table.</td></tr>
42+<tr><td nowrap>NoTidScan(table)</td>
43+ <td>Forces not to do TID scan on the table. </td></tr>
44+<tr><td nowrap>NoIndexScan(table)</td>
45+ <td>Forces not to do index scan and index only scan (For PostgreSQL
46+ 9.2 and later) on the table. </td></tr>
47+<tr><td nowrap>NoIndexOnlyScan(table)</td>
48+ <td>Forces not to do index only scan on the table. Available for PostgreSQL 9.2 and later.</td></tr>
49+<tr><td nowrap>NoBitmapScan(table)</td>
50+ <td>Forces not to do bitmap scan on the table. </td></tr>
51+
52+<tr><td rowspan="6" nowrap>Join method</td>
53+ <td nowrap>NestLoop(table table[ table...])</td>
54+ <td>Forces nested loop for the joins consist of the specifiled tables.</td></tr>
55+<tr><td nowrap>HashJoin(table table[ table...])</td>
56+ <td>Forces hash join for the joins consist of the specifiled tables.</td></tr>
57+<tr><td nowrap>MergeJoin(table table[ table...])</td>
58+ <td>Forces merge join for the joins consist of the specifiled tables.</td></tr>
59+<tr><td nowrap>NoNestLoop(table table[ table...])</td>
60+ <td>Forces not to do nested loop for the joins consist of the specifiled tables.</td></tr>
61+<tr><td nowrap>NoHashJoin(table table[ table...])</td>
62+ <td>Forces not to do hash join for the joins consist of the specifiled tables.</td></tr>
63+<tr><td nowrap>NoMergeJoin(table table[ table...])</td>
64+ <td>Forces not to do merge join for the joins consist of the specifiled tables.</td></tr>
65+
66+<tr><td rowspan="2">Join order</td>
67+ <td nowrap>Leading(table table[ table...])</td>
68+ <td>Forces join order as specified.</td></tr>
69+<tr><td nowrap>Leading(&lt;join pair&gt;)</td>
70+ <td>Forces join order and directions as specified. A join pair is a pair of tables and/or other join pairs enclosed by parentheses, which can make a nested structure.</td>
71+
72+<tr><td>Row number correction</td>
73+ <td nowrap>Rows(table table[ table...] correction)</td>
74+ <td>Corrects row number of a result of the joins consist of the specfied tables. The available correction methods are absolute (#&ltn&gt), addition (+&ltn&gt), subtract (-&ltn&gt) and multiplication (*&ltn&gt). &ltn&gt should be a string that strtod() can read.
75+<tr><td>GUC</td>
76+ <td nowrap>Set(GUC-param value)</td>
77+ <td>Set the GUC parameter to the value while planner is running.</td></tr>
78+</tbody>
79+</table></p>
80+
81+
82+<hr>
83+<div class="navigation">
84+ <a href="pg_hint_plan-ja.html">pg_hint_plan</a> &gt;
85+ <a href="hint_list-ja.html">Appendix A. hints list</a>
86+</div>
87+
88+<p class="footer">Copyright (c) 2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION</p>
89+
90+<!--
91+<script type="text/javascript">
92+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
93+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
94+</script><script src="pg_statsinfo-ja_files/ga.js" type="text/javascript"></script>
95+<script type="text/javascript">
96+try{
97+var pageTracker = _gat._getTracker("UA-10244036-6");
98+pageTracker._trackPageview();
99+} catch(err) {}
100+</script>
101+-->
102+</body>
103+</html>
--- /dev/null
+++ b/doc/pg_hint_plan.html
@@ -0,0 +1,427 @@
1+<!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+<html lang="en_US">
3+<head>
4+<title>pg_hint_plan</title>
5+<!-- Uncoment after the tool has been hosted somewhere.
6+<link rel="home" title="pg_hint_plan" href="index.html">
7+-->
8+<link rel="stylesheet" type="text/css" href="style.css">
9+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10+<!--
11+<style type="text/css">
12+h2 { border-style:solid none none none; margin-top: 2em; }
13+h3 { margin-top: 2em; }
14+dt { margin-top: 0.5em; margin-bottom: 0.3em;}
15+pre { margin: 0 2em 0 2em; padding:0.3em; border-style: solid; border-width:0.1em; border-color: #97A69F; background-color: #DEFFEF; }
16+</style>
17+-->
18+</head>
19+
20+<body>
21+<h1 id="pg_hint_plan">pg_hint_plan 1.1</h1>
22+<div class="navigation">
23+ <a href="pg_hint_plan-ja.html">pg_hint_plan</a>
24+</div>
25+<hr>
26+
27+<div class="index">
28+<ol>
29+<li><a href="#name">Name</a></li>
30+<li><a href="#synopsis">Synopsis</a></li>
31+<li><a href="#description">Description</a>
32+<li><a href="#install">Installation</a></li>
33+<li><a href="#uninstall">Uninstallation</a></li>
34+<li><a href="#examples">Hint descriptions</a></li>
35+<li><a href="#hint_syntax">Hint syntax</a></li>
36+<li><a href="#restrictions">Restrictions</a></li>
37+<li><a href="#technics">Technics to hint on disired targets</a></li>
38+<li><a href="#errors">Errors of hints</a></li>
39+<li><a href="#func_limits">Functional limitations</a></li>
40+<li><a href="#requirement">Requirements</a></li>
41+<li><a href="#seealso">See Also</a></li>
42+<li><a href="hint_list.html">Appendix A. Hints list</a></li>
43+</div>
44+
45+<h2 id="name">Name</h2>
46+<p>pg_hint_plan -- controls execution plan with hinting phrases in comment of special form.</p>
47+
48+<h2 id="synopsis">Synopsis</h2>
49+<p>PostgreSQL uses cost based optimizer, which utilizes data statistics, not static rules. The planner (optimizer) esitimates costs of each possible execution plans for a SQL statement then the execution plan with the lowest cost finally be executed. The planner does its best to select the best best execution plan, but not perfect, since it doesn't count some properties of the data, for example, correlation between columns.</p>
50+<p>pg_hint_plan makes it possible to tweak execution plans using so-called "hints", which are simple descriptions in the SQL comment of special form.</p>
51+
52+<h2 id="description">Description</h2>
53+
54+<h3 id="hint-rule">Basic Usage</h3>
55+<p>pg_hint_plan reads hinting phrases in a comment of special form given with the target SQL statement. The special form is beginning by the character sequence "/*+" and ends with "*/". Hint phrases are consists of hint name and following parameters enclosed by parentheses and delimited by spaces. Each hinting phrases can be delimited by new lines for readability.</p>
56+
57+<p>In the example below , hash join is selected as the joning method and scanning pgbench_accounts by sequential scan method.</p>
58+<pre>
59+postgres=# /*+
60+postgres*# <span class="strong">HashJoin(a b)</span>
61+postgres*# <span class="strong">SeqScan(a)</span>
62+postgres*# */
63+postgres-# EXPLAIN SELECT *
64+postgres-# FROM pgbench_branches b
65+postgres-# JOIN pgbench_accounts a ON b.bid = a.bid
66+postgres-# ORDER BY a.aid;
67+ QUERY PLAN
68+---------------------------------------------------------------------------------------
69+ Sort (cost=31465.84..31715.84 rows=100000 width=197)
70+ Sort Key: a.aid
71+ -> <span class="strong">Hash Join</span> (cost=1.02..4016.02 rows=100000 width=197)
72+ Hash Cond: (a.bid = b.bid)
73+ -> <span class="strong">Seq Scan on pgbench_accounts a</span> (cost=0.00..2640.00 rows=100000 width=97)
74+ -> Hash (cost=1.01..1.01 rows=1 width=100)
75+ -> Seq Scan on pgbench_branches b (cost=0.00..1.01 rows=1 width=100)
76+(7 rows)
77+
78+postgres=# </pre>
79+
80+<h3 id="hint-group">The types of hints</h3>
81+<p>Hinting phrases are classified into four types based on what kind of object they can affect. Scaning methods, join methods, joining order, row number correction and GUC setting. You will see the lists of hint phrases of each type in <a href="hint_list.html">Hint list</a>.</p>
82+
83+<h4>Hints for scan methods </h4>
84+<p>Scan method hints enforce the scanning method on the table specified as parameter. pg_hint_plan recognizes the target table by alias names if any. They are 'SeqScan' , 'IndexScan' and so on.</p>
85+<p>Scan hints are effective on ordinary tables, inheritance tables, UNLOGGED tables, temporary tables and system catalogs. It cannot be applicable on external(foreign) tables, table functions, VALUES command results, CTEs, Views and Sub-enquiries.</p>
86+
87+
88+<h4>Hints for join methods</h4>
89+<p>Join method hints enforces the join methods of the joins consists of tables specified as parameters. </p>
90+<p>Ordinary tables, inheritance tables, UNLOGGED tables, temporary tables, external (foreign) tables, system catalogs, table functions, VALUES command results and CTEs are allowed to be in the parameter list. But views and sub query are not.</p>
91+
92+<h4>Hint for joining order</h4>
93+<p> Joining in specific order can be enforced using the "Leading" hint. The objects are joined in the order of the objects in the parameter list.</p>
94+
95+<h4>Hint for row number correction</h4>
96+<p>From the restriction of the planner's capability, it misestimates the number of results on some conditions. This type of hint corrects it. </p>
97+
98+<h4>GUC parameters temporarily setting</h4>
99+<p>'Set' hint changes GUC parameters just while planning. GUC parameter shown in <a href="http://www.postgresql.org/docs/current/static/runtime-config-query.html">Query Planning</a> can have the expected effects on planning unless any other hint conflicts with the planner method configuration parameters. The last one among hints on the same GUC parameter makes effect. <a href="#hint-GUC">GUC parameters for pg_hint_plan</a> are also settable by this hint but it won't work as your expectation. See <a href="#restrictions">Restrictions</a> for details.</p>
100+
101+<h3 id="hint-GUC">GUC parameters for pg_hint_plan</h3>
102+<p>GUC parameters below affect the behavior of pg_hint_planpg_hint_plan.</p>
103+<table>
104+<thead>
105+<tr>
106+<tr><th>Parameter name</th><th>discription</th><th>Default</th></tr>
107+</tr></thead>
108+<tbody>
109+<tr><td>pg_hint_plan.enable_hint</td>
110+ <td>Enbles or disables the function of pg_hint_plan.</td><td>on</td></tr>
111+<tr><td>pg_hint_plan.debug_print</td>
112+ <td>Enables and select the verbosity of the debug output of pg_hint_plan. off, on, detailed and verbose are valid.</td><td>off</td></tr>
113+<tr><td>pg_hint_plan.message_level</td>
114+ <td>Specifies the message level of debug prints. error, warning, notice, info, log, debug<n> are valid and fatal and panic are inhibited.</td><td>info</td></tr>
115+</tbody>
116+</table>
117+<p>
118+PostgreSQL 9.1 requires a custom variable class to be defined for those GUC parameters. See <a href="http://www.postgresql.org/docs/9.1/static/runtime-config-custom.html#GUC-CUSTOM-VARIABLE-CLASSES">custom_variable_classes</a> for details.
119+</p>
120+
121+<h2 id="install">Installation</h2>
122+This section describes the installation steps.
123+<h3 id="build">building binary module</h3>
124+<p>Simplly run "make" in the top of the source tree, then "make install" as appropriate user. The PATH environment variable should be set properly for the target PostgreSQL for this process. </p>
125+<pre>
126+$ tar xzvf pg_hint_plan-1.x.x.tar.gz
127+$ cd pg_hint_plan-1.x.x
128+$ make
129+$ su
130+# make install
131+</pre>
132+
133+<h3 id="hint-load">Loding pg_hint_plan</h3>
134+<p>Basically pg_hint_plan does not requires CREATE EXTENSION. Simplly loading it by LOAD command will activate it and of course you can load it globally by setting shared_preload_libraries in postgresql.conf. Or you might be interested in ALTER USER SET/ALTER DATABASE SET for automatic loading for specific sessions.
135+<pre>
136+postgres=# LOAD 'pg_hint_plan';
137+LOAD
138+postgres=# </pre></p>
139+
140+<p>Do CREATE EXTENSION and SET pg_hint_plan.enable_hint_tables TO on if you are planning to hint tables.</p>
141+
142+
143+<h2 id="uninstall">Unistallation</h2>
144+<p>"make uninstall" in the top directory of source tree will uninstall the installed files if you installed from the source tree and it is left available. </p>
145+
146+<pre>
147+$ cd pg_hint_plan-1.x.x
148+$ su
149+# make uninstall
150+</pre>
151+
152+
153+<h2 id="examples">Hint descriptions</h2>
154+This section explains how to spell each type of hints.
155+<h3>Scan method hints</h3>
156+<p>Scan hints have basically has one parameter to specify the target object. This additional parameter for scans using indexes is preferable index name. The target object should be specified by its alias name if any. In the following example, table1 is scanned by sequential scan and table2 is scanned using the primary key index.
157+<pre>
158+postgres=# /*+
159+postgres*# SeqScan(t1)
160+postgres*# IndexScan(t2 t2_pkey)
161+postgres*# */
162+postgres-# SELECT * FROM table1 t1 JOIN table table2 t2 ON (t1.key = t2.key);
163+</pre>
164+</p>
165+
166+<h3>Join method hints</h3>
167+<p>Join hints have two or more objects which compose the join as parameters. If three objects are specified, the hint will be applied when joining any one of them after joining other two objects. In the following example, table1 and table2 are joined fisrt using nested loop and the result is joined against table3 using merge join.</p>
168+
169+<pre>
170+postgres=# /*+
171+postgres*# NestLoop(t1 t2)
172+postgres*# MergeJoin(t1 t2 t3)
173+postgres*# Leading(t1 t2 t3)
174+postgres*# */
175+postgres-# SELECT * FROM table1 t1
176+postgres-# JOIN table table2 t2 ON (t1.key = t2.key)
177+postgres-# JOIN table table3 t3 ON (t2.key = t3.key);
178+</pre>
179+
180+<h3>Joining order hints</h3>
181+<p>Although there might be the case that table2 and 3 are joined first and table1 after that and the NestLoop hint won't be in effect after all. "Leading" hint enforces the joining order for the cases. The Leading hint in the above example enforces the joining order to table1, 2, 3 then both join method hints will be effective.</p>
182+<p>
183+The above form of Leading hint enforces joining order but joining direction (inner/outer or driven/driving assignment) is left to the planner. If you want to also enforce joining directions, the second form of this hint will help.
184+</p>
185+<pre>
186+postgres=# /*+ Leading((t1 (t2 t3))) */ SELECT...
187+</pre>
188+<p>
189+Every pair of parentheses enclose two elements which are an object or nested parentheses. The first element in a pair of parentheses is the driver or outer table and the second is the driven or inner.
190+</p>
191+
192+<h3>Row number correction hints</h3>
193+<p>
194+Planner misestimates the number of the records for joins on some condition. This hint can corrects the number by several methods, which are absolute value, addition/subtraction and multiplication. The parameters are the list of objects compose the targetted join then operation. The following example shows notations to correct the number of the join on a and b by the four correction methods.
195+</p>
196+<pre>
197+postgres=# /*+ Rows(a b #10) */ SELECT... ; Sets rows of join result to 10
198+postgres=# /*+ Rows(a b +10) */ SELECT... ; Increments row number by 10
199+postgres=# /*+ Rows(a b -10) */ SELECT... ; Subtracts 10 from the row number.
200+postgres=# /*+ Rows(a b *10) */ SELECT... ; Makes the number 10 times larger.
201+</pre>
202+
203+<h3>GUC temporarily setting</h3>
204+<p>
205+"Set" hint sets GUC parameter values during the target statement is under plannning. In the following example, planning for the query is done with random_page_cost is 2.0.
206+<pre>
207+postgres=# /*+
208+postgres*# Set(random_page_cost 2.0)
209+postgres*# */
210+postgres-# SELECT * FROM table1 t1 WHERE key = 'value';
211+...
212+</pre>
213+</p>
214+
215+<h2 id="hint_syntax">Hint syntax</h2>
216+<h3>Hint comment location</h3>
217+<p>pg_hint_plan reads hints from only the first block comment, and any characters except alphabets, digits, spaces, underscores, commas and parentheses are not allowed before the comment. In the following example HashJoin(a b) and SeqScan(a) are recognized as Hint and IndexScan(a) and MergeJoin(a b) is not. </p>
218+<pre>
219+postgres=# /*+
220+postgres*# <span class="strong">HashJoin(a b)</span>
221+postgres*# <span class="strong">SeqScan(a)</span>
222+postgres*# */
223+postgres-# /*+ IndexScan(a) */
224+postgres-# EXPLAIN SELECT /*+ MergeJoin(a b) */ *
225+postgres-# FROM pgbench_branches b
226+postgres-# JOIN pgbench_accounts a ON b.bid = a.bid
227+postgres-# ORDER BY a.aid;
228+ QUERY PLAN
229+---------------------------------------------------------------------------------------
230+ Sort (cost=31465.84..31715.84 rows=100000 width=197)
231+ Sort Key: a.aid
232+ -> <span class="strong">Hash Join</span> (cost=1.02..4016.02 rows=100000 width=197)
233+ Hash Cond: (a.bid = b.bid)
234+ -> <span class="strong">Seq Scan on pgbench_accounts a</span> (cost=0.00..2640.00 rows=100000 width=97)
235+ -> Hash (cost=1.01..1.01 rows=1 width=100)
236+ -> Seq Scan on pgbench_branches b (cost=0.00..1.01 rows=1 width=100)
237+(7 rows)
238+
239+postgres=# </pre>
240+<h3>Escaping special chacaters in object names</h3>
241+<p>The objects as the hint parameter should be enclosed by double quotes if they includes parentheses, double quotes and white spaces. The escaping rule is the same as PostgreSQL.
242+</p>
243+<h3>Distinction among table occurrences with the same name </h3>
244+<p>Target name duplication caused by multiple occurrences of the same object or objects with the same name in different name spaces can be avoided by giving alias names for each occurrence in the target query and using them in hint phases.
245+The example below, the first SQL statement results in error from using a table name appeared twice in the target query, while the second example works since each occurrence of table t1 is given a distinct alias name and specified in the HashJoin hint using it.
246+</p>
247+<pre>
248+postgres=# /*+ <span class="strong">HashJoin(t1 t1)</span>*/
249+postgres-# EXPLAIN SELECT * FROM s1.t1
250+postgres-# JOIN public.t1 ON (s1.t1.id=public.t1.id);
251+INFO: hint syntax error at or near "HashJoin(t1 t1)"
252+<span class="strong">DETAIL: Relation name "t1" is ambiguous.</span>
253+ QUERY PLAN
254+------------------------------------------------------------------
255+ Merge Join (cost=337.49..781.49 rows=28800 width=8)
256+ Merge Cond: (s1.t1.id = public.t1.id)
257+ -> Sort (cost=168.75..174.75 rows=2400 width=4)
258+ Sort Key: s1.t1.id
259+ -> Seq Scan on t1 (cost=0.00..34.00 rows=2400 width=4)
260+ -> Sort (cost=168.75..174.75 rows=2400 width=4)
261+ Sort Key: public.t1.id
262+ -> Seq Scan on t1 (cost=0.00..34.00 rows=2400 width=4)
263+(8 行)
264+
265+postgres=# /*+ <span class="strong">HashJoin(pt st)</span> */
266+postgres-# EXPLAIN SELECT * FROM s1.t1 st
267+postgres-# JOIN public.t1 pt ON (st.id=pt.id);
268+ QUERY PLAN
269+---------------------------------------------------------------------
270+ <span class="strong">Hash Join</span> (cost=64.00..1112.00 rows=28800 width=8)
271+ Hash Cond: (st.id = pt.id)
272+ -> Seq Scan on t1 st (cost=0.00..34.00 rows=2400 width=4)
273+ -> Hash (cost=34.00..34.00 rows=2400 width=4)
274+ -> Seq Scan on t1 pt (cost=0.00..34.00 rows=2400 width=4)
275+(5 行)
276+
277+postgres=#</pre>
278+</p>
279+<h2 id="restrictions">Restrictions</h2>
280+<h3>Limitations on multiple VALUES lists in FROM clauses</h3>
281+<p>All occurences of VALUES lists in FROM clauses in a query has the same name "*VALUES*" irrespective of aliases syntactically given to them or shown in explain descriptions. So it cannot be hinted at all if appeares twice or more in a target query. </p>
282+<h3>Hinting on inheritance children</h3>
283+<p>Inheritnce children cannot be hinted individually. They share the same hints on their parent.</p>
284+
285+<h3>Setting pg_hint_plan parameters by Set hints</h3>
286+<p>pg_hint_plan paramters changes the behavior of itself so some parameters doesn't work as expected.</p>
287+<ul>
288+<li>Hints to change enable_hint, enable_hint_tables are ignored, but they are reported as "used hints" in debug logs.</li>
289+<li>Setting debug_print and message_level works from midst of the processing of the target query.</li>
290+</ul>
291+
292+
293+<h2 id="technics">Technics to hint on desired targets</h2>
294+<h3>Hinting on objecects implicitly used in the target query</h3>
295+<p>Hints are effective on any objects with the target name even if they aren't aparent in the query, specifically objects in views. For that reason, you should create different views in which targetted objects have distinct aliases if you want to hint them differently from the first view.</p>
296+<p>In the following examples, the first query is assigning the same name "t1" on the two occurrences of the table1 so the hint SeqScan(t1) affects both scans. On the other hand the second assignes the different name 't3' on the one of them so the hint affects only on the rest one.</p>
297+<p>This mechanism also applies on rewritten queries by rules.</p>
298+<pre>
299+postgres=# CREATE VIEW view1 AS SELECT * FROM table1 <span class="strong">t1</span>;
300+CREATE TABLE
301+postgres=# /*+ SeqScan(<span class="strong">t1</span>) */
302+postgres=# EXPLAIN SELECT * FROM table1 <span class="strong">t1</span> JOIN view1 t2 ON (t1.key = t2.key) WHERE t2.key = 1;
303+ QUERY PLAN
304+-----------------------------------------------------------------
305+ Nested Loop (cost=0.00..358.01 rows=1 width=16)
306+ -> Seq Scan on table1 <span class="strong">t1</span> (cost=0.00..179.00 rows=1 width=8)
307+ Filter: (key = 1)
308+ -> Seq Scan on table1 <span class="strong">t1</span> (cost=0.00..179.00 rows=1 width=8)
309+ Filter: (key = 1)
310+(5 rows)
311+
312+postgres=# /*+ SeqScan(<span class="strong">t3</span>) */
313+postgres=# EXPLAIN SELECT * FROM table1 <span class="strong">t3</span> JOIN view1 t2 ON (t1.key = t2.key) WHERE t2.key = 1;
314+ QUERY PLAN
315+--------------------------------------------------------------------------------
316+ Nested Loop (cost=0.00..187.29 rows=1 width=16)
317+ -> Seq Scan on table1 <span class="strong">t3</span> (cost=0.00..179.00 rows=1 width=8)
318+ Filter: (key = 1)
319+ -> Index Scan using foo_pkey on table1 t1 (cost=0.00..8.28 rows=1 width=8)
320+ Index Cond: (key = 1)
321+(5 rows)
322+
323+</pre>
324+<h3>Hinting on the hinheritance children</h3>
325+<p>Hints targeted on inheritance parents automatically affect on all their own children. Child tables cannot have their own hint specified. </p>
326+
327+<h3>Scope of hints on multistatement</h3>
328+<p>One multistatement description can have exactly one hint comment and the hints affects all of the individual statement in the multistatement. Notice that the seemingly multistatement on the interactive interface of psql is internally a sequence of single statements so hints affects only on the statement just following. Conversely, every single statement have their own hint comments affect on them.</p>
329+
330+<h3>Subqueries in some contexts</h3>
331+<p>Subqueries in the following context also can be hinted.</p>
332+<pre>
333+IN (SELECT ... {LIMIT | OFFSET ...} ...)
334+= ANY (SELECT ... {LIMIT | OFFSET ...} ...)
335+= SOME (SELECT ... {LIMIT | OFFSET ...} ...)
336+</pre>
337+<p>For these syntaxes, planner internally assigns the name of "ANY_subquery" to the subquery when planning joins including it, so join hints are applicable on such joins using the implicit name.</p>
338+<pre>
339+postgres=# /*+HashJoin(a1 ANY_subquery)*/
340+postgres=# EXPLAIN SELECT *
341+postgres=# FROM pgbench_accounts a1
342+postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
343+ QUERY PLAN
344+
345+---------------------------------------------------------------------------------------------
346+ Hash Semi Join (cost=0.49..2903.00 rows=1 width=97)
347+ Hash Cond: (a1.aid = a2.bid)
348+ -> Seq Scan on pgbench_accounts a1 (cost=0.00..2640.00 rows=100000 width=97)
349+ -> Hash (cost=0.36..0.36 rows=10 width=4)
350+ -> Limit (cost=0.00..0.26 rows=10 width=4)
351+ -> Seq Scan on pgbench_accounts a2 (cost=0.00..2640.00 rows=100000 width=4)
352+(6 rows)
353+</pre>
354+
355+<h3>Using IndexOnlyScan hint (PostgreSQL 9.2 and later)</h3>
356+<p>You shoud explicitly specify an index that can perform index only scan if you put IndexOnlyScan hint on a table that have other indexes that cannot perform index only scan. Or pg_hint_plan may select them. </p>
357+
358+<h3>Precaution points for NoIndexScan hint (PostgreSQL 9.2 and later)</h3>
359+<p>NoIndexScan hint involes NoIndexOnlyScan.</p>
360+
361+
362+<h2 id="errors">Errors of hints</h2>
363+<p>pg_hint_plan stops parsing on any error and uses hints already parsed on the most cases. Followings are the typical errors.</p>
364+<h3>Syntax errors </h3>
365+<p>Any syntactical errors or wrong hint names are reported as an syntax error. These errors are reported in the server log with the message level which specified by pg_hint_plan.message_level if pg_hint_plan.debug_print is on and aboves.</p>
366+<h3>Object misspecifications</h3>
367+<p>Object misspecifications results silent ingorance of the hints. This kind of error is reported as "not used hints" in the server log by the same condtion to syntax errors.</p>
368+
369+<h3>Redundant or conflicting hints</h3>
370+<p>The last hint will be active when redundant hints or hints conflicting with each other. This kind of error is reported as "duplication hints" in the server log by the same condition to syntax errors.</p>
371+
372+<h3>Nested comments</h3>
373+<p>Hint comment cannot include another block comment within. If pg_hint_plan finds it, differently from other erros, it stops parsing and abandans all hints already parsed. This kind of error is reported in the same manner as other errors. </p>
374+
375+<h2 id="func_limits">Functional limitations</h2>
376+<h3>Influences of some planner GUC parameters</h3>
377+<p>The planner does not try to consider joining order for FROM clause entries more than from_collapse_limit. pg_hint_plan cannot affect joining order as expected for the case.</p>
378+
379+<h3>Cases that pg_hint_plan essentially cannot affect </h3>
380+<p>By the nature of pg_hint_plan, it cannot affect some cases that out of scope of the planner like following.</p>
381+<ul>
382+<li>FULL OUTER JOIN to use nested loop</li>
383+<li>To use indexes that does not have columns used in quals</li>
384+<li>To do TID scans for queries without ctid conditions</li>
385+</ul>
386+
387+<h3>Queries in ECPG</h3>
388+<p>ECPG removes comments in queries written as embedded SQLs so hints cannot be passed form those queries. The only exception is that EXECUTE command passes given string unmodifed. Please consider hint tables for this case.</p>
389+
390+<h3>Effects on query fingerprints</h3>
391+<p>The same queries with different commnets yields the same fingerprint by pg_stat_statements on PostgreSQL 9.2 and later, but they yield different fingerprints on 9.1 and earlier, so the same queires with different hints are summerized as separate queries on such versions.</p>
392+
393+<h2 id="requirement">Requirements</h2>
394+<dl>
395+<dt>PostgreSQL versions tested</dt>
396+ <dd>Version 9.1, 9.2, 9.3, 9.4</dd>
397+<dt>OS versions tested</dt>
398+ <dd>RHEL 6.5, 7.0</dd>
399+</dl>
400+
401+<h2 id="seealso">See also</h2>
402+<h3 id="postgresql_document">PostgreSQL documents</h3>
403+<a href="http://www.postgresql.org/docs/current/static/sql-explain.html">EXPLAIN</a>
404+<a href="http://www.postgresql.org/docs/current/static/sql-set.html">SET</a>
405+<a href="http://www.postgresql.org/docs/current/static/runtime-config.html">Server Config</a>
406+<hr>
407+
408+<div class="navigation">
409+ <a href="pg_hint_plan.html">pg_hint_plan</a>
410+</div>
411+
412+<p class="footer">Copyright (c) 2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION</p>
413+
414+<!--
415+<script type="text/javascript">
416+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
417+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
418+</script><script src="pg_statsinfo-ja_files/ga.js" type="text/javascript"></script>
419+<script type="text/javascript">
420+try{
421+var pageTracker = _gat._getTracker("UA-10244036-6");
422+pageTracker._trackPageview();
423+} catch(err) {}
424+</script>
425+-->
426+</body>
427+</html>