mirror of https://github.com/citusdata/citus.git
Always use right mem cxt when creating ColumnarReadState
All the callers except columnar_relation_copy_for_cluster were already switching to right memory context when creating ColumnarReadState. With this commit, we embed that logic into init_columnar_read_state to avoid further such bugs. That way, we start using the right memory context for columnar_relation_copy_for_cluster too.pull/5165/head
parent
7fcecde203
commit
b3d9fc91f8
|
@ -253,12 +253,16 @@ CreateColumnarScanMemoryContext(void)
|
||||||
*/
|
*/
|
||||||
static ColumnarReadState *
|
static ColumnarReadState *
|
||||||
init_columnar_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_needed,
|
init_columnar_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_needed,
|
||||||
List *scanQual)
|
List *scanQual, MemoryContext scanContext)
|
||||||
{
|
{
|
||||||
|
MemoryContext oldContext = MemoryContextSwitchTo(scanContext);
|
||||||
|
|
||||||
List *neededColumnList = NeededColumnsList(tupdesc, attr_needed);
|
List *neededColumnList = NeededColumnsList(tupdesc, attr_needed);
|
||||||
ColumnarReadState *readState = ColumnarBeginRead(relation, tupdesc, neededColumnList,
|
ColumnarReadState *readState = ColumnarBeginRead(relation, tupdesc, neededColumnList,
|
||||||
scanQual);
|
scanQual);
|
||||||
|
|
||||||
|
MemoryContextSwitchTo(oldContext);
|
||||||
|
|
||||||
return readState;
|
return readState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,11 +306,10 @@ columnar_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlo
|
||||||
*/
|
*/
|
||||||
if (scan->cs_readState == NULL)
|
if (scan->cs_readState == NULL)
|
||||||
{
|
{
|
||||||
MemoryContext oldContext = MemoryContextSwitchTo(scan->scanContext);
|
|
||||||
scan->cs_readState =
|
scan->cs_readState =
|
||||||
init_columnar_read_state(scan->cs_base.rs_rd, slot->tts_tupleDescriptor,
|
init_columnar_read_state(scan->cs_base.rs_rd, slot->tts_tupleDescriptor,
|
||||||
scan->attr_needed, scan->scanQual);
|
scan->attr_needed, scan->scanQual,
|
||||||
MemoryContextSwitchTo(oldContext);
|
scan->scanContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecClearTuple(slot);
|
ExecClearTuple(slot);
|
||||||
|
@ -490,8 +493,6 @@ columnar_index_fetch_tuple(struct IndexFetchTableData *sscan,
|
||||||
/* initialize read state for the first row */
|
/* initialize read state for the first row */
|
||||||
if (scan->cs_readState == NULL)
|
if (scan->cs_readState == NULL)
|
||||||
{
|
{
|
||||||
MemoryContext oldContext = MemoryContextSwitchTo(scan->scanContext);
|
|
||||||
|
|
||||||
/* we need all columns */
|
/* we need all columns */
|
||||||
int natts = columnarRelation->rd_att->natts;
|
int natts = columnarRelation->rd_att->natts;
|
||||||
Bitmapset *attr_needed = bms_add_range(NULL, 0, natts - 1);
|
Bitmapset *attr_needed = bms_add_range(NULL, 0, natts - 1);
|
||||||
|
@ -501,8 +502,8 @@ columnar_index_fetch_tuple(struct IndexFetchTableData *sscan,
|
||||||
|
|
||||||
scan->cs_readState = init_columnar_read_state(columnarRelation,
|
scan->cs_readState = init_columnar_read_state(columnarRelation,
|
||||||
slot->tts_tupleDescriptor,
|
slot->tts_tupleDescriptor,
|
||||||
attr_needed, scanQual);
|
attr_needed, scanQual,
|
||||||
MemoryContextSwitchTo(oldContext);
|
scan->scanContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 rowNumber = tid_to_row_number(*tid);
|
uint64 rowNumber = tid_to_row_number(*tid);
|
||||||
|
@ -799,8 +800,10 @@ columnar_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
|
||||||
/* no quals for table rewrite */
|
/* no quals for table rewrite */
|
||||||
List *scanQual = NIL;
|
List *scanQual = NIL;
|
||||||
|
|
||||||
|
MemoryContext scanContext = CreateColumnarScanMemoryContext();
|
||||||
ColumnarReadState *readState = init_columnar_read_state(OldHeap, sourceDesc,
|
ColumnarReadState *readState = init_columnar_read_state(OldHeap, sourceDesc,
|
||||||
attr_needed, scanQual);
|
attr_needed, scanQual,
|
||||||
|
scanContext);
|
||||||
|
|
||||||
Datum *values = palloc0(sourceDesc->natts * sizeof(Datum));
|
Datum *values = palloc0(sourceDesc->natts * sizeof(Datum));
|
||||||
bool *nulls = palloc0(sourceDesc->natts * sizeof(bool));
|
bool *nulls = palloc0(sourceDesc->natts * sizeof(bool));
|
||||||
|
|
Loading…
Reference in New Issue