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

Commitc0854eb

Browse files
committed
make use of function translate_col_privs()
1 parent75f2c0f commitc0854eb

File tree

4 files changed

+151
-48
lines changed

4 files changed

+151
-48
lines changed

‎src/include/pathman.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,31 @@ Oid get_pathman_config_relid(bool invalid_is_ok);
8989
Oidget_pathman_config_params_relid(boolinvalid_is_ok);
9090

9191

92-
voidset_append_rel_pathlist(PlannerInfo*root,RelOptInfo*rel,Indexrti,
93-
PathKey*pathkeyAsc,PathKey*pathkeyDesc);
94-
92+
/*
93+
* Create RelOptInfo & RTE for a selected partition.
94+
*/
9595
Indexappend_child_relation(PlannerInfo*root,Relationparent_relation,
9696
Indexparent_rti,intir_index,Oidchild_oid,
9797
List*wrappers);
9898

9999

100+
/*
101+
* Copied from PostgreSQL (prepunion.c)
102+
*/
103+
voidmake_inh_translation_list(Relationoldrelation,Relationnewrelation,
104+
Indexnewvarno,List**translated_vars);
105+
106+
Bitmapset*translate_col_privs(constBitmapset*parent_privs,
107+
List*translated_vars);
108+
109+
110+
/*
111+
* Copied from PostgreSQL (allpaths.c)
112+
*/
113+
voidset_append_rel_pathlist(PlannerInfo*root,RelOptInfo*rel,Indexrti,
114+
PathKey*pathkeyAsc,PathKey*pathkeyDesc);
115+
116+
100117
typedefstruct
101118
{
102119
constNode*orig;/* examined expression */

‎src/partition_creation.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,16 @@ create_table_using_stmt(CreateStmt *create_stmt, Oid relowner)
857857
staticvoid
858858
postprocess_child_table_and_atts(Oidparent_relid,Oidpartition_relid)
859859
{
860-
Relationpg_class_rel,
860+
Relationparent_rel,
861+
partition_rel,
862+
pg_class_rel,
861863
pg_attribute_rel;
862864

863865
TupleDescpg_class_desc,
864866
pg_attribute_desc;
865867

868+
List*translated_vars;
869+
866870
HeapTuplehtup;
867871
ScanKeyDataskey[2];
868872
SysScanDescscan;
@@ -872,6 +876,16 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
872876

873877
Snapshotsnapshot;
874878

879+
/* Both parent & partition have already been locked */
880+
parent_rel=heap_open(parent_relid,NoLock);
881+
partition_rel=heap_open(partition_relid,NoLock);
882+
883+
make_inh_translation_list(parent_rel,partition_rel,0,&translated_vars);
884+
885+
heap_close(parent_rel,NoLock);
886+
heap_close(partition_rel,NoLock);
887+
888+
/* Open catalog's relations */
875889
pg_class_rel=heap_open(RelationRelationId,RowExclusiveLock);
876890
pg_attribute_rel=heap_open(AttributeRelationId,RowExclusiveLock);
877891

@@ -914,9 +928,9 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
914928
if (HeapTupleIsValid(htup=systable_getnext(scan)))
915929
{
916930
ItemPointerDataiptr;
917-
Datumvalues[Natts_pg_class]= { (Datum)0 };
918-
boolnulls[Natts_pg_class]= { false };
919-
boolreplaces[Natts_pg_class]= { false };
931+
Datumvalues[Natts_pg_class]= { (Datum)0 };
932+
boolnulls[Natts_pg_class]= { false };
933+
boolreplaces[Natts_pg_class]= { false };
920934

921935
/* Copy ItemPointer of this tuple */
922936
iptr=htup->t_self;
@@ -950,9 +964,8 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
950964
BTEqualStrategyNumber,F_INT2GT,
951965
Int16GetDatum(InvalidAttrNumber));
952966

953-
scan=systable_beginscan(pg_attribute_rel,
954-
AttributeRelidNumIndexId,
955-
true,snapshot,2,skey);
967+
scan=systable_beginscan(pg_attribute_rel,AttributeRelidNumIndexId,
968+
true,snapshot,lengthof(skey),skey);
956969

957970
/* Go through the list of parent's columns */
958971
while (HeapTupleIsValid(htup=systable_getnext(scan)))
@@ -963,6 +976,7 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
963976

964977
AttrNumbercur_attnum;
965978
boolcur_attnum_null;
979+
Var*cur_var;
966980

967981
/* Get parent column's ACL */
968982
acl_datum=heap_getattr(htup,Anum_pg_attribute_attacl,
@@ -980,11 +994,18 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
980994
acl_column->attlen);
981995
}
982996

983-
/* Fetch number of current column */
997+
/* Fetch number of current column(parent)*/
984998
cur_attnum=DatumGetInt16(heap_getattr(htup,Anum_pg_attribute_attnum,
985999
pg_attribute_desc,&cur_attnum_null));
9861000
Assert(cur_attnum_null== false);/* must not be NULL! */
9871001

1002+
/* Fetch Var of partition's corresponding column */
1003+
cur_var= (Var*)list_nth(translated_vars,cur_attnum-1);
1004+
if (!cur_var)
1005+
continue;/* column is dropped */
1006+
1007+
Assert(cur_var->varattno!=InvalidAttrNumber);
1008+
9881009
/* Search for 'partition_relid' */
9891010
ScanKeyInit(&subskey[0],
9901011
Anum_pg_attribute_attrelid,
@@ -995,19 +1016,18 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
9951016
ScanKeyInit(&subskey[1],
9961017
Anum_pg_attribute_attnum,
9971018
BTEqualStrategyNumber,F_INT2EQ,
998-
Int16GetDatum(cur_attnum));
1019+
Int16GetDatum(cur_var->varattno));/* partition's column */
9991020

1000-
subscan=systable_beginscan(pg_attribute_rel,
1001-
AttributeRelidNumIndexId,
1002-
true,snapshot,2,subskey);
1021+
subscan=systable_beginscan(pg_attribute_rel,AttributeRelidNumIndexId,
1022+
true,snapshot,lengthof(subskey),subskey);
10031023

10041024
/* There should be exactly one tuple (our child's column) */
10051025
if (HeapTupleIsValid(subhtup=systable_getnext(subscan)))
10061026
{
10071027
ItemPointerDataiptr;
1008-
Datumvalues[Natts_pg_attribute]= { (Datum)0 };
1009-
boolnulls[Natts_pg_attribute]= { false };
1010-
boolreplaces[Natts_pg_attribute]= { false };
1028+
Datumvalues[Natts_pg_attribute]= { (Datum)0 };
1029+
boolnulls[Natts_pg_attribute]= { false };
1030+
boolreplaces[Natts_pg_attribute]= { false };
10111031

10121032
/* Copy ItemPointer of this tuple */
10131033
iptr=subhtup->t_self;

‎src/partition_filter.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include"init.h"
1212
#include"nodes_common.h"
13+
#include"pathman.h"
1314
#include"partition_creation.h"
1415
#include"partition_filter.h"
1516
#include"planner_tree_modification.h"
@@ -248,6 +249,7 @@ scan_result_parts_storage(Oid partid, ResultPartsStorage *parts_storage)
248249
*parent_rte;
249250
Indexchild_rte_idx;
250251
ResultRelInfo*child_result_rel_info;
252+
List*translated_vars;
251253

252254
/* Lock partition and check if it exists */
253255
LockRelationOid(partid,parts_storage->head_open_lock_mode);
@@ -264,16 +266,21 @@ scan_result_parts_storage(Oid partid, ResultPartsStorage *parts_storage)
264266
child_rel=heap_open(partid,NoLock);
265267
CheckValidResultRel(child_rel,parts_storage->command_type);
266268

269+
/* Build Var translation list for 'inserted_cols' */
270+
make_inh_translation_list(parent_rel,child_rel,0,&translated_vars);
271+
267272
/* Create RangeTblEntry for partition */
268273
child_rte=makeNode(RangeTblEntry);
269-
270274
child_rte->rtekind=RTE_RELATION;
271275
child_rte->relid=partid;
272276
child_rte->relkind=child_rel->rd_rel->relkind;
273277
child_rte->eref=parent_rte->eref;
274278
child_rte->requiredPerms=parent_rte->requiredPerms;
275279
child_rte->checkAsUser=parent_rte->checkAsUser;
276-
child_rte->insertedCols=parent_rte->insertedCols;
280+
child_rte->insertedCols=translate_col_privs(parent_rte->insertedCols,
281+
translated_vars);
282+
child_rte->updatedCols=translate_col_privs(parent_rte->updatedCols,
283+
translated_vars);
277284

278285
/* Check permissions for partition */
279286
ExecCheckRTPerms(list_make1(child_rte), true);

‎src/pg_pathman.c

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include"runtime_merge_append.h"
2222

2323
#include"postgres.h"
24+
#include"access/sysattr.h"
2425
#include"foreign/fdwapi.h"
2526
#include"miscadmin.h"
2627
#include"optimizer/clauses.h"
@@ -73,11 +74,6 @@ static double estimate_paramsel_using_prel(const PartRelationInfo *prel,
7374
intstrategy);
7475

7576

76-
/* Copied from PostgreSQL (prepunion.c) */
77-
staticvoidmake_inh_translation_list(Relationoldrelation,Relationnewrelation,
78-
Indexnewvarno,List**translated_vars);
79-
80-
8177
/* Copied from PostgreSQL (allpaths.c) */
8278
staticvoidset_plain_rel_size(PlannerInfo*root,
8379
RelOptInfo*rel,
@@ -240,12 +236,10 @@ append_child_relation(PlannerInfo *root, Relation parent_relation,
240236

241237
/* Create RangeTblEntry for child relation */
242238
child_rte=copyObject(parent_rte);
243-
child_rte->relid=child_oid;
244-
child_rte->relkind=child_relation->rd_rel->relkind;
245-
child_rte->inh= false;/* relation has no children */
246-
child_rte->requiredPerms=0;
247-
248-
/* FIXME: call translate_col_privs() on this RTE's column bitmapsets */
239+
child_rte->relid=child_oid;
240+
child_rte->relkind=child_relation->rd_rel->relkind;
241+
child_rte->inh= false;/* relation has no children */
242+
child_rte->requiredPerms=0;/* perform all checks on parent */
249243

250244
/* Add 'child_rte' to rtable and 'root->simple_rte_array' */
251245
root->parse->rtable=lappend(root->parse->rtable,child_rte);
@@ -261,16 +255,28 @@ append_child_relation(PlannerInfo *root, Relation parent_relation,
261255

262256
/* Build an AppendRelInfo for this child */
263257
appinfo=makeNode(AppendRelInfo);
264-
appinfo->parent_relid=parent_rti;
265-
appinfo->child_relid=childRTindex;
266-
appinfo->parent_reloid=parent_rte->relid;
258+
appinfo->parent_relid=parent_rti;
259+
appinfo->child_relid=childRTindex;
260+
appinfo->parent_reloid=parent_rte->relid;
267261

268262
make_inh_translation_list(parent_relation,child_relation,childRTindex,
269263
&appinfo->translated_vars);
270264

271265
/* Now append 'appinfo' to 'root->append_rel_list' */
272266
root->append_rel_list=lappend(root->append_rel_list,appinfo);
273267

268+
269+
if (parent_rte->relid!=child_oid)
270+
{
271+
child_rte->selectedCols=translate_col_privs(parent_rte->selectedCols,
272+
appinfo->translated_vars);
273+
child_rte->insertedCols=translate_col_privs(parent_rte->insertedCols,
274+
appinfo->translated_vars);
275+
child_rte->updatedCols=translate_col_privs(parent_rte->updatedCols,
276+
appinfo->translated_vars);
277+
}
278+
279+
274280
/* Adjust target list for this child */
275281
adjust_rel_targetlist_compat(root,child_rel,parent_rel,appinfo);
276282

@@ -352,22 +358,21 @@ append_child_relation(PlannerInfo *root, Relation parent_relation,
352358
{
353359
child_rowmark=makeNode(PlanRowMark);
354360

355-
child_rowmark->rti=childRTindex;
356-
child_rowmark->prti=parent_rti;
357-
child_rowmark->rowmarkId=parent_rowmark->rowmarkId;
361+
child_rowmark->rti=childRTindex;
362+
child_rowmark->prti=parent_rti;
363+
child_rowmark->rowmarkId=parent_rowmark->rowmarkId;
358364
/* Reselect rowmark type, because relkind might not match parent */
359-
child_rowmark->markType=select_rowmark_type(child_rte,
360-
parent_rowmark->strength);
361-
child_rowmark->allMarkTypes= (1 <<child_rowmark->markType);
362-
child_rowmark->strength=parent_rowmark->strength;
363-
child_rowmark->waitPolicy=parent_rowmark->waitPolicy;
364-
child_rowmark->isParent= false;
365-
366-
/* Include child's rowmark type in parent's allMarkTypes */
367-
parent_rowmark->allMarkTypes |=child_rowmark->allMarkTypes;
365+
child_rowmark->markType=select_rowmark_type(child_rte,
366+
parent_rowmark->strength);
367+
child_rowmark->allMarkTypes= (1 <<child_rowmark->markType);
368+
child_rowmark->strength=parent_rowmark->strength;
369+
child_rowmark->waitPolicy=parent_rowmark->waitPolicy;
370+
child_rowmark->isParent= false;
368371

369372
root->rowMarks=lappend(root->rowMarks,child_rowmark);
370373

374+
/* Include child's rowmark type in parent's allMarkTypes */
375+
parent_rowmark->allMarkTypes |=child_rowmark->allMarkTypes;
371376
parent_rowmark->isParent= true;
372377
}
373378

@@ -1572,14 +1577,69 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
15721577
}
15731578
}
15741579

1580+
1581+
/*
1582+
* translate_col_privs
1583+
* Translate a bitmapset representing per-column privileges from the
1584+
* parent rel's attribute numbering to the child's.
1585+
*
1586+
* The only surprise here is that we don't translate a parent whole-row
1587+
* reference into a child whole-row reference. That would mean requiring
1588+
* permissions on all child columns, which is overly strict, since the
1589+
* query is really only going to reference the inherited columns. Instead
1590+
* we set the per-column bits for all inherited columns.
1591+
*/
1592+
Bitmapset*
1593+
translate_col_privs(constBitmapset*parent_privs,
1594+
List*translated_vars)
1595+
{
1596+
Bitmapset*child_privs=NULL;
1597+
boolwhole_row;
1598+
intattno;
1599+
ListCell*lc;
1600+
1601+
/* System attributes have the same numbers in all tables */
1602+
for (attno=FirstLowInvalidHeapAttributeNumber+1;attno<0;attno++)
1603+
{
1604+
if (bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
1605+
parent_privs))
1606+
child_privs=bms_add_member(child_privs,
1607+
attno-FirstLowInvalidHeapAttributeNumber);
1608+
}
1609+
1610+
/* Check if parent has whole-row reference */
1611+
whole_row=bms_is_member(InvalidAttrNumber-FirstLowInvalidHeapAttributeNumber,
1612+
parent_privs);
1613+
1614+
/* And now translate the regular user attributes, using the vars list */
1615+
attno=InvalidAttrNumber;
1616+
foreach(lc,translated_vars)
1617+
{
1618+
Var*var= (Var*)lfirst(lc);
1619+
1620+
attno++;
1621+
if (var==NULL)/* ignore dropped columns */
1622+
continue;
1623+
Assert(IsA(var,Var));
1624+
if (whole_row||
1625+
bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
1626+
parent_privs))
1627+
child_privs=bms_add_member(child_privs,
1628+
var->varattno-FirstLowInvalidHeapAttributeNumber);
1629+
}
1630+
1631+
returnchild_privs;
1632+
}
1633+
1634+
15751635
/*
15761636
* make_inh_translation_list
15771637
* Build the list of translations from parent Vars to child Vars for
15781638
* an inheritance child.
15791639
*
15801640
* For paranoia's sake, we match type/collation as well as attribute name.
15811641
*/
1582-
staticvoid
1642+
void
15831643
make_inh_translation_list(Relationoldrelation,Relationnewrelation,
15841644
Indexnewvarno,List**translated_vars)
15851645
{
@@ -1685,7 +1745,6 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
16851745
*translated_vars=vars;
16861746
}
16871747

1688-
16891748
/*
16901749
* set_append_rel_pathlist
16911750
* Build access paths for an "append relation"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp