• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

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

firtst release


Commit MetaInfo

Revision04011fe2b352d3c561663645b71a368dc65b9f85 (tree)
Time2017-10-10 12:42:13
AuthorKyotaro Horiguchi <horiguchi.kyotaro@lab....>
CommiterKyotaro Horiguchi

Log Message

Added a notice in the manual.

Added an item that explains about letter case handling of object names
in hints.

Change Summary

Incremental Difference

--- a/doc/pg_hint_plan-ja.html
+++ b/doc/pg_hint_plan-ja.html
@@ -493,7 +493,9 @@ postgres$# END;
493493 postgres$# $$ LANGUAGE plpgsql;
494494 </pre>
495495 </dd>
496-<dt>オブジェクト名の引用符付け</dt>
496+<dt>ヒント句内のオブジェクト名の文字ケース</dt>
497+<dd>PostgreSQL は引用符で囲われないオブジェクト名を文字ケースを無視して扱いますが、pg_hint_plan は指定されたオブジェクト名の文字ケースはそのまま PostgreSQL の内部表現と比較します。つまり、ヒント句で TBL と指定した場合、データベース上で "TBL" と定義したもののみと合致し, TBL, tbl, Tbl など引用符で囲われないオブジェクト名とは合致しません。</dd>
498+<dt>ヒント句内のオブジェクト名の引用符付け</dt>
497499 <dd>ヒントに記述するオブジェクト名や別名が括弧((、)のいずれか)、二重引用符(")、空白(スペース、タブ、改行のいずれか)を含む場合は、通常のSQL文で使う場合と同じように二重引用符(")で囲んでください。二重引用符を含むオブジェクト名は、全体を二重引用符で括ったうえで、内部に含む二重引用符を二重引用符でエスケープしてください(例: 「quoted"table"name」→「"quoted""table""name"」)。</dd>
498500 <dt>同一名称テーブルの区別</dt>
499501 <dd>スキーマ違いや同一テーブルの複数回使用などでクエリ中に同一名称のテーブルが複数回出現する場合は、テーブルに別名をつけてそれぞれのテーブルを区別してください。以下の例の1つ目のSQL文では、HashJoin(t1 t1)をヒントに指定したとき、ヒント句対象のオブジェクトが特定できずにエラーになっています。2つ目のSQL文では、各テーブルにptやstという別名をつけているため、実行計画作成時にヒントで指定した通りにHash Joinを選択しています。</p>
@@ -626,7 +628,20 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
626628
627629 postgres=#
628630 </pre>
631+<<<<<<< HEAD
629632 一つのクエリで上記のような副問い合わせを複数使用している場合は、「ANY_subquery」と指定しても対象を特定できないため、ヒント句はエラーとなり無視されます。</br>
633+=======
634+
635+<dt><h3>IndexOnlyScanヒント句</h3></dt>
636+<dd>ヒント句の対象となるテーブルにIndex Only Scanが可能なインデックスとIndex Only Scanが不可能なインデックスが同時に存在する場合、Index Only Scanが可能なインデックスをテーブルに対してIndexOnlyScanヒント句を追加で指定しないとIndex Scanが選択されることがあります。</dd>
637+
638+<dt><h3>NoIndexScanヒントの挙動について</h3></dt>
639+<dd>NoIndexScanヒント句を指定した場合は、Index ScanだけでなくIndex Only Scanも選択されません。</dd>
640+</dl>
641+
642+<dt><h3>UNION に対する並列実行ヒント</h3></dt>
643+<dd>UNIONは直下のサブクエリが全て並列実行可能な場合にだけ並列実行を行います。一方ですべてのサブクエリが並列実行可能な場合は、そのうちの一つで並列実行を強制するとコスト比較の結果UNION全体が並列実行されることになります。ただし並列実行ヒントによる並列実行の禁止を行った場合はそのスキャンは並列実行不可となります。
644+>>>>>>> c6204a7... Added a notice in the manual.
630645 </dd>
631646 <dt>IndexOnlyScanヒント句の指定(PostgreSQL 9.2以降)</dt>
632647 <dd>ヒント句の対象となるテーブルにIndex Only Scanが可能なインデックスとIndex Only Scanが不可能なインデックスが存在する場合、Index Only Scanが可能なインデックスをテーブルと併せてIndexOnlyScanヒント句に指定しないとIndex Scanが選択されることがあります。</dd>
--- a/doc/pg_hint_plan.html
+++ b/doc/pg_hint_plan.html
@@ -237,6 +237,44 @@ postgres-# ORDER BY a.aid;
237237 (7 rows)
238238
239239 postgres=# </pre>
240+</dd>
241+
242+<h3>Using with PL/pgSQL</h3>
243+<dd>pg_hint_plan works for queries in PL/pgSQL scripts with some restrictions.
244+<ul>
245+ <li>Hints affect only on the following kind of queires.
246+ <ul>
247+ <li>Queries that returns one row. (SELECT, INSERT, UPDATE and DELETE)</li>
248+ <li>Queries that returns multiple rows. (RETURN QUERY)</li>
249+ <li>Dynamic SQL statements. (EXECUTE)</li>
250+ <li>Cursor open. (OPEN)</li>
251+ <li>Loop over result of a query (FOR)</li>
252+ </ul>
253+
254+ <li>A hint comment have to be placed after the first word in a query
255+ as the following since preceding comments are not sent as a part
256+ of the query.</li>
257+</ul>
258+<pre>
259+postgres=# CREATE FUNCTION hints_func(integer) RETURNS integer AS $$
260+postgres$# DECLARE
261+postgres$# id integer;
262+postgres$# cnt integer;
263+postgres$# BEGIN
264+postgres$# SELECT <b><u>/*+ NoIndexScan(a) */</u></b> aid
265+postgres$# INTO id FROM pgbench_accounts a WHERE aid = $1;
266+postgres$# SELECT <b><u>/*+ SeqScan(a) */</u></b> count(*)
267+postgres$# INTO cnt FROM pgbench_accounts a;
268+postgres$# RETURN id + cnt;
269+postgres$# END;
270+postgres$# $$ LANGUAGE plpgsql;
271+</pre>
272+</dd>
273+
274+<h3>Letter case in a hinted object</h3>
275+<p>Unlike the way PostgreSQL handles object names, pg_hint_plan compares bare object names in hints against the database internal object names in case sensitive way. Therefore an object name TBL in a hint matches only "TBL" in database and does not match any unquoted names like TBL, tbl or Tbl.
276+</p>
277+
240278 <h3>Escaping special chacaters in object names</h3>
241279 <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.
242280 </p>
@@ -274,6 +312,7 @@ postgres-# JOIN public.t1 pt ON (st.id=pt.id);
274312 -> Seq Scan on t1 pt (cost=0.00..34.00 rows=2400 width=4)
275313 (5 行)
276314
315+<<<<<<< HEAD
277316 postgres=#</pre>
278317 </p>
279318 <h2 id="restrictions">Restrictions</h2>
@@ -295,6 +334,42 @@ postgres=#</pre>
295334 <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>
296335 <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>
297336 <p>This mechanism also applies on rewritten queries by rules.</p>
337+=======
338+<h3>Underlying tables of views or rules</h3>
339+<dd>Hints are not applicable on views itself, but they can affect the
340+queries within if the object names match the object names in the
341+expanded query on the view. Assigning aliases to the tables in a view
342+enables them to be manipulated from outside the view.
343+<pre>
344+<b>postgres=#</b> CREATE VIEW v1 AS SELECT * FROM <b><u>t2</u></b>;
345+<b>postgres=#</b> EXPLAIN <b>/*+ HashJoin(t1 v1) */</b>
346+ SELECT * FROM t1 JOIN v1 ON (c1.a = v1.a);
347+ QUERY PLAN
348+------------------------------------------------------------------
349+ Hash Join (cost=3.27..18181.67 rows=101 width=8)
350+ Hash Cond: (t1.a = t2.a)
351+ -> Seq Scan on t1 (cost=0.00..14427.01 rows=1000101 width=4)
352+ -> Hash (cost=2.01..2.01 rows=101 width=4)
353+ -> Seq Scan on t2 (cost=0.00..2.01 rows=101 width=4)
354+</pre>
355+</dd>
356+
357+<h3>Inheritance tables</h3>
358+<dd>Hints can point only the parent of an inheritance tables and the
359+hint affect all the inheritance. Hints simultaneously point directly
360+to children are not in effect.
361+</dd>
362+
363+<h3>Hinting on multistatements</h3>
364+<dd>One multistatement 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.</dd>
365+
366+<h3>VALUES expressions</h3>
367+<dd>VALUES expressions in FROM clause are named as *VALUES* internally
368+so it is hintable if it is the only VALUES in a query. Two or more
369+VALUES expressions in a query seems distinguishable looking its
370+explain result. But in reality it is mere a cosmetic and they are not
371+distinguisable.
372+>>>>>>> c6204a7... Added a notice in the manual.
298373 <pre>
299374 postgres=# CREATE VIEW view1 AS SELECT * FROM table1 <span class="strong">t1</span>;
300375 CREATE TABLE
@@ -355,9 +430,18 @@ postgres=# WHERE aid IN (SELECT bid FROM pgbench_accounts a2 LIMIT 10);
355430 <h3>Using IndexOnlyScan hint (PostgreSQL 9.2 and later)</h3>
356431 <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>
357432
433+<<<<<<< HEAD
358434 <h3>Precaution points for NoIndexScan hint (PostgreSQL 9.2 and later)</h3>
359435 <p>NoIndexScan hint involes NoIndexOnlyScan.</p>
360436
437+=======
438+<h3>Parallel hint and UNION</h3>
439+<dd>A UNION can run in parallel only when all underlying subqueries
440+are parallel-safe. Conversely enforcing parallel on any of
441+the subqueries let a parallel-executable UNION run in
442+parallel. Meanwhile, a parallel hint with zero workers hinhibits a scan
443+from executed in parallel.</dd>
444+>>>>>>> c6204a7... Added a notice in the manual.
361445
362446 <h2 id="errors">Errors of hints</h2>
363447 <p>pg_hint_plan stops parsing on any error and uses hints already parsed on the most cases. Followings are the typical errors.</p>