Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit51ee6f3

Browse files
committed
Replace min_parallel_relation_size with two new GUCs.
When min_parallel_relation_size was added, the only supported typeof parallel scan was a parallel sequential scan, but there arepending patches for parallel index scan, parallel index-only scan,and parallel bitmap heap scan. Those patches introduce two newtypes of complications: first, what's relevant is not really thetotal size of the relation but the portion of it that we will scan;and second, index pages and heap pages shouldn't necessarily betreated in exactly the same way. Typically, the number of indexpages will be quite small, but that doesn't necessarily mean thata parallel index scan can't pay off.Therefore, we introduce min_parallel_table_scan_size, which worksout a degree of parallelism for scans based on the number of tablepages that will be scanned (and which is therefore equivalent tomin_parallel_relation_size for parallel sequential scans) and alsomin_parallel_index_scan_size which can be used to work out a degreeof parallelism based on the number of index pages that will bescanned.Amit Kapila and Robert HaasDiscussion:http://postgr.es/m/CAA4eK1KowGSYYVpd2qPpaPPA5R90r++QwDFbrRECTE9H_HvpOg@mail.gmail.comDiscussion:http://postgr.es/m/CAA4eK1+TnM4pXQbvn7OXqam+k_HZqb0ROZUMxOiL6DWJYCyYow@mail.gmail.com
1 parent5d40286 commit51ee6f3

File tree

8 files changed

+105
-38
lines changed

8 files changed

+105
-38
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,16 +3835,37 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
38353835
</listitem>
38363836
</varlistentry>
38373837

3838-
<varlistentry id="guc-min-parallel-relation-size" xreflabel="min_parallel_relation_size">
3839-
<term><varname>min_parallel_relation_size</varname> (<type>integer</type>)
3838+
<varlistentry id="guc-min-parallel-table-scan-size" xreflabel="min_parallel_table_scan_size">
3839+
<term><varname>min_parallel_table_scan_size</varname> (<type>integer</type>)
38403840
<indexterm>
3841-
<primary><varname>min_parallel_relation_size</> configuration parameter</primary>
3841+
<primary><varname>min_parallel_table_scan_size</> configuration parameter</primary>
38423842
</indexterm>
38433843
</term>
38443844
<listitem>
38453845
<para>
3846-
Sets the minimum size of relations to be considered for parallel scan.
3847-
The default is 8 megabytes (<literal>8MB</>).
3846+
Sets the minimum amount of table data that must be scanned in order
3847+
for a parallel scan to be considered. For a parallel sequential scan,
3848+
the amount of table data scanned is always equal to the size of the
3849+
table, but when indexes are used the amount of table data
3850+
scanned will normally be less. The default is 8
3851+
megabytes (<literal>8MB</>).
3852+
</para>
3853+
</listitem>
3854+
</varlistentry>
3855+
3856+
<varlistentry id="guc-min-parallel-index-scan-size" xreflabel="min_parallel_index_scan_size">
3857+
<term><varname>min_parallel_index_scan_size</varname> (<type>integer</type>)
3858+
<indexterm>
3859+
<primary><varname>min_parallel_index_scan_size</> configuration parameter</primary>
3860+
</indexterm>
3861+
</term>
3862+
<listitem>
3863+
<para>
3864+
Sets the minimum amount of index data that must be scanned in order
3865+
for a parallel scan to be considered. Note that a parallel index scan
3866+
typically won't touch the entire index; it is the number of pages
3867+
which the planner believes will actually be touched by the scan which
3868+
is relevant. The default is 512 kilobytes (<literal>512kB</>).
38483869
</para>
38493870
</listitem>
38503871
</varlistentry>

‎doc/src/sgml/release-9.6.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,8 +2407,8 @@ and many others in the same vein
24072407
is available through other new configuration parameters
24082408
<xref linkend="guc-force-parallel-mode">,
24092409
<xref linkend="guc-parallel-setup-cost">, <xref
2410-
linkend="guc-parallel-tuple-cost">, and <xref
2411-
linkend="guc-min-parallel-relation-size">.
2410+
linkend="guc-parallel-tuple-cost">, and
2411+
<literal>min_parallel_relation_size</literal>.
24122412
</para>
24132413
</listitem>
24142414

‎src/backend/optimizer/path/allpaths.c

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef struct pushdown_safety_info
5757
/* These parameters are set by GUC */
5858
boolenable_geqo= false;/* just in case GUC doesn't set it */
5959
intgeqo_threshold;
60-
intmin_parallel_relation_size;
60+
intmin_parallel_table_scan_size;
61+
intmin_parallel_index_scan_size;
6162

6263
/* Hook for plugins to get control in set_rel_pathlist() */
6364
set_rel_pathlist_hook_typeset_rel_pathlist_hook=NULL;
@@ -126,7 +127,8 @@ static void subquery_push_qual(Query *subquery,
126127
staticvoidrecurse_push_qual(Node*setOp,Query*topquery,
127128
RangeTblEntry*rte,Indexrti,Node*qual);
128129
staticvoidremove_unused_subquery_outputs(Query*subquery,RelOptInfo*rel);
129-
staticintcompute_parallel_worker(RelOptInfo*rel,BlockNumberpages);
130+
staticintcompute_parallel_worker(RelOptInfo*rel,BlockNumberheap_pages,
131+
BlockNumberindex_pages);
130132

131133

132134
/*
@@ -679,7 +681,7 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
679681
{
680682
intparallel_workers;
681683

682-
parallel_workers=compute_parallel_worker(rel,rel->pages);
684+
parallel_workers=compute_parallel_worker(rel,rel->pages,0);
683685

684686
/* If any limit was set to zero, the user doesn't want a parallel scan. */
685687
if (parallel_workers <=0)
@@ -2876,13 +2878,20 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
28762878

28772879
/*
28782880
* Compute the number of parallel workers that should be used to scan a
2879-
* relation. "pages" is the number of pages from the relation that we
2880-
* expect to scan.
2881+
* relation. We compute the parallel workers based on the size of the heap to
2882+
* be scanned and the size of the index to be scanned, then choose a minimum
2883+
* of those.
2884+
*
2885+
* "heap_pages" is the number of pages from the table that we expect to scan.
2886+
* "index_pages" is the number of pages from the index that we expect to scan.
28812887
*/
28822888
staticint
2883-
compute_parallel_worker(RelOptInfo*rel,BlockNumberpages)
2889+
compute_parallel_worker(RelOptInfo*rel,BlockNumberheap_pages,
2890+
BlockNumberindex_pages)
28842891
{
2885-
intparallel_workers;
2892+
intparallel_workers=0;
2893+
intheap_parallel_workers=1;
2894+
intindex_parallel_workers=1;
28862895

28872896
/*
28882897
* If the user has set the parallel_workers reloption, use that; otherwise
@@ -2892,7 +2901,8 @@ compute_parallel_worker(RelOptInfo *rel, BlockNumber pages)
28922901
parallel_workers=rel->rel_parallel_workers;
28932902
else
28942903
{
2895-
intparallel_threshold;
2904+
intheap_parallel_threshold;
2905+
intindex_parallel_threshold;
28962906

28972907
/*
28982908
* If this relation is too small to be worth a parallel scan, just
@@ -2901,25 +2911,48 @@ compute_parallel_worker(RelOptInfo *rel, BlockNumber pages)
29012911
* might not be worthwhile just for this relation, but when combined
29022912
* with all of its inheritance siblings it may well pay off.
29032913
*/
2904-
if (pages< (BlockNumber)min_parallel_relation_size&&
2914+
if (heap_pages< (BlockNumber)min_parallel_table_scan_size&&
2915+
index_pages< (BlockNumber)min_parallel_index_scan_size&&
29052916
rel->reloptkind==RELOPT_BASEREL)
29062917
return0;
29072918

2908-
/*
2909-
* Select the number of workers based on the log of the size of the
2910-
* relation. This probably needs to be a good deal more
2911-
* sophisticated, but we need something here for now. Note that the
2912-
* upper limit of the min_parallel_relation_size GUC is chosen to
2913-
* prevent overflow here.
2914-
*/
2915-
parallel_workers=1;
2916-
parallel_threshold=Max(min_parallel_relation_size,1);
2917-
while (pages >= (BlockNumber) (parallel_threshold*3))
2919+
if (heap_pages>0)
2920+
{
2921+
/*
2922+
* Select the number of workers based on the log of the size of
2923+
* the relation. This probably needs to be a good deal more
2924+
* sophisticated, but we need something here for now. Note that
2925+
* the upper limit of the min_parallel_table_scan_size GUC is
2926+
* chosen to prevent overflow here.
2927+
*/
2928+
heap_parallel_threshold=Max(min_parallel_table_scan_size,1);
2929+
while (heap_pages >= (BlockNumber) (heap_parallel_threshold*3))
2930+
{
2931+
heap_parallel_workers++;
2932+
heap_parallel_threshold *=3;
2933+
if (heap_parallel_threshold>INT_MAX /3)
2934+
break;/* avoid overflow */
2935+
}
2936+
2937+
parallel_workers=heap_parallel_workers;
2938+
}
2939+
2940+
if (index_pages>0)
29182941
{
2919-
parallel_workers++;
2920-
parallel_threshold *=3;
2921-
if (parallel_threshold>INT_MAX /3)
2922-
break;/* avoid overflow */
2942+
/* same calculation as for heap_pages above */
2943+
index_parallel_threshold=Max(min_parallel_index_scan_size,1);
2944+
while (index_pages >= (BlockNumber) (index_parallel_threshold*3))
2945+
{
2946+
index_parallel_workers++;
2947+
index_parallel_threshold *=3;
2948+
if (index_parallel_threshold>INT_MAX /3)
2949+
break;/* avoid overflow */
2950+
}
2951+
2952+
if (parallel_workers>0)
2953+
parallel_workers=Min(parallel_workers,index_parallel_workers);
2954+
else
2955+
parallel_workers=index_parallel_workers;
29232956
}
29242957
}
29252958

‎src/backend/utils/misc/guc.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,16 +2776,27 @@ static struct config_int ConfigureNamesInt[] =
27762776
},
27772777

27782778
{
2779-
{"min_parallel_relation_size",PGC_USERSET,QUERY_TUNING_COST,
2780-
gettext_noop("Sets the minimumsize ofrelations to be consideredfor parallel scan."),
2781-
NULL,
2779+
{"min_parallel_table_scan_size",PGC_USERSET,QUERY_TUNING_COST,
2780+
gettext_noop("Sets the minimumamount oftable datafor a parallel scan."),
2781+
gettext_noop("If the planner estimates that it will read a number of table pages too small to reach this limit, a parallel scan will not be considered."),
27822782
GUC_UNIT_BLOCKS,
27832783
},
2784-
&min_parallel_relation_size,
2784+
&min_parallel_table_scan_size,
27852785
(8*1024*1024) /BLCKSZ,0,INT_MAX /3,
27862786
NULL,NULL,NULL
27872787
},
27882788

2789+
{
2790+
{"min_parallel_index_scan_size",PGC_USERSET,QUERY_TUNING_COST,
2791+
gettext_noop("Sets the minimum amount of index data for a parallel scan."),
2792+
gettext_noop("If the planner estimates that it will read a number of index pages too small to reach this limit, a parallel scan will not be considered."),
2793+
GUC_UNIT_BLOCKS,
2794+
},
2795+
&min_parallel_index_scan_size,
2796+
(512*1024) /BLCKSZ,0,INT_MAX /3,
2797+
NULL,NULL,NULL
2798+
},
2799+
27892800
{
27902801
/* Can't be set in postgresql.conf */
27912802
{"server_version_num",PGC_INTERNAL,PRESET_OPTIONS,

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@
300300
#cpu_operator_cost = 0.0025# same scale as above
301301
#parallel_tuple_cost = 0.1# same scale as above
302302
#parallel_setup_cost = 1000.0# same scale as above
303-
#min_parallel_relation_size = 8MB
303+
#min_parallel_table_scan_size = 8MB
304+
#min_parallel_index_scan_size = 512kB
304305
#effective_cache_size = 4GB
305306

306307
# - Genetic Query Optimizer -

‎src/include/optimizer/paths.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
*/
2323
externboolenable_geqo;
2424
externintgeqo_threshold;
25-
externintmin_parallel_relation_size;
25+
externintmin_parallel_table_scan_size;
26+
externintmin_parallel_index_scan_size;
2627

2728
/* Hook for plugins to get control in set_rel_pathlist() */
2829
typedefvoid (*set_rel_pathlist_hook_type) (PlannerInfo*root,

‎src/test/regress/expected/select_parallel.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ begin isolation level repeatable read;
99
-- encourage use of parallel plans
1010
set parallel_setup_cost=0;
1111
set parallel_tuple_cost=0;
12-
setmin_parallel_relation_size=0;
12+
setmin_parallel_table_scan_size=0;
1313
set max_parallel_workers_per_gather=4;
1414
explain (costs off)
1515
select count(*) from a_star;

‎src/test/regress/sql/select_parallel.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ begin isolation level repeatable read;
1212
-- encourage use of parallel plans
1313
set parallel_setup_cost=0;
1414
set parallel_tuple_cost=0;
15-
setmin_parallel_relation_size=0;
15+
setmin_parallel_table_scan_size=0;
1616
set max_parallel_workers_per_gather=4;
1717

1818
explain (costs off)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp