aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2022-11-29 09:39:36 +0100
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2022-11-29 09:39:36 +0100
commitad86d159b6ab90b195b06fb5c7b593900a7f9cd8 (patch)
treeacea26f7f4dd2c3bfd2e17dea81d3bc616926594 /src/backend/commands
parent00ae5d6f588e9d21fa4f4d267811f3f602fe45af (diff)
downloadpostgresql-ad86d159b6ab90b195b06fb5c7b593900a7f9cd8.tar.gz
postgresql-ad86d159b6ab90b195b06fb5c7b593900a7f9cd8.zip
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
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/indexcmds.c3
-rw-r--r--src/backend/commands/tablecmds.c24
2 files changed, 18 insertions, 9 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 91cee27743d..b5b860c3abf 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1290,7 +1290,8 @@ DefineIndex(Oid relationId,
childidxs = RelationGetIndexList(childrel);
attmap =
build_attrmap_by_name(RelationGetDescr(childrel),
- parentDesc);
+ parentDesc,
+ false);
foreach(cell, childidxs)
{
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 845208d662b..10c1955884f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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,