mirror of https://github.com/citusdata/citus.git
Pull memory allocation out of while loop
parent
a2de41fe14
commit
71f8dd28b8
|
@ -727,6 +727,9 @@ FilterAndPartitionTable(const char *filterQuery,
|
||||||
Portal queryPortal = NULL;
|
Portal queryPortal = NULL;
|
||||||
int connected = 0;
|
int connected = 0;
|
||||||
int finished = 0;
|
int finished = 0;
|
||||||
|
uint32 columnCount = 0;
|
||||||
|
Datum *valueArray = NULL;
|
||||||
|
bool *isNullArray = NULL;
|
||||||
|
|
||||||
const char *noPortalName = NULL;
|
const char *noPortalName = NULL;
|
||||||
const bool readOnly = true;
|
const bool readOnly = true;
|
||||||
|
@ -773,17 +776,17 @@ FilterAndPartitionTable(const char *filterQuery,
|
||||||
OutputBinaryHeaders(partitionFileArray, fileCount);
|
OutputBinaryHeaders(partitionFileArray, fileCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
columnCount = (uint32) SPI_tuptable->tupdesc->natts;
|
||||||
|
valueArray = (Datum *) palloc0(columnCount * sizeof(Datum));
|
||||||
|
isNullArray = (bool *) palloc0(columnCount * sizeof(bool));
|
||||||
|
|
||||||
while (SPI_processed > 0)
|
while (SPI_processed > 0)
|
||||||
{
|
{
|
||||||
TupleDesc rowDescriptor = SPI_tuptable->tupdesc;
|
|
||||||
uint32 columnCount = (uint32) rowDescriptor->natts;
|
|
||||||
Datum *valueArray = (Datum *) palloc0(columnCount * sizeof(Datum));
|
|
||||||
bool *isNullArray = (bool *) palloc0(columnCount * sizeof(bool));
|
|
||||||
|
|
||||||
int rowIndex = 0;
|
int rowIndex = 0;
|
||||||
for (rowIndex = 0; rowIndex < SPI_processed; rowIndex++)
|
for (rowIndex = 0; rowIndex < SPI_processed; rowIndex++)
|
||||||
{
|
{
|
||||||
HeapTuple row = SPI_tuptable->vals[rowIndex];
|
HeapTuple row = SPI_tuptable->vals[rowIndex];
|
||||||
|
TupleDesc rowDescriptor = SPI_tuptable->tupdesc;
|
||||||
FileOutputStream partitionFile = { 0, 0, 0 };
|
FileOutputStream partitionFile = { 0, 0, 0 };
|
||||||
StringInfo rowText = NULL;
|
StringInfo rowText = NULL;
|
||||||
Datum partitionKey = 0;
|
Datum partitionKey = 0;
|
||||||
|
@ -822,14 +825,14 @@ FilterAndPartitionTable(const char *filterQuery,
|
||||||
resetStringInfo(rowText);
|
resetStringInfo(rowText);
|
||||||
}
|
}
|
||||||
|
|
||||||
pfree(valueArray);
|
|
||||||
pfree(isNullArray);
|
|
||||||
|
|
||||||
SPI_freetuptable(SPI_tuptable);
|
SPI_freetuptable(SPI_tuptable);
|
||||||
|
|
||||||
SPI_cursor_fetch(queryPortal, fetchForward, prefetchCount);
|
SPI_cursor_fetch(queryPortal, fetchForward, prefetchCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pfree(valueArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
SPI_cursor_close(queryPortal);
|
SPI_cursor_close(queryPortal);
|
||||||
|
|
||||||
if (BinaryWorkerCopyFormat)
|
if (BinaryWorkerCopyFormat)
|
||||||
|
|
Loading…
Reference in New Issue