1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Add 'missing_ok' argument to build_attrmap_by_name

When it's given as true, return a 0 in the position of the missing
column rather than raising an error.

This is currently unused, but it allows us to reimplement column
permission checking in a subsequent commit.  It seems worth breaking
into a separate commit because it affects unrelated code.

Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqFfiai=qBxPDTjaio_ZcaqUKh+FC=prESrB8ogZgFNNNQ@mail.gmail.com
This commit is contained in:
Alvaro Herrera
2022-11-29 09:39:36 +01:00
parent 00ae5d6f58
commit ad86d159b6
10 changed files with 55 additions and 28 deletions

View File

@ -1206,7 +1206,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
}
attmap = build_attrmap_by_name(RelationGetDescr(rel),
RelationGetDescr(parent));
RelationGetDescr(parent),
false);
idxstmt =
generateClonedIndexStmt(NULL, idxRel,
attmap, &constraintOid);
@ -9647,7 +9648,8 @@ addFkRecurseReferenced(List **wqueue, Constraint *fkconstraint, Relation rel,
* definition to match the partition's column layout.
*/
map = build_attrmap_by_name_if_req(RelationGetDescr(partRel),
RelationGetDescr(pkrel));
RelationGetDescr(pkrel),
false);
if (map)
{
mapped_pkattnum = palloc(sizeof(AttrNumber) * numfks);
@ -9814,7 +9816,8 @@ addFkRecurseReferencing(List **wqueue, Constraint *fkconstraint, Relation rel,
CheckTableNotInUse(partition, "ALTER TABLE");
attmap = build_attrmap_by_name(RelationGetDescr(partition),
RelationGetDescr(rel));
RelationGetDescr(rel),
false);
for (int j = 0; j < numfks; j++)
mapped_fkattnum[j] = attmap->attnums[fkattnum[j] - 1];
@ -10022,7 +10025,8 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
trigrel = table_open(TriggerRelationId, RowExclusiveLock);
attmap = build_attrmap_by_name(RelationGetDescr(partitionRel),
RelationGetDescr(parentRel));
RelationGetDescr(parentRel),
false);
foreach(cell, clone)
{
Oid constrOid = lfirst_oid(cell);
@ -10219,7 +10223,8 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
* different. This map is used to convert them.
*/
attmap = build_attrmap_by_name(RelationGetDescr(partRel),
RelationGetDescr(parentRel));
RelationGetDescr(parentRel),
false);
partFKs = copyObject(RelationGetFKeyList(partRel));
@ -12335,7 +12340,8 @@ ATPrepAlterColumnType(List **wqueue,
cmd = copyObject(cmd);
attmap = build_attrmap_by_name(RelationGetDescr(childrel),
RelationGetDescr(rel));
RelationGetDescr(rel),
false);
((ColumnDef *) cmd->def)->cooked_default =
map_variable_attnos(def->cooked_default,
1, 0,
@ -18043,7 +18049,8 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
/* construct an indexinfo to compare existing indexes against */
info = BuildIndexInfo(idxRel);
attmap = build_attrmap_by_name(RelationGetDescr(attachrel),
RelationGetDescr(rel));
RelationGetDescr(rel),
false);
constraintOid = get_relation_idx_constraint_oid(RelationGetRelid(rel), idx);
/*
@ -18981,7 +18988,8 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
childInfo = BuildIndexInfo(partIdx);
parentInfo = BuildIndexInfo(parentIdx);
attmap = build_attrmap_by_name(RelationGetDescr(partTbl),
RelationGetDescr(parentTbl));
RelationGetDescr(parentTbl),
false);
if (!CompareIndexInfo(childInfo, parentInfo,
partIdx->rd_indcollation,
parentIdx->rd_indcollation,