Skip to content

Commit

Permalink
remove MemoryContextContains
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-v-kush authored Dec 19, 2024
1 parent fcc3292 commit b62f15e
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions columnar/src/backend/columnar/columnar_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,34 +1195,6 @@ FreeChunkData(ChunkData *chunkData)
pfree(chunkData);
}

#if PG_VERSION_NUM >= PG_VERSION_16
/* Copied from postgres 15 source, since it was removed from 16. */
static bool
MemoryContextContains(MemoryContext context, void *pointer)
{
MemoryContext ptr_context;

/*
* NB: Can't use GetMemoryChunkContext() here - that performs assertions
* that aren't acceptable here since we might be passed memory not
* allocated by any memory context.
*
* Try to detect bogus pointers handed to us, poorly though we can.
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
* allocated chunk.
*/
if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
return false;

/*
* OK, it's probably safe to look at the context.
*/
ptr_context = *(MemoryContext *) (((char *) pointer) - sizeof(void *));

return ptr_context == context;
}
#endif

/* FreeChunkValueArrayBuffer relase valueBufferArray memory. */
void FreeChunkBufferValueArray(ChunkData *chunkData)
{
Expand All @@ -1235,7 +1207,7 @@ void FreeChunkBufferValueArray(ChunkData *chunkData)

for (columnIndex = 0; columnIndex < chunkData->columnCount; columnIndex++)
{
if (chunkData->valueBufferArray[columnIndex] != NULL && !MemoryContextContains(ColumnarCacheMemoryContext(), chunkData->valueBufferArray[columnIndex]))
if (chunkData->valueBufferArray[columnIndex] != NULL)
{
pfree(chunkData->valueBufferArray[columnIndex]->data);
pfree(chunkData->valueBufferArray[columnIndex]);
Expand Down Expand Up @@ -1957,11 +1929,12 @@ DeserializeChunkData(StripeBuffers *stripeBuffers, uint64 chunkIndex,

if(shouldCache)
{
/* store current chunk's data buffer to be freed at next chunk read */
/* valueBuffer will be freed in cache */
chunkData->valueBufferArray[columnIndex] = NULL;
}
else
{
/* store current chunk's data buffer to be freed at next chunk read */
chunkData->valueBufferArray[columnIndex] = valueBuffer;
}
}
Expand Down

0 comments on commit b62f15e

Please sign in to comment.