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

Commitc70a71a

Browse files
committed
acquire suitable lock in append_child_relation()
1 parent5c36a5d commitc70a71a

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

‎src/hooks.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include"catalog/pg_authid.h"
3030
#include"miscadmin.h"
3131
#include"optimizer/cost.h"
32+
#include"optimizer/prep.h"
3233
#include"optimizer/restrictinfo.h"
3334
#include"rewrite/rewriteManip.h"
3435
#include"utils/typcache.h"
@@ -290,6 +291,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
290291
if ((prel=get_pathman_relation_info(rte->relid))!=NULL)
291292
{
292293
Relationparent_rel;/* parent's relation (heap) */
294+
PlanRowMark*parent_rowmark;/* parent's rowmark */
293295
Oid*children;/* selected children oids */
294296
List*ranges,/* a list of IndexRanges */
295297
*wrappers;/* a list of WrapperNodes */
@@ -305,6 +307,9 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
305307
/* Make copy of partitioning expression and fix Var's varno attributes */
306308
part_expr=PrelExpressionForRelid(prel,rti);
307309

310+
/* Get partitioning-related clauses (do this before append_child_relation()) */
311+
part_clauses=get_partitioning_clauses(rel->baserestrictinfo,prel,rti);
312+
308313
if (prel->parttype==PT_RANGE)
309314
{
310315
/*
@@ -382,19 +387,25 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
382387
/* Parent has already been locked by rewriter */
383388
parent_rel=heap_open(rte->relid,NoLock);
384389

385-
/* Add parent if asked to */
386-
if (prel->enable_parent)
387-
append_child_relation(root,parent_rel,rti,0,rte->relid,NULL);
390+
parent_rowmark=get_plan_rowmark(root->rowMarks,rti);
388391

389392
/*
390-
*Iterate all indexes in rangeset and append corresponding child relations.
393+
*WARNING: 'prel' might become invalid after append_child_relation().
391394
*/
395+
396+
/* Add parent if asked to */
397+
if (prel->enable_parent)
398+
append_child_relation(root,parent_rel,parent_rowmark,
399+
rti,0,rte->relid,NULL);
400+
401+
/* Iterate all indexes in rangeset and append child relations */
392402
foreach(lc,ranges)
393403
{
394404
IndexRangeirange=lfirst_irange(lc);
395405

396406
for (i=irange_lower(irange);i <=irange_upper(irange);i++)
397-
append_child_relation(root,parent_rel,rti,i,children[i],wrappers);
407+
append_child_relation(root,parent_rel,parent_rowmark,
408+
rti,i,children[i],wrappers);
398409
}
399410

400411
/* Now close parent relation */
@@ -424,9 +435,6 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
424435
pg_pathman_enable_runtime_merge_append))
425436
return;
426437

427-
/* Get partitioning-related clauses */
428-
part_clauses=get_partitioning_clauses(rel->baserestrictinfo,prel,rti);
429-
430438
/* Skip if there's no PARAMs in partitioning-related clauses */
431439
if (!clause_contains_params((Node*)part_clauses))
432440
return;

‎src/include/pathman.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ Oid get_pathman_config_params_relid(bool invalid_is_ok);
105105
/*
106106
* Create RelOptInfo & RTE for a selected partition.
107107
*/
108-
Indexappend_child_relation(PlannerInfo*root,Relationparent_relation,
109-
Indexparent_rti,intir_index,Oidchild_oid,
108+
Indexappend_child_relation(PlannerInfo*root,
109+
Relationparent_relation,
110+
PlanRowMark*parent_rowmark,
111+
Indexparent_rti,
112+
intir_index,
113+
Oidchild_oid,
110114
List*wrappers);
111115

112116

‎src/pg_pathman.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#include"optimizer/restrictinfo.h"
3131
#include"optimizer/cost.h"
3232
#include"utils/datum.h"
33-
#include"utils/lsyscache.h"
3433
#include"utils/rel.h"
34+
#include"utils/lsyscache.h"
35+
#include"utils/syscache.h"
3536
#include"utils/selfuncs.h"
3637
#include"utils/typcache.h"
3738

@@ -364,8 +365,12 @@ get_pathman_config_params_relid(bool invalid_is_ok)
364365
* NOTE: partially based on the expand_inherited_rtentry() function.
365366
*/
366367
Index
367-
append_child_relation(PlannerInfo*root,Relationparent_relation,
368-
Indexparent_rti,intir_index,Oidchild_oid,
368+
append_child_relation(PlannerInfo*root,
369+
Relationparent_relation,
370+
PlanRowMark*parent_rowmark,
371+
Indexparent_rti,
372+
intir_index,
373+
Oidchild_oid,
369374
List*wrappers)
370375
{
371376
RangeTblEntry*parent_rte,
@@ -375,17 +380,35 @@ append_child_relation(PlannerInfo *root, Relation parent_relation,
375380
Relationchild_relation;
376381
AppendRelInfo*appinfo;
377382
IndexchildRTindex;
378-
PlanRowMark*parent_rowmark,
379-
*child_rowmark;
383+
PlanRowMark*child_rowmark;
380384
Node*childqual;
381385
List*childquals;
382386
ListCell*lc1,
383387
*lc2;
388+
LOCKMODElockmode;
389+
390+
/* Choose a correct lock mode */
391+
if (parent_rti==root->parse->resultRelation)
392+
lockmode=RowExclusiveLock;
393+
elseif (parent_rowmark&&RowMarkRequiresRowShareLock(parent_rowmark->markType))
394+
lockmode=RowShareLock;
395+
else
396+
lockmode=AccessShareLock;
397+
398+
/* Acquire a suitable lock on partition */
399+
LockRelationOid(child_oid,lockmode);
400+
401+
/* Check that partition exists */
402+
if (!SearchSysCacheExists1(RELOID,ObjectIdGetDatum(child_oid)))
403+
{
404+
UnlockRelationOid(child_oid,lockmode);
405+
return0;
406+
}
384407

385408
parent_rel=root->simple_rel_array[parent_rti];
386409
parent_rte=root->simple_rte_array[parent_rti];
387410

388-
/*FIXME: acquire a suitable lock on partition */
411+
/*Open child relation (we've just locked it) */
389412
child_relation=heap_open(child_oid,NoLock);
390413

391414
/* Create RangeTblEntry for child relation */
@@ -408,7 +431,6 @@ append_child_relation(PlannerInfo *root, Relation parent_relation,
408431

409432

410433
/* Create rowmarks required for child rels */
411-
parent_rowmark=get_plan_rowmark(root->rowMarks,parent_rti);
412434
if (parent_rowmark)
413435
{
414436
child_rowmark=makeNode(PlanRowMark);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp