aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/indexcmds.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:31:56 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:45:03 +0200
commit5015e1e1b58f81a036e4ad16291ef4b3bb7a596c (patch)
tree86ee608e961dc830e733c534db089f1e45706414 /src/backend/commands/indexcmds.c
parent2016055a92f26d648aba9f66d26cc0bcd1619eff (diff)
downloadpostgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.tar.gz
postgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.zip
Assorted examples of expanded type-safer palloc/pg_malloc API
This adds some uses of the new palloc/pg_malloc variants here and there as a demonstration and test. This is kept separate from the actual API patch, since the latter might be backpatched at some point. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r--src/backend/commands/indexcmds.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 3c6e09815e0..9167bab0c55 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -229,10 +229,10 @@ CheckIndexCompatible(Oid oldId,
*/
indexInfo = makeIndexInfo(numberOfAttributes, numberOfAttributes,
accessMethodId, NIL, NIL, false, false, false, false);
- typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- classObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- coloptions = (int16 *) palloc(numberOfAttributes * sizeof(int16));
+ typeObjectId = palloc_array(Oid, numberOfAttributes);
+ collationObjectId = palloc_array(Oid, numberOfAttributes);
+ classObjectId = palloc_array(Oid, numberOfAttributes);
+ coloptions = palloc_array(int16, numberOfAttributes);
ComputeIndexAttrs(indexInfo,
typeObjectId, collationObjectId, classObjectId,
coloptions, attributeList,
@@ -895,10 +895,10 @@ DefineIndex(Oid relationId,
!concurrent,
concurrent);
- typeObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- classObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
- coloptions = (int16 *) palloc(numberOfAttributes * sizeof(int16));
+ typeObjectId = palloc_array(Oid, numberOfAttributes);
+ collationObjectId = palloc_array(Oid, numberOfAttributes);
+ classObjectId = palloc_array(Oid, numberOfAttributes);
+ coloptions = palloc_array(int16, numberOfAttributes);
ComputeIndexAttrs(indexInfo,
typeObjectId, collationObjectId, classObjectId,
coloptions, allIndexParams,
@@ -1210,7 +1210,7 @@ DefineIndex(Oid relationId,
if ((!stmt->relation || stmt->relation->inh) && partdesc->nparts > 0)
{
int nparts = partdesc->nparts;
- Oid *part_oids = palloc(sizeof(Oid) * nparts);
+ Oid *part_oids = palloc_array(Oid, nparts);
bool invalidate_parent = false;
Relation parentIndex;
TupleDesc parentDesc;
@@ -1786,9 +1786,9 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
if (exclusionOpNames)
{
Assert(list_length(exclusionOpNames) == nkeycols);
- indexInfo->ii_ExclusionOps = (Oid *) palloc(sizeof(Oid) * nkeycols);
- indexInfo->ii_ExclusionProcs = (Oid *) palloc(sizeof(Oid) * nkeycols);
- indexInfo->ii_ExclusionStrats = (uint16 *) palloc(sizeof(uint16) * nkeycols);
+ indexInfo->ii_ExclusionOps = palloc_array(Oid, nkeycols);
+ indexInfo->ii_ExclusionProcs = palloc_array(Oid, nkeycols);
+ indexInfo->ii_ExclusionStrats = palloc_array(uint16, nkeycols);
nextExclOp = list_head(exclusionOpNames);
}
else
@@ -2112,7 +2112,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
if (!indexInfo->ii_OpclassOptions)
indexInfo->ii_OpclassOptions =
- palloc0(sizeof(Datum) * indexInfo->ii_NumIndexAttrs);
+ palloc0_array(Datum, indexInfo->ii_NumIndexAttrs);
indexInfo->ii_OpclassOptions[attn] =
transformRelOptions((Datum) 0, attribute->opclassopts,
@@ -3459,7 +3459,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
/* Save the list of relation OIDs in private context */
oldcontext = MemoryContextSwitchTo(private_context);
- idx = palloc(sizeof(ReindexIndexInfo));
+ idx = palloc_object(ReindexIndexInfo);
idx->indexId = cellOid;
/* other fields set later */
@@ -3508,7 +3508,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
*/
oldcontext = MemoryContextSwitchTo(private_context);
- idx = palloc(sizeof(ReindexIndexInfo));
+ idx = palloc_object(ReindexIndexInfo);
idx->indexId = cellOid;
indexIds = lappend(indexIds, idx);
/* other fields set later */
@@ -3589,7 +3589,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
* Save the list of relation OIDs in private context. Note
* that invalid indexes are allowed here.
*/
- idx = palloc(sizeof(ReindexIndexInfo));
+ idx = palloc_object(ReindexIndexInfo);
idx->indexId = relationOid;
indexIds = lappend(indexIds, idx);
/* other fields set later */
@@ -3734,7 +3734,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
*/
oldcontext = MemoryContextSwitchTo(private_context);
- newidx = palloc(sizeof(ReindexIndexInfo));
+ newidx = palloc_object(ReindexIndexInfo);
newidx->indexId = newIndexId;
newidx->safe = idx->safe;
newidx->tableId = idx->tableId;
@@ -3748,10 +3748,10 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
* avoid multiple locks taken on the same relation, instead we rely on
* parentRelationIds built earlier.
*/
- lockrelid = palloc(sizeof(*lockrelid));
+ lockrelid = palloc_object(LockRelId);
*lockrelid = indexRel->rd_lockInfo.lockRelId;
relationLocks = lappend(relationLocks, lockrelid);
- lockrelid = palloc(sizeof(*lockrelid));
+ lockrelid = palloc_object(LockRelId);
*lockrelid = newIndexRel->rd_lockInfo.lockRelId;
relationLocks = lappend(relationLocks, lockrelid);
@@ -3783,11 +3783,11 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
oldcontext = MemoryContextSwitchTo(private_context);
/* Add lockrelid of heap relation to the list of locked relations */
- lockrelid = palloc(sizeof(*lockrelid));
+ lockrelid = palloc_object(LockRelId);
*lockrelid = heapRelation->rd_lockInfo.lockRelId;
relationLocks = lappend(relationLocks, lockrelid);
- heaplocktag = (LOCKTAG *) palloc(sizeof(LOCKTAG));
+ heaplocktag = palloc_object(LOCKTAG);
/* Save the LOCKTAG for this parent relation for the wait phase */
SET_LOCKTAG_RELATION(*heaplocktag, lockrelid->dbId, lockrelid->relId);