Skip to content

Commit

Permalink
Fix pg_aocsseg to work with attnum-filenum mapping
Browse files Browse the repository at this point in the history
Attnum-filenum mapping was introduced in pg_attribute_encoding in the
commit cdd03c165ad

The mapping represents the range of files used by the column for an
AOCO table. This change is to fix pg_aocsseg table to work show the
correct physical segno using this filenum field

Co-authored-by: Soumyadeep Chakraborty <[email protected]>
  • Loading branch information
2 people authored and Tao-Ma committed Jan 12, 2025
1 parent 1c94a2e commit 8793a07
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/backend/access/aocs/aocssegfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "catalog/namespace.h"
#include "catalog/indexing.h"
#include "catalog/gp_fastsequence.h"
#include "catalog/pg_attribute_encoding.h"
#include "cdb/cdbvars.h"
#include "executor/spi.h"
#include "nodes/makefuncs.h"
Expand Down Expand Up @@ -1186,6 +1187,8 @@ gp_aocsseg_internal(PG_FUNCTION_ARGS, Oid aocsRelOid)

int columnNum;
/* 0-based index into columns. */

FileNumber *fileNums;
} Context;

FuncCallContext *funcctx;
Expand Down Expand Up @@ -1263,6 +1266,14 @@ gp_aocsseg_internal(PG_FUNCTION_ARGS, Oid aocsRelOid)
appendOnlyMetaDataSnapshot,
&context->totalAocsSegFiles);

context->fileNums = palloc(sizeof(FileNumber) * context->relnatts);
for (int i = 0; i < context->relnatts; ++i)
{
FileNumber filenum = GetFilenumForAttribute(RelationGetRelid(aocsRel), i + 1);
Assert(filenum != InvalidFileNumber);
context->fileNums[i] = filenum;
}

heap_close(pg_aocsseg_rel, AccessShareLock);
heap_close(aocsRel, AccessShareLock);

Expand Down Expand Up @@ -1340,7 +1351,7 @@ gp_aocsseg_internal(PG_FUNCTION_ARGS, Oid aocsRelOid)
values[0] = Int32GetDatum(GpIdentity.segindex);
values[1] = Int32GetDatum(aocsSegfile->segno);
values[2] = Int16GetDatum(context->columnNum);
values[3] = Int32GetDatum(context->columnNum * AOTupleId_MultiplierSegmentFileNum + aocsSegfile->segno);
values[3] = Int32GetDatum((context->fileNums[context->columnNum] - 1) * AOTupleId_MultiplierSegmentFileNum + aocsSegfile->segno);
values[4] = Int64GetDatum(aocsSegfile->total_tupcount);
values[5] = Int64GetDatum(eof);
values[6] = Int64GetDatum(eof_uncompressed);
Expand Down Expand Up @@ -1395,6 +1406,8 @@ gp_aocsseg_history(PG_FUNCTION_ARGS)

int columnNum;
/* 0-based index into columns. */

FileNumber *fileNums;
} Context;

FuncCallContext *funcctx;
Expand Down Expand Up @@ -1475,6 +1488,14 @@ gp_aocsseg_history(PG_FUNCTION_ARGS)
SnapshotAny, //Get ALL tuples from pg_aocsseg_ % including aborted and in - progress ones.
& context->totalAocsSegFiles);

context->fileNums = palloc(sizeof(FileNumber) * context->relnatts);
for (int i = 0; i < context->relnatts; ++i)
{
FileNumber filenum = GetFilenumForAttribute(RelationGetRelid(aocsRel), i + 1);
Assert(filenum != InvalidFileNumber);
context->fileNums[i] = filenum;
}

heap_close(pg_aocsseg_rel, AccessShareLock);
heap_close(aocsRel, AccessShareLock);

Expand Down Expand Up @@ -1551,7 +1572,7 @@ gp_aocsseg_history(PG_FUNCTION_ARGS)
values[0] = Int32GetDatum(GpIdentity.segindex);
values[1] = Int32GetDatum(aocsSegfile->segno);
values[2] = Int16GetDatum(context->columnNum);
values[3] = Int32GetDatum(context->columnNum * AOTupleId_MultiplierSegmentFileNum + aocsSegfile->segno);
values[3] = Int32GetDatum((context->fileNums[context->columnNum] - 1) * AOTupleId_MultiplierSegmentFileNum + aocsSegfile->segno);
values[4] = Int64GetDatum(aocsSegfile->total_tupcount);
values[5] = Int64GetDatum(eof);
values[6] = Int64GetDatum(eof_uncompressed);
Expand Down

0 comments on commit 8793a07

Please sign in to comment.