gortiz opened a new pull request, #20360:
URL: https://github.com/apache/pinot/pull/20360
## Summary
In the multi-stage engine, a `Project` that only reorders or drops columns
(every expression is an `InputRef`) no longer copies each row.
`TransformOperator` now returns a lazy view of the input block. When the block
goes to a remote mailbox, the data block is built directly from the source
rows, so no projected row is created. When a local receiver reads the rows, the
view creates them at that time, so the cost is the same as before.
## Why
`TransformOperator` allocated one `Object[]` per row for every projection.
For a pure column reference this copy holds the same values as the input. When
the next operator is a send to a remote worker, the copy is read once by
`DataBlockBuilder.buildFromRows` and then discarded.
## How
- `RowHeapDataBlock.project(columnMap, projectedSchema)` returns a view over
the rows of the block.
- `asSerialized()` builds the data block from the source rows through the
column map.
- `getRows()` creates the projected rows only when it is called. Then the
view drops its reference to the wider source rows.
- Aggregation functions (`getAggFunctions()`) are remapped to the
projected columns.
- `DataBlockBuilder.buildFromRows(rows, schema, aggFunctions, columnMap)` is
a new overload. Column `i` of the data block reads `row[columnMap[i]]`.
- `TransformOperator` computes the column map once, in the constructor. If
every projection is an `InputRef`, it returns the view. Otherwise it evaluates
the operands as before. `ReferenceOperand` returns the input value unchanged,
so the rows of the view are equal to the rows of the copy.
- `BlockSplitter.Default` reads the number of rows before it reads the rows.
A block that fits in one chunk is returned unchanged, so a view stays lazy.
The view shares the values of the source rows, as the copy did. The
projected `Object[]` arrays are new, so a consumer that changes its rows does
not change the source block.
## Benchmark
`BenchmarkMseRowProjection` (new, in `pinot-perf`): 10,000 rows, 8 input
columns (LONG and STRING), JDK 25, laptop. "Copy" is the old path of
`TransformOperator`. "Build and serialize" is the work of a remote mailbox:
build the data block and write the buffers that `GrpcSendingMailbox` sends.
"Read rows" is the work of a local receiver.
| Case | Copy | View |
|---|---|---|
| Build and serialize, 2 of 8 columns | 206 µs, 546 KB | 183 µs, 266 KB |
| Build and serialize, 8 of 8 columns | 632 µs, 1476 KB | 522 µs, 956 KB |
| Read rows, 2 of 8 columns | 47 µs, 280 KB | 48 µs, 280 KB |
| Read rows, 8 of 8 columns | 96 µs, 520 KB | 94 µs, 520 KB |
For remote receivers, the view is 11-17% faster and allocates 35-51% less
memory per block. For local receivers, the cost does not change.
## Tests
- `RowHeapDataBlockProjectionTest` (new): rows, schema, serialization and
aggregation functions of a view, and the release of the source rows.
- `DataBlockBuilderTest`: `buildFromRows` with a column map gives the same
data block as a copy.
- `TransformOperatorTest`: the view for column references gives the same
rows and the same serialized values as the copy.
- `BlockSplitterTest`: a block that fits in one chunk is returned unchanged.
- `ResourceBasedQueriesTest` passes (4401 tests).
No change to wire formats, configs or public SPI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]