提交 2ec69545 编写于 作者: A Ashwin Agrawal

pgindent appendonly directory.

上级 4832071b
......@@ -21,13 +21,13 @@
/*
* Frees the data allocated by the visimap entry.
*
*
* No other function should be called on the visibility map entry
* after this function has been called.
*/
*/
void
AppendOnlyVisimapEntry_Finish(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
......@@ -45,14 +45,14 @@ AppendOnlyVisimapEntry_Finish(
;
* Assumes a zero-allocated visimap entry data structure.
*
* Until appendonly_visimap_copyout or appendonly_visimap_clear is called,
* Until appendonly_visimap_copyout or appendonly_visimap_clear is called,
* the data structure
* is not usable for visibility checks or updates.
*/
*/
void
AppendOnlyVisimapEntry_Init(
AppendOnlyVisimapEntry *visiMapEntry,
MemoryContext memoryContext)
AppendOnlyVisimapEntry *visiMapEntry,
MemoryContext memoryContext)
{
Assert(visiMapEntry);
......@@ -68,12 +68,12 @@ AppendOnlyVisimapEntry_Init(
/*
* Resets the visibility map data structure.
*
* It puts the entry into the identical state as after a
* It puts the entry into the identical state as after a
* call to AppendOnlyVisimapEntry_Init.
*/
*/
void
AppendOnlyVisimapEntry_Reset(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
......@@ -89,12 +89,12 @@ AppendOnlyVisimapEntry_Reset(
* Initializes a previously unused entry that covers the given tuple id.
* The tuple is not marked as updated as no state has been changed yet.
*
* Note that the firstRowNum is not the rowNum of the tuple id.
*/
* Note that the firstRowNum is not the rowNum of the tuple id.
*/
void
AppendOnlyVisimapEntry_New(
AppendOnlyVisimapEntry* visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
Assert(visiMapEntry);
Assert(tupleId);
......@@ -105,22 +105,22 @@ AppendOnlyVisimapEntry_New(
visiMapEntry->segmentFileNum = AOTupleIdGet_segmentFileNum(tupleId);
visiMapEntry->firstRowNum = AppendOnlyVisimapEntry_GetFirstRowNum(visiMapEntry,
tupleId);
tupleId);
ItemPointerSetInvalid(&visiMapEntry->tupleTid);
ItemPointerSetInvalid(&visiMapEntry->tupleTid);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: New entry "
"(segNum, firstRowNum) = (%u, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum,
visiMapEntry->firstRowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: New entry "
"(segNum, firstRowNum) = (%u, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum,
visiMapEntry->firstRowNum);
}
static Datum
AppendOnlyVisimap_GetAttrNotNull(HeapTuple t, TupleDesc td, int attr)
{
Datum d;
bool isNull;
Datum d;
bool isNull;
d = fastgetattr(t, attr, td, &isNull);
if (isNull)
......@@ -132,17 +132,18 @@ AppendOnlyVisimap_GetAttrNotNull(HeapTuple t, TupleDesc td, int attr)
void
AppendOnlyVisiMapEnty_ReadData(
AppendOnlyVisimapEntry *visiMapEntry, size_t dataSize)
AppendOnlyVisimapEntry *visiMapEntry, size_t dataSize)
{
int newWordCount;
int newWordCount;
Assert(visiMapEntry);
Assert(CurrentMemoryContext == visiMapEntry->memoryContext);
BitmapDecompressState decompressState;
BitmapDecompress_Init(&decompressState,
visiMapEntry->data->data,
dataSize);
visiMapEntry->data->data,
dataSize);
if (BitmapDecompress_HasError(&decompressState))
{
......@@ -151,17 +152,17 @@ AppendOnlyVisiMapEnty_ReadData(
bms_free(visiMapEntry->bitmap);
newWordCount =
newWordCount =
BitmapDecompress_GetBlockCount(&decompressState);
if (newWordCount > 0)
{
visiMapEntry->bitmap = palloc0(
offsetof(Bitmapset, words) + (newWordCount * sizeof(bitmapword)));
offsetof(Bitmapset, words) + (newWordCount * sizeof(bitmapword)));
visiMapEntry->bitmap->nwords = newWordCount;
BitmapDecompress_Decompress(
&decompressState,
visiMapEntry->bitmap->words,
newWordCount);
&decompressState,
visiMapEntry->bitmap->words,
newWordCount);
}
else if (newWordCount == 0)
{
......@@ -169,8 +170,8 @@ AppendOnlyVisiMapEnty_ReadData(
}
else
{
elog(ERROR,
"illegal visimap block count: visimap block count %d", newWordCount);
elog(ERROR,
"illegal visimap block count: visimap block count %d", newWordCount);
}
}
......@@ -181,37 +182,37 @@ AppendOnlyVisiMapEnty_ReadData(
* Should only be called with values and nulls provides
* by a successful read from the aovisimap table using
* an AppendOnlyVisimapIndex data structure.
*/
*/
void
AppendOnlyVisimapEntry_Copyout(
AppendOnlyVisimapEntry *visiMapEntry,
HeapTuple tuple,
TupleDesc tupleDesc)
AppendOnlyVisimapEntry *visiMapEntry,
HeapTuple tuple,
TupleDesc tupleDesc)
{
struct varlena *value;
struct varlena *detoast_value;
MemoryContext oldContext;
size_t dataSize;
Datum d;
bool isNull;
MemoryContext oldContext;
size_t dataSize;
Datum d;
bool isNull;
Assert(visiMapEntry);
Assert(!visiMapEntry->dirty);
Assert(tuple);
Assert(tupleDesc);
Assert(!visiMapEntry->dirty); /* entry should not contain dirty data */
Assert(!visiMapEntry->dirty); /* entry should not contain dirty data */
d = AppendOnlyVisimap_GetAttrNotNull(tuple, tupleDesc, Anum_pg_aovisimap_segno);
visiMapEntry->segmentFileNum = DatumGetInt64(d);
d = AppendOnlyVisimap_GetAttrNotNull(tuple, tupleDesc, Anum_pg_aovisimap_firstrownum);
visiMapEntry->firstRowNum = DatumGetInt64(d);
elogif (Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: copy out: "
"segNo %u firstRowNum " INT64_FORMAT,
visiMapEntry->segmentFileNum,
visiMapEntry->firstRowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: copy out: "
"segNo %u firstRowNum " INT64_FORMAT,
visiMapEntry->segmentFileNum,
visiMapEntry->firstRowNum);
d = fastgetattr(tuple, Anum_pg_aovisimap_visimap, tupleDesc, &isNull);
if (isNull)
......@@ -224,7 +225,7 @@ AppendOnlyVisimapEntry_Copyout(
}
else
{
value = (struct varlena*)DatumGetPointer(d);
value = (struct varlena *) DatumGetPointer(d);
detoast_value = pg_detoast_datum(value);
oldContext = MemoryContextSwitchTo(visiMapEntry->memoryContext);
......@@ -233,14 +234,15 @@ AppendOnlyVisimapEntry_Copyout(
Assert(visiMapEntry->data);
Assert(APPENDONLY_VISIMAP_DATA_BUFFER_SIZE >= VARSIZE(detoast_value));
memcpy(visiMapEntry->data, detoast_value, VARSIZE(detoast_value));
dataSize = VARSIZE(detoast_value) -
dataSize = VARSIZE(detoast_value) -
offsetof(AppendOnlyVisimapData, data);
AppendOnlyVisiMapEnty_ReadData(visiMapEntry, dataSize);
MemoryContextSwitchTo(oldContext);
if (detoast_value != value) {
if (detoast_value != value)
{
pfree(detoast_value);
detoast_value = NULL;
}
......@@ -250,10 +252,10 @@ AppendOnlyVisimapEntry_Copyout(
/*
* Returns the hidden tuple count value from a visimap entry heap tuple.
*
*/
*/
int64
AppendOnlyVisimapEntry_GetHiddenTupleCount(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
......@@ -262,15 +264,16 @@ AppendOnlyVisimapEntry_GetHiddenTupleCount(
void
AppendOnlyVisimapEntry_WriteData(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
int bitmapSize, compressedBitmapSize;
int bitmapSize,
compressedBitmapSize;
Assert(visiMapEntry);
Assert(CurrentMemoryContext == visiMapEntry->memoryContext);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
bitmapSize = (visiMapEntry->bitmap ? (visiMapEntry->bitmap->nwords * sizeof(uint32)): 0);
bitmapSize = (visiMapEntry->bitmap ? (visiMapEntry->bitmap->nwords * sizeof(uint32)) : 0);
bitmapSize += BITMAP_COMPRESSION_HEADER_SIZE;
Assert(visiMapEntry->data);
......@@ -278,16 +281,17 @@ AppendOnlyVisimapEntry_WriteData(
visiMapEntry->data->version = 1;
compressedBitmapSize = Bitmap_Compress(
BITMAP_COMPRESSION_TYPE_DEFAULT,
(visiMapEntry->bitmap ? visiMapEntry->bitmap->words : NULL),
(visiMapEntry->bitmap ? visiMapEntry->bitmap->nwords : 0),
visiMapEntry->data->data,
bitmapSize);
BITMAP_COMPRESSION_TYPE_DEFAULT,
(visiMapEntry->bitmap ? visiMapEntry->bitmap->words : NULL),
(visiMapEntry->bitmap ? visiMapEntry->bitmap->nwords : 0),
visiMapEntry->data->data,
bitmapSize);
Assert(compressedBitmapSize >= BITMAP_COMPRESSION_HEADER_SIZE);
SET_VARSIZE(visiMapEntry->data,
offsetof(AppendOnlyVisimapData, data) + compressedBitmapSize);
offsetof(AppendOnlyVisimapData, data) + compressedBitmapSize);
}
/**
* Persist the entry information to heap tuple value/nulls.
* Should only be called after a call to AppendOnlyVisimapEntry_copyout
......@@ -295,12 +299,12 @@ AppendOnlyVisimapEntry_WriteData(
*
* May be called when visimap entry is not updated. However, that is usually
* wasteful.
*/
*/
void
AppendOnlyVisimapEntry_Write(
AppendOnlyVisimapEntry *visiMapEntry,
Datum* values,
bool* nulls)
AppendOnlyVisimapEntry *visiMapEntry,
Datum *values,
bool *nulls)
{
MemoryContext oldContext;
......@@ -309,10 +313,10 @@ AppendOnlyVisimapEntry_Write(
Assert(nulls);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
elogif (Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: write (segno, firstRowNum) = "
"(%d, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum, visiMapEntry->firstRowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: write (segno, firstRowNum) = "
"(%d, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum, visiMapEntry->firstRowNum);
values[Anum_pg_aovisimap_segno - 1] = Int32GetDatum(visiMapEntry->segmentFileNum);
nulls[Anum_pg_aovisimap_segno - 1] = false;
......@@ -339,10 +343,10 @@ AppendOnlyVisimapEntry_Write(
/*
* Returns true iff all entries in the visimap entry are visible.
*/
*/
static bool
AppendOnlyVisimapEntry_AreAllVisible(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
......@@ -355,12 +359,12 @@ AppendOnlyVisimapEntry_AreAllVisible(
* visibility map entry).
*
* Assumes that the current visibility map entry covers the row number.
*/
*/
static void
AppendOnlyVisimapEntry_GetRownumOffset(
AppendOnlyVisimapEntry *visiMapEntry,
int64 rowNum,
int64* rowNumOffset)
AppendOnlyVisimapEntry *visiMapEntry,
int64 rowNum,
int64 *rowNumOffset)
{
Assert(visiMapEntry);
Assert(rowNum >= 0);
......@@ -383,10 +387,10 @@ AppendOnlyVisimapEntry_GetRownumOffset(
*/
bool
AppendOnlyVisimapEntry_CoversTuple(
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
int rowNum;
int rowNum;
Assert(visiMapEntry);
Assert(tupleId);
......@@ -395,27 +399,27 @@ AppendOnlyVisimapEntry_CoversTuple(
{
return false;
}
if (visiMapEntry->segmentFileNum !=
AOTupleIdGet_segmentFileNum(tupleId))
if (visiMapEntry->segmentFileNum !=
AOTupleIdGet_segmentFileNum(tupleId))
{
return false;
}
rowNum = AOTupleIdGet_rowNum(tupleId);
return (visiMapEntry->firstRowNum <= rowNum)
&& ((visiMapEntry->firstRowNum + APPENDONLY_VISIMAP_MAX_RANGE) > rowNum);
&& ((visiMapEntry->firstRowNum + APPENDONLY_VISIMAP_MAX_RANGE) > rowNum);
}
/*
* Returns the matching first row number of a given
* AO tuple id.
*/
*/
int64
AppendOnlyVisimapEntry_GetFirstRowNum(
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
(void)visiMapEntry;
int rowNum;
(void) visiMapEntry;
int rowNum;
rowNum = AOTupleIdGet_rowNum(tupleId);
return (rowNum / APPENDONLY_VISIMAP_MAX_RANGE) * APPENDONLY_VISIMAP_MAX_RANGE;
......@@ -431,14 +435,15 @@ AppendOnlyVisimapEntry_GetFirstRowNum(
* The final visibility also depends on other information, e.g. if the
* original transaction has been aborted. Such information is
* not stored in the visimap.
*/
*/
bool
AppendOnlyVisimapEntry_IsVisible(
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
int64 rowNum, rowNumOffset;
bool visibilityBit;
int64 rowNum,
rowNumOffset;
bool visibilityBit;
Assert(visiMapEntry);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
......@@ -446,44 +451,44 @@ AppendOnlyVisimapEntry_IsVisible(
rowNum = AOTupleIdGet_rowNum(tupleId);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: Check row visibility: "
"firstRowNum " INT64_FORMAT ", rowNum " INT64_FORMAT,
visiMapEntry->firstRowNum, rowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: Check row visibility: "
"firstRowNum " INT64_FORMAT ", rowNum " INT64_FORMAT,
visiMapEntry->firstRowNum, rowNum);
if (AppendOnlyVisimapEntry_AreAllVisible(visiMapEntry))
{
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: All entries are visibile: "
"(firstRowNum, rowNum) = (" INT64_FORMAT ", " INT64_FORMAT ")",
visiMapEntry->firstRowNum, rowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: All entries are visibile: "
"(firstRowNum, rowNum) = (" INT64_FORMAT ", " INT64_FORMAT ")",
visiMapEntry->firstRowNum, rowNum);
return true;
}
Assert(rowNum >= visiMapEntry->firstRowNum);
rowNumOffset = 0;
AppendOnlyVisimapEntry_GetRownumOffset(visiMapEntry,
rowNum, &rowNumOffset);
rowNum, &rowNumOffset);
visibilityBit = !bms_is_member(rowNumOffset,
visiMapEntry->bitmap);
visiMapEntry->bitmap);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: (firstRowNum, rowNum, visible) = "
"(" INT64_FORMAT ", " INT64_FORMAT ", %d)",
visiMapEntry->firstRowNum, rowNum, (int)visibilityBit);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: (firstRowNum, rowNum, visible) = "
"(" INT64_FORMAT ", " INT64_FORMAT ", %d)",
visiMapEntry->firstRowNum, rowNum, (int) visibilityBit);
return visibilityBit;
return visibilityBit;
}
/*
* The minimal size (in uint32's elements) the entry array needs to have to
* cover the given offset
*/
*/
static uint32
AppendOnlyVisimapEntry_GetMinimalSizeToCover(int64 offset)
{
uint32 minSize;
uint32 minSize;
Assert(offset >= 0);
......@@ -507,13 +512,14 @@ AppendOnlyVisimapEntry_GetMinimalSizeToCover(int64 offset)
*
* This function is only modifying the bitmap. The caller needs to take
* care that change is persisted.
*/
HTSU_Result
*/
HTSU_Result
AppendOnlyVisimapEntry_HideTuple(
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
int64 rowNum, rowNumOffset;
int64 rowNum,
rowNumOffset;
MemoryContext oldContext;
HTSU_Result result;
......@@ -521,33 +527,35 @@ AppendOnlyVisimapEntry_HideTuple(
Assert(tupleId);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
Assert(AppendOnlyVisimapEntry_CoversTuple(visiMapEntry, tupleId));
rowNum = AOTupleIdGet_rowNum(tupleId);
elogif (Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: Hide tuple: "
"firstRowNum " INT64_FORMAT ", rowNum " INT64_FORMAT,
visiMapEntry->firstRowNum, rowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map entry: Hide tuple: "
"firstRowNum " INT64_FORMAT ", rowNum " INT64_FORMAT,
visiMapEntry->firstRowNum, rowNum);
rowNumOffset = 0;
AppendOnlyVisimapEntry_GetRownumOffset(visiMapEntry,
rowNum,
&rowNumOffset);
rowNum,
&rowNumOffset);
oldContext = MemoryContextSwitchTo(visiMapEntry->memoryContext);
/* enlarge the bitmap by a power of two.
* this avoids the O(n*n) resizing policy of the original bitmap set */
/*
* enlarge the bitmap by a power of two. this avoids the O(n*n) resizing
* policy of the original bitmap set
*/
if (!bms_covers_member(visiMapEntry->bitmap, rowNumOffset))
visiMapEntry->bitmap =
bms_resize(visiMapEntry->bitmap,
AppendOnlyVisimapEntry_GetMinimalSizeToCover(rowNumOffset));
visiMapEntry->bitmap =
bms_resize(visiMapEntry->bitmap,
AppendOnlyVisimapEntry_GetMinimalSizeToCover(rowNumOffset));
if (!bms_is_member(rowNumOffset, visiMapEntry->bitmap))
{
visiMapEntry->bitmap = bms_add_member(visiMapEntry->bitmap, rowNumOffset);
result = HeapTupleMayBeUpdated;
}
}
else if (visiMapEntry->dirty)
{
/* The bit was already set and it was this command */
......@@ -567,10 +575,10 @@ AppendOnlyVisimapEntry_HideTuple(
/**
* Returns true iff the visi map entry needs to be persisted.
*/
bool
*/
bool
AppendOnlyVisimapEntry_HasChanged(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
return visiMapEntry->dirty;
......@@ -580,9 +588,9 @@ AppendOnlyVisimapEntry_HasChanged(
* Returns true iff the entry contains valid data.
* That is either CopyOut or New has been called.
*/
bool
bool
AppendOnlyVisimapEntry_IsValid(
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapEntry *visiMapEntry)
{
Assert(visiMapEntry);
return (visiMapEntry->segmentFileNum >= 0 &&
......@@ -591,42 +599,43 @@ AppendOnlyVisimapEntry_IsValid(
/*
* Return the next invisible tuple id in the given visibility map.
*/
*/
bool
AppendOnlyVisimapEntry_GetNextInvisible(
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
AppendOnlyVisimapEntry *visiMapEntry,
AOTupleId *tupleId)
{
int64 currentBitmapOffset, rowNum;
int offset;
int64 currentBitmapOffset,
rowNum;
int offset;
Assert(visiMapEntry);
Assert(AppendOnlyVisimapEntry_IsValid(visiMapEntry));
Assert(tupleId);
currentBitmapOffset = -1; /* before the first */
currentBitmapOffset = -1; /* before the first */
if (AppendOnlyVisimapEntry_CoversTuple(
visiMapEntry, tupleId))
visiMapEntry, tupleId))
{
AppendOnlyVisimapEntry_GetRownumOffset(
visiMapEntry,
AOTupleIdGet_rowNum(tupleId),
&currentBitmapOffset);
visiMapEntry,
AOTupleIdGet_rowNum(tupleId),
&currentBitmapOffset);
}
currentBitmapOffset++;
offset = bms_first_from(visiMapEntry->bitmap,
currentBitmapOffset);
currentBitmapOffset);
if (offset >= 0)
{
rowNum = visiMapEntry->firstRowNum + offset;
AOTupleIdInit_Init(tupleId);
AOTupleIdInit_segmentFileNum(
tupleId,
visiMapEntry->segmentFileNum);
tupleId,
visiMapEntry->segmentFileNum);
AOTupleIdInit_rowNum(
tupleId,
rowNum);
tupleId,
rowNum);
return true;
}
else
......@@ -634,4 +643,3 @@ AppendOnlyVisimapEntry_GetNextInvisible(
return false;
}
}
......@@ -26,14 +26,14 @@
/*
* Frees the data allocated by the visimap store
*
*
* No function using the visibility map store should be called
* after this function call.
*/
*/
void
AppendOnlyVisimapStore_Finish(
AppendOnlyVisimapStore *visiMapStore,
LOCKMODE lockmode)
AppendOnlyVisimapStore *visiMapStore,
LOCKMODE lockmode)
{
if (visiMapStore->scanKeys)
{
......@@ -46,23 +46,23 @@ AppendOnlyVisimapStore_Finish(
}
/*
* Inits the visimap store.
* Inits the visimap store.
* The store is ready for usage after this function call.
*
* Assumes a zero-allocated visimap store data structure.
* Assumes that the visimap memory context is active.
*/
*/
void
AppendOnlyVisimapStore_Init(
AppendOnlyVisimapStore *visiMapStore,
Oid visimapRelid,
Oid visimapIdxid,
LOCKMODE lockmode,
Snapshot snapshot,
MemoryContext memoryContext)
AppendOnlyVisimapStore *visiMapStore,
Oid visimapRelid,
Oid visimapIdxid,
LOCKMODE lockmode,
Snapshot snapshot,
MemoryContext memoryContext)
{
TupleDesc heapTupleDesc;
ScanKey scanKey;
TupleDesc heapTupleDesc;
ScanKey scanKey;
Assert(visiMapStore);
Assert(CurrentMemoryContext == memoryContext);
......@@ -73,9 +73,9 @@ AppendOnlyVisimapStore_Init(
visiMapStore->memoryContext = memoryContext;
visiMapStore->visimapRelation = heap_open(
visimapRelid, lockmode);
visimapRelid, lockmode);
visiMapStore->visimapIndex = index_open(
visimapIdxid, lockmode);
visimapIdxid, lockmode);
heapTupleDesc =
RelationGetDescr(visiMapStore->visimapRelation);
......@@ -83,21 +83,21 @@ AppendOnlyVisimapStore_Init(
visiMapStore->scanKeys = palloc0(sizeof(ScanKeyData) * APPENDONLY_VISIMAP_INDEX_SCAN_KEY_NUM);
// scan key: segno
/* scan key: segno */
scanKey = visiMapStore->scanKeys;
ScanKeyInit(scanKey,
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
0);
// scan key: firstRowNum
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
0);
/* scan key: firstRowNum */
scanKey++;
ScanKeyInit(scanKey,
Anum_pg_aovisimap_firstrownum, /* attribute number to scan */
BTEqualStrategyNumber, /* strategy */
F_INT8EQ, /* reg proc to use */
0);
Anum_pg_aovisimap_firstrownum, /* attribute number to scan */
BTEqualStrategyNumber, /* strategy */
F_INT8EQ, /* reg proc to use */
0);
}
/*
......@@ -110,42 +110,42 @@ AppendOnlyVisimapStore_Init(
* returned by AppendOnlyVisimapStore_find.
*
* Should not be called twice in the same command.
*/
*/
void
AppendOnlyVisimapStore_Store(
AppendOnlyVisimapStore* visiMapStore,
AppendOnlyVisimapEntry* visiMapEntry)
AppendOnlyVisimapStore *visiMapStore,
AppendOnlyVisimapEntry *visiMapEntry)
{
MemoryContext oldContext;
Relation visimapRelation;
TupleDesc heapTupleDesc;
HeapTuple tuple;
Datum values[Natts_pg_aovisimap];
bool nulls[Natts_pg_aovisimap];
Relation visimapRelation;
TupleDesc heapTupleDesc;
HeapTuple tuple;
Datum values[Natts_pg_aovisimap];
bool nulls[Natts_pg_aovisimap];
Assert(visiMapStore);
Assert(visiMapEntry);
elogif (Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Store visimap entry: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum, visiMapEntry->firstRowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Store visimap entry: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
visiMapEntry->segmentFileNum, visiMapEntry->firstRowNum);
oldContext = MemoryContextSwitchTo(visiMapStore->memoryContext);
AppendOnlyVisimapEntry_Write(visiMapEntry, values,
nulls);
nulls);
visimapRelation = visiMapStore->visimapRelation;
heapTupleDesc = RelationGetDescr(visimapRelation);
tuple = heap_form_tuple(heapTupleDesc,
values,
nulls);
values,
nulls);
/*
* Write out the visimap entry to the relation.
* If this visimap entry already in the relation, we update
* the row. Otherwise, a new row is inserted.
* Write out the visimap entry to the relation. If this visimap entry
* already in the relation, we update the row. Otherwise, a new row is
* inserted.
*/
if (ItemPointerIsValid(&visiMapEntry->tupleTid))
{
......@@ -157,13 +157,13 @@ AppendOnlyVisimapStore_Store(
}
CatalogUpdateIndexes(visimapRelation, tuple);
heap_freetuple(tuple);
MemoryContextSwitchTo(oldContext);
// Invalidate the data after storing it.
ItemPointerSetInvalid(&visiMapEntry->tupleTid);
/* Invalidate the data after storing it. */
ItemPointerSetInvalid(&visiMapEntry->tupleTid);
}
/**
......@@ -171,7 +171,7 @@ AppendOnlyVisimapStore_Store(
* segmentFileNum and firstRowNum.
*
* Note: The firstRowNum needs to be a valid firstRowNum. It is
* especially not the tuple id of the append-only tuple checked, updated,
* especially not the tuple id of the append-only tuple checked, updated,
* or deleted.
*
* Returns true if there is such a tuple and
......@@ -182,46 +182,46 @@ AppendOnlyVisimapStore_Store(
*/
bool
AppendOnlyVisimapStore_Find(
AppendOnlyVisimapStore* visiMapStore,
int32 segmentFileNum,
int64 firstRowNum,
AppendOnlyVisimapEntry* visiMapEntry)
AppendOnlyVisimapStore *visiMapStore,
int32 segmentFileNum,
int64 firstRowNum,
AppendOnlyVisimapEntry *visiMapEntry)
{
ScanKey scanKeys;
ScanKey scanKeys;
IndexScanDesc indexScan;
Assert(visiMapStore);
Assert(visiMapEntry);
Assert(RelationIsValid(visiMapStore->visimapRelation));
Assert(RelationIsValid(visiMapStore->visimapIndex));
elogif (Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Load entry: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
segmentFileNum, firstRowNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Load entry: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
segmentFileNum, firstRowNum);
scanKeys = visiMapStore->scanKeys;
scanKeys[0].sk_argument = Int32GetDatum(segmentFileNum);
scanKeys[1].sk_argument = Int64GetDatum(firstRowNum);
indexScan = AppendOnlyVisimapStore_BeginScan(
visiMapStore,
APPENDONLY_VISIMAP_INDEX_SCAN_KEY_NUM,
scanKeys);
visiMapStore,
APPENDONLY_VISIMAP_INDEX_SCAN_KEY_NUM,
scanKeys);
if (!AppendOnlyVisimapStore_GetNext(
visiMapStore,
indexScan,
BackwardScanDirection,
visiMapEntry,
&visiMapEntry->tupleTid))
visiMapStore,
indexScan,
BackwardScanDirection,
visiMapEntry,
&visiMapEntry->tupleTid))
{
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Visimap entry does not exist: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
segmentFileNum, firstRowNum);
// failed to lookup row
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Visimap entry does not exist: "
"(segFileNum, firstRowNum) = (%u, " INT64_FORMAT ")",
segmentFileNum, firstRowNum);
/* failed to lookup row */
AppendOnlyVisimapStore_EndScan(visiMapStore, indexScan);
return false;
}
......@@ -238,9 +238,9 @@ AppendOnlyVisimapStore_Find(
*/
static HeapTuple
AppendOnlyVisimapStore_GetNextTuple(
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan,
ScanDirection scanDirection)
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan,
ScanDirection scanDirection)
{
Assert(visiMapStore);
Assert(RelationIsValid(visiMapStore->visimapRelation));
......@@ -263,14 +263,14 @@ AppendOnlyVisimapStore_GetNextTuple(
*/
bool
AppendOnlyVisimapStore_GetNext(
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan,
ScanDirection scanDirection,
AppendOnlyVisimapEntry* visiMapEntry,
ItemPointerData *tupleTid)
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan,
ScanDirection scanDirection,
AppendOnlyVisimapEntry *visiMapEntry,
ItemPointerData *tupleTid)
{
HeapTuple tuple;
TupleDesc heapTupleDesc;
HeapTuple tuple;
TupleDesc heapTupleDesc;
Assert(visiMapStore);
Assert(RelationIsValid(visiMapStore->visimapRelation));
......@@ -286,7 +286,7 @@ AppendOnlyVisimapStore_GetNext(
if (visiMapEntry)
{
AppendOnlyVisimapEntry_Copyout(visiMapEntry, tuple,
heapTupleDesc);
heapTupleDesc);
}
if (tupleTid)
{
......@@ -298,11 +298,11 @@ AppendOnlyVisimapStore_GetNext(
/*
* Deletes all visibility map information from a given
* segment file.
*/
*/
void
AppendOnlyVisimapStore_DeleteSegmentFile(
AppendOnlyVisimapStore *visiMapStore,
int segmentFileNum)
AppendOnlyVisimapStore *visiMapStore,
int segmentFileNum)
{
ScanKeyData scanKey;
IndexScanDesc indexScan;
......@@ -311,66 +311,66 @@ AppendOnlyVisimapStore_DeleteSegmentFile(
Assert(visiMapStore);
Assert(RelationIsValid(visiMapStore->visimapRelation));
Assert(RelationIsValid(visiMapStore->visimapIndex));
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Delete segment file: "
"(segFileNum) = (%u)", segmentFileNum);
elogif(Debug_appendonly_print_visimap, LOG,
"Append-only visi map store: Delete segment file: "
"(segFileNum) = (%u)", segmentFileNum);
ScanKeyInit(&scanKey,
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
Int32GetDatum(segmentFileNum));
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
Int32GetDatum(segmentFileNum));
indexScan = AppendOnlyVisimapStore_BeginScan(
visiMapStore,
1,
&scanKey);
visiMapStore,
1,
&scanKey);
while (AppendOnlyVisimapStore_GetNext(visiMapStore,
indexScan,
ForwardScanDirection,
NULL,
&tid))
indexScan,
ForwardScanDirection,
NULL,
&tid))
{
simple_heap_delete(visiMapStore->visimapRelation,
&tid);
&tid);
}
AppendOnlyVisimapStore_EndScan(visiMapStore, indexScan);
}
/*
* Returns the number of hidden tuples in a given segment file
*/
*/
int64
AppendOnlyVisimapStore_GetSegmentFileHiddenTupleCount(
AppendOnlyVisimapStore *visiMapStore,
AppendOnlyVisimapEntry *visiMapEntry,
int segmentFileNum)
AppendOnlyVisimapStore *visiMapStore,
AppendOnlyVisimapEntry *visiMapEntry,
int segmentFileNum)
{
ScanKeyData scanKey;
IndexScanDesc indexScan;
int64 hiddenTupcount = 0;
int64 hiddenTupcount = 0;
Assert(visiMapStore);
Assert(visiMapEntry);
Assert(RelationIsValid(visiMapStore->visimapRelation));
Assert(RelationIsValid(visiMapStore->visimapIndex));
ScanKeyInit(&scanKey,
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
Int32GetDatum(segmentFileNum));
Anum_pg_aovisimap_segno, /* segno */
BTEqualStrategyNumber,
F_INT4EQ,
Int32GetDatum(segmentFileNum));
indexScan = AppendOnlyVisimapStore_BeginScan(
visiMapStore,
1,
&scanKey);
visiMapStore,
1,
&scanKey);
while (AppendOnlyVisimapStore_GetNext(visiMapStore,
indexScan, ForwardScanDirection,
visiMapEntry, NULL))
indexScan, ForwardScanDirection,
visiMapEntry, NULL))
{
hiddenTupcount += AppendOnlyVisimapEntry_GetHiddenTupleCount(visiMapEntry);
}
......@@ -380,28 +380,28 @@ AppendOnlyVisimapStore_GetSegmentFileHiddenTupleCount(
/*
* Returns the number of hidden tuples in a given releation
*/
*/
int64
AppendOnlyVisimapStore_GetRelationHiddenTupleCount(
AppendOnlyVisimapStore *visiMapStore,
AppendOnlyVisimapEntry *visiMapEntry)
AppendOnlyVisimapStore *visiMapStore,
AppendOnlyVisimapEntry *visiMapEntry)
{
IndexScanDesc indexScan;
int64 hiddenTupcount = 0;
int64 hiddenTupcount = 0;
Assert(visiMapStore);
Assert(visiMapEntry);
Assert(RelationIsValid(visiMapStore->visimapRelation));
Assert(RelationIsValid(visiMapStore->visimapIndex));
indexScan = AppendOnlyVisimapStore_BeginScan(
visiMapStore,
0,
NULL);
visiMapStore,
0,
NULL);
while (AppendOnlyVisimapStore_GetNext(visiMapStore,
indexScan, ForwardScanDirection,
visiMapEntry, NULL))
indexScan, ForwardScanDirection,
visiMapEntry, NULL))
{
hiddenTupcount += AppendOnlyVisimapEntry_GetHiddenTupleCount(visiMapEntry);
}
......@@ -413,35 +413,34 @@ AppendOnlyVisimapStore_GetRelationHiddenTupleCount(
* Starts a scan over the visimap store.
*
* Parameter keys may be NULL iff nkeys is zero.
*/
*/
IndexScanDesc
AppendOnlyVisimapStore_BeginScan(
AppendOnlyVisimapStore *visiMapStore,
int nkeys,
ScanKey keys)
AppendOnlyVisimapStore *visiMapStore,
int nkeys,
ScanKey keys)
{
Assert(visiMapStore);
Assert(RelationIsValid(visiMapStore->visimapRelation));
return index_beginscan(
visiMapStore->visimapRelation,
visiMapStore->visimapIndex,
visiMapStore->snapshot,
nkeys,
keys);
visiMapStore->visimapRelation,
visiMapStore->visimapIndex,
visiMapStore->snapshot,
nkeys,
keys);
}
/*
* Ends a index scan over the visimap store.
*/
*/
void
AppendOnlyVisimapStore_EndScan(
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan)
AppendOnlyVisimapStore *visiMapStore,
IndexScanDesc indexScan)
{
Assert(visiMapStore);
Assert(indexScan);
index_endscan(indexScan);
}
......@@ -24,41 +24,38 @@
#include "utils/builtins.h"
extern Datum
gp_aovisimap(PG_FUNCTION_ARGS);
extern Datum
gp_aovisimap_name(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap_name(PG_FUNCTION_ARGS);
static Datum
gp_aovisimap_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
{
Datum values[3];
bool nulls[3];
HeapTuple tuple;
Datum result;
HeapTuple tuple;
Datum result;
typedef struct Context
{
Relation aorel;
Relation aorel;
AppendOnlyVisimapScan visiMapScan;
AOTupleId aoTupleId;
AOTupleId aoTupleId;
} Context;
FuncCallContext *funcctx;
Context *context;
Context *context;
if (SRF_IS_FIRSTCALL())
{
TupleDesc tupdesc;
MemoryContext oldcontext;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/*
* switch to memory context appropriate for multiple function
* calls
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
......@@ -88,10 +85,10 @@ gp_aovisimap_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
}
AppendOnlyVisimapScan_Init(&context->visiMapScan,
context->aorel->rd_appendonly->visimaprelid,
context->aorel->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
context->aorel->rd_appendonly->visimaprelid,
context->aorel->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
AOTupleIdInit_Init(&context->aoTupleId);
funcctx->user_fctx = (void *) context;
......@@ -105,14 +102,14 @@ gp_aovisimap_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
while (true)
{
if (!AppendOnlyVisimapScan_GetNextInvisible(
&context->visiMapScan,
&context->aoTupleId))
&context->visiMapScan,
&context->aoTupleId))
{
break;
}
MemSet(values, 0, sizeof(values));
MemSet(nulls, false, sizeof(nulls));
values[0] = ItemPointerGetDatum((ItemPointer)&context->aoTupleId);
values[0] = ItemPointerGetDatum((ItemPointer) &context->aoTupleId);
values[1] = Int32GetDatum(AOTupleIdGet_segmentFileNum(&context->aoTupleId));
values[2] = Int64GetDatum(AOTupleIdGet_rowNum(&context->aoTupleId));
......@@ -121,7 +118,7 @@ gp_aovisimap_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
SRF_RETURN_NEXT(funcctx, result);
}
AppendOnlyVisimapScan_Finish(&context->visiMapScan, AccessShareLock);
heap_close(context->aorel, AccessShareLock);
pfree(context);
......@@ -132,8 +129,8 @@ gp_aovisimap_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
Datum
gp_aovisimap(PG_FUNCTION_ARGS)
{
Oid relid;
Oid relid;
relid = PG_GETARG_OID(0);
return gp_aovisimap_internal(fcinfo, relid);
}
......@@ -141,9 +138,9 @@ gp_aovisimap(PG_FUNCTION_ARGS)
Datum
gp_aovisimap_name(PG_FUNCTION_ARGS)
{
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
parentrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
relid = RangeVarGetRelid(parentrv, false);
......@@ -151,35 +148,33 @@ gp_aovisimap_name(PG_FUNCTION_ARGS)
return gp_aovisimap_internal(fcinfo, relid);
}
extern Datum
gp_aovisimap_hidden_info(PG_FUNCTION_ARGS);
extern Datum
gp_aovisimap_hidden_info_name(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap_hidden_info(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap_hidden_info_name(PG_FUNCTION_ARGS);
static Datum
gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
{
Datum values[3];
bool nulls[3];
HeapTuple tuple;
Datum result;
HeapTuple tuple;
Datum result;
typedef struct Context
{
AppendOnlyVisimap visiMap;
Relation parentRelation;
Relation parentRelation;
FileSegInfo **appendonlySegfileInfo;
AOCSFileSegInfo **aocsSegfileInfo;
int segfile_info_total;
int segfile_info_total;
int i;
int i;
} Context;
FuncCallContext *funcctx;
Context *context;
Context *context;
if (SRF_IS_FIRSTCALL())
{
......@@ -190,8 +185,7 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
funcctx = SRF_FIRSTCALL_INIT();
/*
* switch to memory context appropriate for multiple function
* calls
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
......@@ -223,23 +217,23 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
if (RelationIsAoRows(context->parentRelation))
{
context->appendonlySegfileInfo = GetAllFileSegInfo(
context->parentRelation,
SnapshotNow,
&context->segfile_info_total);
context->parentRelation,
SnapshotNow,
&context->segfile_info_total);
}
else
{
Assert(RelationIsAoCols(context->parentRelation));
context->aocsSegfileInfo = GetAllAOCSFileSegInfo(context->parentRelation,
SnapshotNow, &context->segfile_info_total);
SnapshotNow, &context->segfile_info_total);
}
context->i = 0;
AppendOnlyVisimap_Init(&context->visiMap,
context->parentRelation->rd_appendonly->visimaprelid,
context->parentRelation->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
context->parentRelation->rd_appendonly->visimaprelid,
context->parentRelation->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
funcctx->user_fctx = (void *) context;
......@@ -251,17 +245,20 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
while (context->i < context->segfile_info_total)
{
int64 tupcount;
int segno;
int64 tupcount;
int segno;
if (context->appendonlySegfileInfo)
{
FileSegInfo *fsinfo = context->appendonlySegfileInfo[context->i];
tupcount = fsinfo->total_tupcount;
segno = fsinfo->segno;
}
else if (context->aocsSegfileInfo)
{
AOCSFileSegInfo *fsinfo = context->aocsSegfileInfo[context->i];
tupcount = fsinfo->total_tupcount;
segno = fsinfo->segno;
}
......@@ -274,7 +271,7 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
MemSet(nulls, false, sizeof(nulls));
values[0] = Int32GetDatum(segno);
values[1] = Int64GetDatum(AppendOnlyVisimap_GetSegmentFileHiddenTupleCount(
&context->visiMap, segno));
&context->visiMap, segno));
values[2] = Int64GetDatum(tupcount);
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
......@@ -283,7 +280,7 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
context->i++;
SRF_RETURN_NEXT(funcctx, result);
}
AppendOnlyVisimap_Finish(&context->visiMap, AccessShareLock);
if (context->appendonlySegfileInfo)
{
......@@ -308,16 +305,17 @@ gp_aovisimap_hidden_info_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
Datum
gp_aovisimap_hidden_info(PG_FUNCTION_ARGS)
{
Oid aoRelOid = PG_GETARG_OID(0);
Oid aoRelOid = PG_GETARG_OID(0);
return gp_aovisimap_hidden_info_internal(fcinfo, aoRelOid);
}
Datum
gp_aovisimap_hidden_info_name(PG_FUNCTION_ARGS)
{
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
parentrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
relid = RangeVarGetRelid(parentrv, false);
......@@ -325,16 +323,14 @@ gp_aovisimap_hidden_info_name(PG_FUNCTION_ARGS)
return gp_aovisimap_hidden_info_internal(fcinfo, relid);
}
extern Datum
gp_aovisimap_entry(PG_FUNCTION_ARGS);
extern Datum
gp_aovisimap_entry_name(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap_entry(PG_FUNCTION_ARGS);
extern Datum gp_aovisimap_entry_name(PG_FUNCTION_ARGS);
static void
gp_aovisimap_encode_bitmap(char* bitmapBuffer, Bitmapset *bms)
gp_aovisimap_encode_bitmap(char *bitmapBuffer, Bitmapset *bms)
{
int i;
int last = -1;
int i;
int last = -1;
Assert(bitmapBuffer);
......@@ -357,34 +353,33 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
{
Datum values[4];
bool nulls[4];
HeapTuple tuple;
Datum result;
HeapTuple tuple;
Datum result;
typedef struct Context
{
AppendOnlyVisimap visiMap;
Relation parentRelation;
Relation parentRelation;
IndexScanDesc indexScan;
text *bitmapBuffer;
text *bitmapBuffer;
} Context;
FuncCallContext *funcctx;
Context *context;
Context *context;
if (SRF_IS_FIRSTCALL())
{
TupleDesc tupdesc;
MemoryContext oldcontext;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/*
* switch to memory context appropriate for multiple function
* calls
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
......@@ -416,13 +411,13 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
}
AppendOnlyVisimap_Init(&context->visiMap,
context->parentRelation->rd_appendonly->visimaprelid,
context->parentRelation->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
context->parentRelation->rd_appendonly->visimaprelid,
context->parentRelation->rd_appendonly->visimapidxid,
AccessShareLock,
SnapshotNow);
context->indexScan = AppendOnlyVisimapStore_BeginScan(&
context->visiMap.visimapStore, 0, NULL);
context->visiMap.visimapStore, 0, NULL);
context->bitmapBuffer = palloc0(VARHDRSZ + APPENDONLY_VISIMAP_MAX_RANGE + 1);
......@@ -435,10 +430,10 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
context = (Context *) funcctx->user_fctx;
if (AppendOnlyVisimapStore_GetNext(&context->visiMap.visimapStore,
context->indexScan,
ForwardScanDirection,
&context->visiMap.visimapEntry,
NULL))
context->indexScan,
ForwardScanDirection,
&context->visiMap.visimapEntry,
NULL))
{
AppendOnlyVisimapEntry *visimapEntry = &context->visiMap.visimapEntry;
......@@ -447,10 +442,10 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
values[0] = Int32GetDatum(visimapEntry->segmentFileNum);
values[1] = Int64GetDatum(visimapEntry->firstRowNum);
values[2] = Int32GetDatum(
(int32)AppendOnlyVisimapEntry_GetHiddenTupleCount(visimapEntry));
gp_aovisimap_encode_bitmap(VARDATA(context->bitmapBuffer),
visimapEntry->bitmap);
(int32) AppendOnlyVisimapEntry_GetHiddenTupleCount(visimapEntry));
gp_aovisimap_encode_bitmap(VARDATA(context->bitmapBuffer),
visimapEntry->bitmap);
SET_VARSIZE(context->bitmapBuffer, APPENDONLY_VISIMAP_MAX_RANGE);
values[3] = PointerGetDatum(context->bitmapBuffer);
......@@ -459,9 +454,9 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
SRF_RETURN_NEXT(funcctx, result);
}
AppendOnlyVisimapStore_EndScan(&context->visiMap.visimapStore,
context->indexScan);
context->indexScan);
AppendOnlyVisimap_Finish(&context->visiMap, AccessShareLock);
heap_close(context->parentRelation, AccessShareLock);
......@@ -475,16 +470,17 @@ gp_aovisimap_entry_internal(PG_FUNCTION_ARGS, Oid aoRelOid)
Datum
gp_aovisimap_entry(PG_FUNCTION_ARGS)
{
Oid aoRelOid = PG_GETARG_OID(0);
Oid aoRelOid = PG_GETARG_OID(0);
return gp_aovisimap_entry_internal(fcinfo, aoRelOid);
}
Datum
gp_aovisimap_entry_name(PG_FUNCTION_ARGS)
{
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
RangeVar *parentrv;
text *relname = PG_GETARG_TEXT_P(0);
Oid relid;
parentrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
relid = RangeVarGetRelid(parentrv, false);
......
......@@ -1763,8 +1763,8 @@ appendonly_beginrangescan(Relation relation,
for (i = 0; i < segfile_count; i++)
{
seginfo[i] = GetFileSegInfo(relation, appendOnlyMetaDataSnapshot,
segfile_no_arr[i]);
seginfo[ i] = GetFileSegInfo(relation, appendOnlyMetaDataSnapshot,
segfile_no_arr[i]);
}
return appendonly_beginrangescan_internal(relation,
snapshot,
......@@ -1975,7 +1975,7 @@ static bool
fetchNextBlock(AppendOnlyFetchDesc aoFetchDesc)
{
AppendOnlyExecutorReadBlock *executorReadBlock =
&aoFetchDesc->executorReadBlock;
&aoFetchDesc->executorReadBlock;
/*
* Try to read next block.
......
......@@ -17,7 +17,8 @@ test__AppendOnlyVisimapDelete_Finish_outoforder(void **state)
AppendOnlyVisiMapDeleteData val;
AppendOnlyVisimapDelete visiMapDelete;
AppendOnlyVisimap visiMap;
bool found;
bool found;
visiMapDelete.visiMap = &visiMap;
visiMap.visimapEntry.segmentFileNum = 2;
visiMap.visimapEntry.firstRowNum = 32768;
......@@ -32,9 +33,9 @@ test__AppendOnlyVisimapDelete_Finish_outoforder(void **state)
will_return(AppendOnlyVisimapEntry_HasChanged, true);
#ifdef USE_ASSERT_CHECKING
/*
* AppendOnlyVisimap_Store calls
* Assert(AppendOnlyVisimapEntry_IsValid)
* AppendOnlyVisimap_Store calls Assert(AppendOnlyVisimapEntry_IsValid)
*/
expect_any(AppendOnlyVisimapEntry_IsValid, visiMapEntry);
will_return(AppendOnlyVisimapEntry_IsValid, true);
......@@ -65,13 +66,13 @@ test__AppendOnlyVisimapDelete_Finish_outoforder(void **state)
}
int
main(int argc, char* argv[])
int
main(int argc, char *argv[])
{
cmockery_parse_arguments(argc, argv);
const UnitTest tests[] = {
unit_test(test__AppendOnlyVisimapDelete_Finish_outoforder)
const UnitTest tests[] = {
unit_test(test__AppendOnlyVisimapDelete_Finish_outoforder)
};
MemoryContextInit();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册