From 6c26c67ea09db4e95a93f3eaefea72d20e54b20c Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Thu, 29 Jul 2021 19:17:03 +0300 Subject: [PATCH] Flush write state when initializing read state In next commit, we will adjust curcid of the snapshot being used when scanning the columnar table. However, for index scan, snapshot is provided not when beginning scan but within fetch-tuple call. For this reason, start flushing pending writes in init_columnar_read_state since this seem to be a prerequisite step that needs to be done before scanning a columnar table regardless of the scan method being used. --- src/backend/columnar/columnar_tableam.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backend/columnar/columnar_tableam.c b/src/backend/columnar/columnar_tableam.c index ea8c6df1e..572c74e28 100644 --- a/src/backend/columnar/columnar_tableam.c +++ b/src/backend/columnar/columnar_tableam.c @@ -227,8 +227,6 @@ columnar_beginscan_extended(Relation relation, Snapshot snapshot, "cannot read from table when there is unflushed data in upper transactions"); } - FlushWriteStateForRelfilenode(relfilenode, GetCurrentSubTransactionId()); - MemoryContextSwitchTo(oldContext); return ((TableScanDesc) scan); @@ -257,6 +255,9 @@ init_columnar_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_n { MemoryContext oldContext = MemoryContextSwitchTo(scanContext); + Oid relfilenode = relation->rd_node.relNode; + FlushWriteStateForRelfilenode(relfilenode, GetCurrentSubTransactionId()); + List *neededColumnList = NeededColumnsList(tupdesc, attr_needed); ColumnarReadState *readState = ColumnarBeginRead(relation, tupdesc, neededColumnList, scanQual, scanContext, snapshot); @@ -429,8 +430,6 @@ columnar_index_fetch_begin(Relation rel) "upper transactions"); } - FlushWriteStateForRelfilenode(relfilenode, GetCurrentSubTransactionId()); - MemoryContext scanContext = CreateColumnarScanMemoryContext(); MemoryContext oldContext = MemoryContextSwitchTo(scanContext);