Skip to content

Commit cd128dc

Browse files
committed
Remove redundant size in serialized variable width block
Avoids encoding the slice length separately from the offsets, which can be used to infer the value directly.
1 parent f61afc4 commit cd128dc

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

core/trino-main/src/test/java/io/trino/execution/buffer/TestPagesSerde.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ public void testVarcharSerializedSize()
211211
// empty page
212212
Page page = new Page(builder.build());
213213
int pageSize = serializedSize(ImmutableList.of(VARCHAR), page);
214-
assertThat(pageSize).isEqualTo(48);
214+
assertThat(pageSize).isEqualTo(44);
215215

216216
// page with one value
217217
VARCHAR.writeString(builder, "alice");
218218
pageSize = 44; // Now we have moved to the normal block implementation so the page size overhead is 44
219219
page = new Page(builder.build());
220220
int firstValueSize = serializedSize(ImmutableList.of(VARCHAR), page) - pageSize;
221-
assertThat(firstValueSize).isEqualTo(8 + 5); // ending offsets + nonNullsCount + "alice"
221+
assertThat(firstValueSize).isEqualTo(4 + 5); // ending offset + nonNullsCount + "alice"
222222

223223
// page with two values
224224
VARCHAR.writeString(builder, "bob");

core/trino-spi/src/main/java/io/trino/spi/block/VariableWidthBlockEncoding.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO
6060
int startingOffset = rawOffsets[arrayBaseOffset];
6161
int totalLength = rawOffsets[positionCount + arrayBaseOffset] - startingOffset;
6262

63-
sliceOutput
64-
.appendInt(totalLength)
65-
.writeBytes(variableWidthBlock.getRawSlice(), startingOffset, totalLength);
63+
sliceOutput.writeBytes(variableWidthBlock.getRawSlice(), startingOffset, totalLength);
6664
}
6765

6866
@Override
@@ -73,8 +71,8 @@ public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceIn
7371

7472
int[] offsets = readOffsetsWithNullsCompacted(sliceInput, valueIsNull, positionCount);
7573

76-
int blockSize = sliceInput.readInt();
77-
Slice slice = Slices.allocate(blockSize);
74+
int sliceSize = offsets[offsets.length - 1];
75+
Slice slice = Slices.allocate(sliceSize);
7876
sliceInput.readBytes(slice);
7977

8078
return new VariableWidthBlock(0, positionCount, slice, offsets, valueIsNull);

0 commit comments

Comments
 (0)