MCPcopy Create free account
hub / github.com/apache/cloudberry / GpFindTargetPartition

Function GpFindTargetPartition

src/backend/commands/tablecmds_gp.c:128–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128static Oid
129GpFindTargetPartition(Relation parent, GpAlterPartitionId *partid,
130 bool missing_ok)
131{
132 Oid target_relid = InvalidOid;
133
134 switch (partid->idtype)
135 {
136 case AT_AP_IDDefault:
137 /* Find default partition */
138 target_relid =
139 get_default_oid_from_partdesc(RelationGetPartitionDesc(parent, false));
140 if (!OidIsValid(target_relid) && !missing_ok)
141 ereport(ERROR,
142 (errcode(ERRCODE_UNDEFINED_OBJECT),
143 errmsg("DEFAULT partition of relation \"%s\" does not exist",
144 RelationGetRelationName(parent))));
145 break;
146 case AT_AP_IDName:
147 {
148 /*
149 * Find partition by name.
150 * After PG12 merge, users may use pg syntax to do the partition maintenance,
151 * like ALTER TABLE ... DETACH/ATTACH PARTITION.
152 * This may cause the partition table's name different from GPDB's partition
153 * table name pattern <parentname>_<level>_prt_<partition_name>.
154 * When this happens, it's not possible to find the target partition table based
155 * on the name specified by the user.
156 *
157 * And if user do use the GPDB's syntax, we still have cases that the partition
158 * table's namespace different from it's parent namespace. See issue:
159 * https://github.com/greenplum-db/gpdb/issues/9903.
160 * Users could always use PARTITION FOR or pg syntax instead.
161 */
162 RangeVar *partrv;
163 char *schemaname;
164 char *partname;
165 Relation partRel;
166 char partsubstring[NAMEDATALEN];
167 List *ancestors = get_partition_ancestors(RelationGetRelid(parent));
168 int level = list_length(ancestors) + 1;
169 char levelStr[NAMEDATALEN];
170
171 snprintf(levelStr, NAMEDATALEN, "%d", level);
172 snprintf(partsubstring, NAMEDATALEN, "prt_%s",
173 strVal(partid->partiddef));
174
175 partname = makeObjectName(RelationGetRelationName(parent),
176 levelStr, partsubstring);
177
178 schemaname = get_namespace_name(parent->rd_rel->relnamespace);
179 partrv = makeRangeVar(schemaname, partname, -1);
180 partRel = table_openrv_extended(partrv, AccessShareLock, missing_ok);
181 if (partRel)
182 {
183 if (partRel->rd_rel->relispartition)
184 {
185 bool found = false;

Callers 3

AtExecGPSplitPartitionFunction · 0.85
ATExecGPPartCmdsFunction · 0.85

Calls 15

RelationGetPartitionDescFunction · 0.85
get_partition_ancestorsFunction · 0.85
list_lengthFunction · 0.85
makeObjectNameFunction · 0.85
get_namespace_nameFunction · 0.85
makeRangeVarFunction · 0.85
table_openrv_extendedFunction · 0.85
table_closeFunction · 0.85
get_partition_for_tupleFunction · 0.85
RelationGetPartitionKeyFunction · 0.85

Tested by

no test coverage detected