Skip to content

Commit

Permalink
Avoid calling the get_typlen multiple times (#256)
Browse files Browse the repository at this point in the history
This commit also changes the column type length judgment in
ReadChunkGroupNextVector().  According to Postgres code, not all
platforms have sizeof(Datum) == 8 [1], so it might be better to
use sizeof(Datum) instead of the magic number 8.

[1] https://github.com/postgres/postgres/blob/master/src/include/postgres.h#L58
  • Loading branch information
japinli authored May 21, 2024
1 parent a9f7a23 commit 8da57c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions columnar/src/backend/columnar/columnar_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2239,10 +2239,10 @@ ReadChunkGroupNextVector(ChunkGroupReadState *chunkGroupReadState, Datum *column


/*
* For data types which have len less or equal 8 we can
* For data types which have len less or equal sizeof(Datum) we can
* use `store_att_byval` function.
*/
if (vectorColumn->columnTypeLen <= 8)
if (vectorColumn->columnTypeLen <= sizeof(Datum))
{
store_att_byval(writeColumnRowPosition,
chunkGroupData->valueArray[columnIndex][rowIndex],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CreateVectorTupleTableSlot(TupleDesc tupleDesc)
int16 columnTypeLen = get_typlen(columnTypeOid);

int16 vectorColumnTypeLen =
columnTypeLen == -1 ? sizeof(Datum) : get_typlen(columnTypeOid);
columnTypeLen == -1 ? sizeof(Datum) : columnTypeLen;

/*
* We consider that type is passed by val also for cases where we have
Expand Down Expand Up @@ -168,4 +168,4 @@ CleanupVectorSlot(VectorTupleTableSlot *vectorSlot)

memset(vectorSlot->keep, true, COLUMNAR_VECTOR_COLUMN_SIZE);
vectorSlot->dimension = 0;
}
}

0 comments on commit 8da57c8

Please sign in to comment.