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

Function RelationBuildPartitionKey

src/backend/utils/cache/partcache.c:80–268  ·  view source on GitHub ↗

* RelationBuildPartitionKey * Build partition key data of relation, and attach to relcache * * Partitioning key data is a complex structure; to avoid complicated logic to * free individual elements whenever the relcache entry is flushed, we give it * its own memory context, a child of CacheMemoryContext, which can easily be * deleted on its own. To avoid leaking memory in that context in c

Source from the content-addressed store, hash-verified

78 * permanently.
79 */
80static void
81RelationBuildPartitionKey(Relation relation)
82{
83 Form_pg_partitioned_table form;
84 HeapTuple tuple;
85 bool isnull;
86 int i;
87 PartitionKey key;
88 AttrNumber *attrs;
89 oidvector *opclass;
90 oidvector *collation;
91 ListCell *partexprs_item;
92 Datum datum;
93 MemoryContext partkeycxt,
94 oldcxt;
95 int16 procnum;
96
97 tuple = SearchSysCache1(PARTRELID,
98 ObjectIdGetDatum(RelationGetRelid(relation)));
99
100 if (!HeapTupleIsValid(tuple))
101 elog(ERROR, "cache lookup failed for partition key of relation %u",
102 RelationGetRelid(relation));
103
104 partkeycxt = AllocSetContextCreate(CurTransactionContext,
105 "partition key",
106 ALLOCSET_SMALL_SIZES);
107 MemoryContextCopyAndSetIdentifier(partkeycxt,
108 RelationGetRelationName(relation));
109
110 key = (PartitionKey) MemoryContextAllocZero(partkeycxt,
111 sizeof(PartitionKeyData));
112
113 /* Fixed-length attributes */
114 form = (Form_pg_partitioned_table) GETSTRUCT(tuple);
115 key->strategy = form->partstrat;
116 key->partnatts = form->partnatts;
117
118 /*
119 * We can rely on the first variable-length attribute being mapped to the
120 * relevant field of the catalog's C struct, because all previous
121 * attributes are non-nullable and fixed-length.
122 */
123 attrs = form->partattrs.values;
124
125 /* But use the hard way to retrieve further variable-length attributes */
126 /* Operator class */
127 datum = SysCacheGetAttr(PARTRELID, tuple,
128 Anum_pg_partitioned_table_partclass, &isnull);
129 Assert(!isnull);
130 opclass = (oidvector *) DatumGetPointer(datum);
131
132 /* Collation */
133 datum = SysCacheGetAttr(PARTRELID, tuple,
134 Anum_pg_partitioned_table_partcollation, &isnull);
135 Assert(!isnull);
136 collation = (oidvector *) DatumGetPointer(datum);
137

Callers 1

RelationGetPartitionKeyFunction · 0.85

Calls 15

SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
MemoryContextAllocZeroFunction · 0.85
SysCacheGetAttrFunction · 0.85
stringToNodeFunction · 0.85
eval_const_expressionsFunction · 0.85
fix_opfuncidsFunction · 0.85
MemoryContextSwitchToFunction · 0.85
list_headFunction · 0.85
get_opfamily_procFunction · 0.85
format_type_beFunction · 0.85
fmgr_info_cxtFunction · 0.85

Tested by

no test coverage detected