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

Commit21d4e2e

Browse files
Reduce lock levels for table storage params related to planning
The following parameters are now updateable with ShareUpdateExclusiveLockeffective_io_concurrencyparallel_workersseq_page_costrandom_page_costn_distinctn_distinct_inheritedSimon Riggs and Fabrízio Mello
1 parent8b4d582 commit21d4e2e

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

‎src/backend/access/common/reloptions.c

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,46 @@
4848
* (iii) add it to the appropriate options struct (perhaps StdRdOptions)
4949
* (iv) add it to the appropriate handling routine (perhaps
5050
* default_reloptions)
51-
* (v) don't forget to document the option
51+
* (v) make sure the lock level is set correctly for that operation
52+
* (vi) don't forget to document the option
5253
*
5354
* Note that we don't handle "oids" in relOpts because it is handled by
5455
* interpretOidsOption().
56+
*
57+
* The default choice for any new option should be AccessExclusiveLock.
58+
* In some cases the lock level can be reduced from there, but the lock
59+
* level chosen should always conflict with itself to ensure that multiple
60+
* changes aren't lost when we attempt concurrent changes.
61+
* The choice of lock level depends completely upon how that parameter
62+
* is used within the server, not upon how and when you'd like to change it.
63+
* Safety first. Existing choices are documented here, and elsewhere in
64+
* backend code where the parameters are used.
65+
*
66+
* In general, anything that affects the results obtained from a SELECT must be
67+
* protected by AccessExclusiveLock.
68+
*
69+
* Autovacuum related parameters can be set at ShareUpdateExclusiveLock
70+
* since they are only used by the AV procs and don't change anything
71+
* currently executing.
72+
*
73+
* Fillfactor can be set because it applies only to subsequent changes made to
74+
* data blocks, as documented in heapio.c
75+
*
76+
* n_distinct options can be set at ShareUpdateExclusiveLock because they
77+
* are only used during ANALYZE, which uses a ShareUpdateExclusiveLock,
78+
* so the ANALYZE will not be affected by in-flight changes. Changing those
79+
* values has no affect until the next ANALYZE, so no need for stronger lock.
80+
*
81+
* Planner-related parameters can be set with ShareUpdateExclusiveLock because
82+
* they only affect planning and not the correctness of the execution. Plans
83+
* cannot be changed in mid-flight, so changes here could not easily result in
84+
* new improved plans in any case. So we allow existing queries to continue
85+
* and existing plans to survive, a small price to pay for allowing better
86+
* plans to be introduced concurrently without interfering with users.
87+
*
88+
* Setting parallel_workers is safe, since it acts the same as
89+
* max_parallel_workers_per_gather which is a USERSET parameter that doesn't
90+
* affect existing plans or queries.
5591
*/
5692

5793
staticrelopt_boolboolRelOpts[]=
@@ -267,7 +303,7 @@ static relopt_int intRelOpts[] =
267303
"effective_io_concurrency",
268304
"Number of simultaneous requests that can be handled efficiently by the disk subsystem.",
269305
RELOPT_KIND_TABLESPACE,
270-
AccessExclusiveLock
306+
ShareUpdateExclusiveLock
271307
},
272308
#ifdefUSE_PREFETCH
273309
-1,0,MAX_IO_CONCURRENCY
@@ -280,7 +316,7 @@ static relopt_int intRelOpts[] =
280316
"parallel_workers",
281317
"Number of parallel processes that can be used per executor node for this relation.",
282318
RELOPT_KIND_HEAP,
283-
AccessExclusiveLock
319+
ShareUpdateExclusiveLock
284320
},
285321
-1,0,1024
286322
},
@@ -314,7 +350,7 @@ static relopt_real realRelOpts[] =
314350
"seq_page_cost",
315351
"Sets the planner's estimate of the cost of a sequentially fetched disk page.",
316352
RELOPT_KIND_TABLESPACE,
317-
AccessExclusiveLock
353+
ShareUpdateExclusiveLock
318354
},
319355
-1,0.0,DBL_MAX
320356
},
@@ -323,7 +359,7 @@ static relopt_real realRelOpts[] =
323359
"random_page_cost",
324360
"Sets the planner's estimate of the cost of a nonsequentially fetched disk page.",
325361
RELOPT_KIND_TABLESPACE,
326-
AccessExclusiveLock
362+
ShareUpdateExclusiveLock
327363
},
328364
-1,0.0,DBL_MAX
329365
},
@@ -332,7 +368,7 @@ static relopt_real realRelOpts[] =
332368
"n_distinct",
333369
"Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations).",
334370
RELOPT_KIND_ATTRIBUTE,
335-
AccessExclusiveLock
371+
ShareUpdateExclusiveLock
336372
},
337373
0,-1.0,DBL_MAX
338374
},
@@ -341,7 +377,7 @@ static relopt_real realRelOpts[] =
341377
"n_distinct_inherited",
342378
"Sets the planner's estimate of the number of distinct values appearing in a column (including child relations).",
343379
RELOPT_KIND_ATTRIBUTE,
344-
AccessExclusiveLock
380+
ShareUpdateExclusiveLock
345381
},
346382
0,-1.0,DBL_MAX
347383
},

‎src/backend/utils/cache/spccache.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ get_tablespace(Oid spcid)
173173
/*
174174
* get_tablespace_page_costs
175175
*Return random and/or sequential page costs for a given tablespace.
176+
*
177+
*This value is not locked by the transaction, so this value may
178+
*be changed while a SELECT that has used these values for planning
179+
*is still executing.
176180
*/
177181
void
178182
get_tablespace_page_costs(Oidspcid,
@@ -200,6 +204,13 @@ get_tablespace_page_costs(Oid spcid,
200204
}
201205
}
202206

207+
/*
208+
* get_tablespace_io_concurrency
209+
*
210+
*This value is not locked by the transaction, so this value may
211+
*be changed while a SELECT that has used these values for planning
212+
*is still executing.
213+
*/
203214
int
204215
get_tablespace_io_concurrency(Oidspcid)
205216
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp