Skip to content

Commit ea45eb5

Browse files
ivan-v-kushcolm-mchugh
authored andcommitted
Move PushActiveSnapshot outside a for loop (#8253)
In the PR [8142](#8142) was added `PushActiveSnapshot`. This commit places it outside a for loop as taking a snapshot is a resource heavy operation.
1 parent 7b4aa22 commit ea45eb5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/backend/columnar/columnar_metadata.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,13 @@ SaveStripeSkipList(RelFileLocator relfilelocator, uint64 stripe,
618618
Oid columnarChunkOid = ColumnarChunkRelationId();
619619
Relation columnarChunk = table_open(columnarChunkOid, RowExclusiveLock);
620620
ModifyState *modifyState = StartModifyRelation(columnarChunk);
621+
bool pushed_snapshot = false;
621622

623+
if (!ActiveSnapshotSet())
624+
{
625+
PushActiveSnapshot(GetTransactionSnapshot());
626+
pushed_snapshot = true;
627+
}
622628
for (columnIndex = 0; columnIndex < columnCount; columnIndex++)
623629
{
624630
for (chunkIndex = 0; chunkIndex < chunkList->chunkCount; chunkIndex++)
@@ -659,11 +665,13 @@ SaveStripeSkipList(RelFileLocator relfilelocator, uint64 stripe,
659665
nulls[Anum_columnar_chunk_minimum_value - 1] = true;
660666
nulls[Anum_columnar_chunk_maximum_value - 1] = true;
661667
}
662-
PushActiveSnapshot(GetTransactionSnapshot());
663668
InsertTupleAndEnforceConstraints(modifyState, values, nulls);
664-
PopActiveSnapshot();
665669
}
666670
}
671+
if (pushed_snapshot)
672+
{
673+
PopActiveSnapshot();
674+
}
667675

668676
FinishModifyRelation(modifyState);
669677
table_close(columnarChunk, RowExclusiveLock);

0 commit comments

Comments
 (0)