Skip to content

Parquet v3: align coalesced reads to a fixed byte grid - #2978

Draft
ianton-ru wants to merge 25 commits into
antalya-26.8from
feature/antalya-26.8/parquet-align-reads-fixed-grid
Draft

ianton-ru wants to merge 25 commits into
antalya-26.8from
feature/antalya-26.8/parquet-align-reads-fixed-grid

Conversation

@ianton-ru

@ianton-ru ianton-ru commented Nov 30, 2026 •

Copy link
Copy Markdown

Part of #2181 (Parquet v3 reader): align coalesced reads to a fixed byte grid. This part works on its own. The part that takes the real part offsets of an object from the object-storage identity cache needs that cache, so it is left out and can follow later.

The prefetcher merges nearby column-chunk ranges into one read task. A merged read can straddle a boundary between two parts of a multipart-uploaded S3 object, which AWS recommends avoiding for byte-range reads. This adds two experimental settings:

  • input_format_parquet_read_alignment_bytes (default 0, off): keep every coalesced read inside one window of a fixed grid of this size, so no read straddles a multiple of it. Set it to the writer's multipart part size, for example 10Mi for delta-rs or 64Mi for Spark/S3A.
  • input_format_parquet_read_alignment_min_bytes (default 1 MiB): do not cut a read at a boundary when the aligned segment ahead of it would be smaller than this. The read then straddles the boundary instead of emitting a tiny extra request.

Only the merging is limited. A single requested range that is larger than a window is read as is, and the window is the one that contains the start of the initial range. Both settings default to the previous behavior.

New profile events: ParquetPrefetcherPartAlignedTasks counts tasks whose merging was cut at a boundary, and ParquetPrefetcherAlignmentSkippedSmall counts the skips by the minimum-size guard.

The code comes from two commits of #2181 by UnamedRus. This PR leaves out the input_format_parquet_align_reads_to_multipart_boundaries setting and the plumbing of the real part offsets, because they need ObjectMetadata.part_offsets from the identity cache. Not measured yet: the effect on S3 request counts or latency. The test checks that results are unchanged and that the alignment and the guard take effect.

Related: #2181

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Added the experimental settings input_format_parquet_read_alignment_bytes and input_format_parquet_read_alignment_min_bytes for the Parquet v3 reader. They keep coalesced reads from straddling the boundaries of a fixed byte grid, for example the multipart part size of the writer. Both are off by default. Added the profile events ParquetPrefetcherPartAlignedTasks and ParquetPrefetcherAlignmentSkippedSmall.

Documentation entry for user-facing changes

The settings are documented in their declarations (input_format_parquet_read_alignment_bytes, input_format_parquet_read_alignment_min_bytes), and the profile events in their descriptions in ProfileEvents.cpp.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

Add the experimental settings `input_format_parquet_read_alignment_bytes` and
`input_format_parquet_read_alignment_min_bytes`. When the first one is greater than zero,
the `Prefetcher` keeps each coalesced read task inside one window of a fixed grid of that
size, so no read straddles a multiple of it. With the grid set to the writer's multipart part
size (10 MiB for delta-rs, 64 MiB for Spark/S3A), no read straddles two parts of a
multipart-uploaded object, which is an AWS byte-range best practice. This needs no per-file
layout and no object-storage identity cache.

Only coalescing is limited: a single requested range larger than a window is left as is.
The window is the one containing the start of the initial requested range.

`input_format_parquet_read_alignment_min_bytes` (default 1 MiB) is an anti-fragmentation
guard: when the aligned segment ahead of the initial range would be smaller than this, the
read is allowed to straddle the boundary instead of emitting a tiny extra request.

New profile events: `ParquetPrefetcherPartAlignedTasks` counts tasks whose coalescing was cut
at a boundary, and `ParquetPrefetcherAlignmentSkippedSmall` counts the skips by the guard.

Both settings default to the previous behavior, and the settings are read straight from
`FormatSettings` in `Prefetcher::init`.

Based on 8afd7bd and b2df559 from #2181,
without the part that takes the real part offsets of an object from the object-storage
identity cache.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru ianton-ru added antalya performance Antalya Roadmap: Performance port-antalya PRs to be ported to all new Antalya releases antalya-26.8 labels Nov 30, 2026
@ianton-ru ianton-ru changed the title Parquet v3: align coalesced reads to a fixed byte grid Parquet v3: align coalesced reads to a fixed byte grid, part 1 Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [495f31b]

@ianton-ru ianton-ru changed the title Parquet v3: align coalesced reads to a fixed byte grid, part 1 Parquet v3: align coalesced reads to a fixed byte grid Nov 30, 2026
ianton-ru and others added 9 commits December 2, 2026 11:16
Make the coalescing of read tasks respect the `input_format_parquet_read_alignment_bytes`
grid in both scan directions:

- the left scan also stops at a range that would extend the task above the upper boundary
  (a range with the same start offset as the initial range, or an overlapping one), not only
  at a range that starts below the lower boundary;
- the right scan also stops when the initial range itself already crosses the boundary;
- the `input_format_parquet_read_alignment_min_bytes` guard is applied per cut in both
  directions instead of once, from the side of the initial range only.

Co-authored-by: Cursor <cursoragent@cursor.com>
…the grid

`Prefetcher` writes a test-level log line for every read task, with its offset, length and the
number of requested ranges it covers. The new test `05820_parquet_read_alignment_no_straddle`
reads the lines with `send_logs_level=test` and checks that, with
`input_format_parquet_read_alignment_bytes` set, no task covering more than one requested range
crosses a multiple of the stride, while without it such tasks exist.

Co-authored-by: Cursor <cursoragent@cursor.com>
…uld be included

The alignment check ran before the state check of the neighbouring range, so a cancelled range
or a range that already has a task counted as a cut: it incremented
`ParquetPrefetcherPartAlignedTasks` and `ParquetPrefetcherAlignmentSkippedSmall` and stopped the scan
past a cancelled range. Do the check only for a range in the `HasRange` state, which would actually be
included in the task.

The test `05819_parquet_read_alignment` relied on that overcounting: its coalescing was off with the
default local-file seek threshold, and the cuts it saw came from ranges that already had tasks. Raise
`input_format_parquet_local_file_min_bytes_for_seek` there so that the chunks are really coalesced.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ange that starts the task

The anti-fragmentation guard measured the segment before a boundary from the current start of the
task. With three or more neighbouring ranges around a boundary, the layout of the tasks depended on
which range started the task: for `X`, `Y` and `C`, where `C` crosses the boundary, `{Y, C}` plus `{X}`
was produced when `C` started, and `{X, Y}` plus `{C}` otherwise.

Decide the cut for each pair of neighbouring ranges that would be joined: the pair is cut when the first
multiple of the stride after the start of the earlier range lies strictly inside the joint span of the
pair, and the guard compares the distance from that start to the boundary with
`input_format_parquet_read_alignment_min_bytes`. The decision depends only on the pair, so it is the same
for both scan directions and for every starting range. This also replaces the window of the initial range.

Co-authored-by: Cursor <cursoragent@cursor.com>
The descriptions of `input_format_parquet_read_alignment_min_bytes` and of the profile event
`ParquetPrefetcherAlignmentSkippedSmall` still talked about "the aligned segment ahead of the initial range".
The guard compares the distance from the start of the range before a cut to the boundary with the minimum,
and the event counts the tasks in which at least one cut was skipped.

Co-authored-by: Cursor <cursoragent@cursor.com>
…dary

The pair rule looks at the joint span of two neighbouring ranges. A zero-length range at a multiple of the
stride has no extent, so the boundary was not strictly inside the span of the pair before it, and for the
pair after it the next multiple was taken. The ranges on both sides of it could be joined into a task that
crosses the boundary, with every pair passing the check.

Give a zero-length range an extent of one byte when deciding the cut. The empty range then belongs to the
side after the boundary, whichever range starts the task.

Co-authored-by: Cursor <cursoragent@cursor.com>
…g the boundary

A joint span of two ranges crosses a multiple of the stride exactly when its first and last bytes are in
different windows of the grid, and the distance from the start of the earlier range to the next multiple is
the stride minus the remainder. This replaces the explicit boundary computation in the cut decision.

Co-authored-by: Cursor <cursoragent@cursor.com>
…_read_alignment

`05820_parquet_read_alignment_no_straddle` generated the same file and ran the same queries as
`05819_parquet_read_alignment`. Keep one test that checks the result, the profile events and, from the
`Read task` log lines, that no coalesced task crosses the grid.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ited

The description of `input_format_parquet_read_alignment_bytes` and the comment in `Prefetcher.h` said
that no read straddles a multiple of the stride. The setting only stops separate requested ranges from
being merged into one read across a multiple. A single requested range that crosses a multiple is still
read as one request, and `input_format_parquet_read_alignment_min_bytes` can let a merged read cross it.
Describe that, and drop the stale "min aligned-segment size" wording.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T19:04:28.980375Z 495f31b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d08994490

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +356 to +357
/// Distance from the start of the earlier range to the first multiple of the stride after it.
if (read_alignment_min_bytes > 0 && read_alignment_stride - earlier_start % read_alignment_stride < read_alignment_min_bytes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check later boundaries after an intrinsic range crossing

When the earlier requested range already crosses a grid boundary, the minimum-size check always measures to that already-unavoidable first boundary and can consequently allow coalescing across additional boundaries. For example, with a 10 MiB stride and 1 MiB minimum, merging ranges [9.5 MiB, 17 MiB) and [20.5 MiB, 21 MiB) is permitted because the distance to 10 MiB is only 0.5 MiB, although the merge newly makes the read cross the 20 MiB boundary and the segment before that boundary is not small. This defeats the setting for large column chunks; evaluate boundaries newly crossed by the joint task rather than only the first boundary after earlier_start.

Useful? React with 👍 / 👎.

ianton-ru and others added 8 commits December 3, 2026 10:41
…crosses

The `input_format_parquet_read_alignment_min_bytes` guard measured the part before the first grid boundary after the start of the earlier range. When the earlier range already crosses a boundary on its own, that boundary is unavoidable, so the guard measured to it and could allow a merge across additional boundaries that the merge newly crosses.

Now a pair of neighbouring ranges is cut when the joined read newly crosses a boundary (the last multiple of the stride not after the later range's start, if the earlier range ends before it), unless the largest part of the joined read before such a boundary is smaller than the minimum. The decision still depends only on the pair, so the resulting tasks do not depend on which range starts the task.

Update the setting, the settings history, the ProfileEvents description and the comment in `Prefetcher.h` to match.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…ndary by itself

The previous change looked only at the multiples of the stride that lie in the gap between two ranges. The column chunks of a file are usually contiguous, so every multiple lies inside some chunk and no pair was ever cut: the alignment did nothing, and coalesced tasks grew up to `bytes_per_read_task` across many multiples.

Restore the cut condition (the joint span of the pair crosses a multiple of the stride, including when one of the ranges crosses it on its own). Fix the anti-fragmentation guard of `input_format_parquet_read_alignment_min_bytes` instead: measure the part of the joint span before the last multiple inside it, which is the largest one, and not before the first multiple after the start of the earlier range. When the earlier range ends close after the first multiple, the first-multiple check allowed a merge across further multiples.

Update the setting, the settings history, the `ProfileEvents` description and the comment in `Prefetcher.h` to match.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…e whole piece that a cut leaves

The `input_format_parquet_read_alignment_min_bytes` guard measured the part before the boundary from the start of the earlier range of the pair. When the earlier range is a small chunk that follows other chunks, the cut leaves all of them as one piece, so the part was underestimated, the guard skipped the cut, and the task kept a boundary with a long part of the task before it. On a file with 8 column chunks per row group, with a stride of 262144 and a minimum of 65536, 6 of 23 coalesced tasks kept such a boundary.

Measure the part from the start of the piece of neighbouring ranges that ends with the earlier range. The start is found by walking to the left with the same checks as the scan (cancelled ranges are skipped, a range that already has a task and a gap of `min_bytes_for_seek` stop the walk, and a pair that is cut stops it). It depends only on the ranges and not on the range that starts the task, so the scan going left and the scan going right decide a pair in the same way. The walk stops as soon as the piece reaches `read_alignment_min_bytes` before the boundary.

Add a run of `05819_parquet_read_alignment` with a minimum that lets a short part straddle, and check that no coalesced task contains a multiple of the stride with at least the minimum before it. The check fails (7 of 29 tasks) with the previous guard.

Update the setting, the settings history and the `ProfileEvents` description.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…ange that starts it

The comment on the alignment decision said that the resulting tasks do not depend on which range of a chain starts the task. That is true for where the alignment cuts a pair, which now depends only on the ranges, but not for the other limits of a task: the gap of `min_bytes_for_seek`, the size of `bytes_per_read_task` and `allow_incidental_read` are checked against the range that starts the task, so the tasks can differ with the order in which the ranges are requested, with or without the alignment. Say so.

In a simulation of the scan on 3000 random sets of up to 5 ranges, with every order of the starting ranges, the tasks depend on the order in 382 sets without the alignment, in 20 sets with the alignment, and in 3 sets only with the alignment. Those 3 depend on the gap or size limit as well.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
… incidentally

`Prefetcher::alignmentPieceStart` ignored `allow_incidental_read`, which the scans in `pickRangesAndCreateTaskIfNotExists` honour. A non-incidental range was counted into the piece, so the guard overestimated the length of the task left before the boundary and a cut could leave a part smaller than `input_format_parquet_read_alignment_min_bytes`. Stop the walk at such a range, like the left scan does.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…disables the cut

With `input_format_parquet_read_alignment_min_bytes` larger than `input_format_parquet_read_alignment_bytes` the part before the boundary is measured within one stride and is always smaller than the minimum, so no merge is ever cut. State this in the setting description, together with the meaning of 0.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…hat cross the same boundary

`Prefetcher::alignmentPieceStart` calls `shouldCutForAlignment` for every pair on its walk, and that calls `alignmentPieceStart` again. For ranges that overlap and cross the same multiple of `input_format_parquet_read_alignment_bytes` closer to it than `input_format_parquet_read_alignment_min_bytes`, every pair starts the walk over all the pairs before it, so the work doubles with each range: 48 columns whose chunks are the same bytes would hold `Prefetcher::mutex` for longer than any query timeout.

A pair on the walk that crosses the same boundary as the pair being decided already decides it: cut or skipped, the part before the boundary is too small. Stop the walk there. It gives the same decisions (checked on 60000 random layouts with a port of the logic) and the work is linear in the number of ranges.

The test reads a file whose columns all point to the same chunk.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
`LOG_TEST(getLogger("ParquetPrefetcher"), ...)` in `pickRangesAndCreateTaskIfNotExists` looked the logger up by name, which takes a global lock, for every task even when nothing is logged. Look it up once.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee50303ef2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +345 to +347
const size_t lower_bound = last_boundary >= read_alignment_min_bytes ? last_boundary - read_alignment_min_bytes : 0;
const size_t piece_start = alignmentPieceStart(ranges, earlier_idx, earlier_start, earlier_end, last_boundary, lower_bound);
small = std::min(read_alignment_stride, last_boundary - piece_start) < read_alignment_min_bytes;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Measure the fragment actually left by the cut

When the later range itself spans multiple grid windows, last_boundary can lie well beyond the end of the earlier range, so this subtraction counts bytes that will not belong to the task left by the cut. For example, with a 10 MiB stride and 1 MiB minimum, ranges [9.5 MiB, 9.6 MiB) and [9.7 MiB, 25 MiB) produce a last boundary of 20 MiB and appear to have a 10 MiB part, causing a cut that emits a 0.1 MiB request. This defeats the anti-fragmentation setting precisely when a large later column chunk intrinsically crosses multiple boundaries; base the minimum-size check on the actual end of the task left before the cut.

Useful? React with 👍 / 👎.

ianton-ru and others added 3 commits December 3, 2026 14:46
The anti-fragmentation guard of `input_format_parquet_read_alignment_bytes` measured the part before the last multiple of the stride inside the joint span of a pair. When the later range spans several windows of the grid, that multiple can be far after the end of the earlier range, so the guard counted bytes of the later range, which the cut does not leave in the piece before it. A short range followed by a long one was cut anyway, and the short range was read as a tiny separate request.

Measure the part up to the end of the earlier range when it is before the boundary. The same-boundary shortcut of the walk over the neighbouring ranges now needs the earlier range to reach that boundary, and the decisions of the walk are remembered for the scan, so that the cost stays polynomial for overlapping ranges.

The check of the guard in `05819_parquet_read_alignment` now looks at the fragments that the cuts leave, instead of the bytes of a task before a multiple of the stride, which include the bytes of the later range. A new test `05825_parquet_read_alignment_short_range_before_long` covers the layout from the review.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
…` next to it

The comment of `shouldCutForAlignment` was left above the aliases of the decisions map that were added in front of it, so it described the wrong declaration. Put the aliases first and the comment right before the function. Comment only.

Related: #2978
Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1e1e27ae9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +379 to +380
/// the decision for a pair is the same for the scan going left and the scan going right. (The limit on the
/// size of the task is not applied, because it depends on the range that starts the task.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the task-size cap when measuring fragments

When input_format_parquet_read_alignment_min_bytes exceeds the 4 MiB bytes_per_read_task cap but remains at most the alignment stride, this walk can count more preceding ranges than the task left by the cut can actually coalesce. For example, with a 10 MiB stride, a 5 MiB minimum, and contiguous 1 MiB ranges ending at the boundary, the walk measures a 5 MiB piece and permits the cut, but the later task's normal size check stops after 4 MiB, leaving a fragment smaller than the configured minimum. Include the task-size constraint in this measurement, or skip cuts when the requested minimum cannot fit within a task.

Useful? React with 👍 / 👎.

ianton-ru and others added 4 commits December 3, 2026 17:11
… anti-fragmentation walk

The guard of `input_format_parquet_read_alignment_min_bytes` walked back over the neighbouring ranges without the limit on the size of a read task. A scan takes only the ranges that start within `bytes_per_read_task` of the range that starts the task, which is 4 times `input_format_parquet_local_file_min_bytes_for_seek` for a local file. When the minimum is larger than that limit, the walk measured a longer piece than the scan leaves before the cut, and the cut left a read task shorter than the minimum.

The walk now stops at a range that starts at or before the earlier range of the pair minus `bytes_per_read_task`. A scan that starts the task at a range before it takes at least these ranges, so the measured piece is a lower bound of the part that the cut leaves.

The same-boundary shortcut in the walk is removed. It relied on the piece measured from the same start for both pairs, which no longer holds. The memo of the decisions for the scan keeps the cost of the walk bounded for overlapping ranges.

The new test `05826_parquet_read_alignment_fragment_below_minimum` reproduces the case on a layout where the reader requests the range that crosses the boundary first.

Related: #2978
Related: https://github.com/Altinity/ClickHouse/pull/2978/files#r4786374976
Co-authored-by: Cursor <cursoragent@cursor.com>
… and document the task size cap

The right scan in `Prefetcher::pickRangesAndCreateTaskIfNotExists` read `ranges[end_idx]` instead of `ranges[idx]`, so it kept examining the last range it had already coalesced, and it stored `end_idx` as the right edge index. Both are now `idx`, so the scan examines each neighbour once, as the left scan does, and it skips cancelled ranges instead of stopping on them.

Also document in `input_format_parquet_read_alignment_min_bytes` that the measured part is capped by the length of the range before the boundary plus four times the minimum seek distance, which is the size limit of a read task.

Co-authored-by: Cursor <cursoragent@cursor.com>
…a cancelled range

The fix of the right scan in `Prefetcher::pickRangesAndCreateTaskIfNotExists` also changes the default read layout, with the alignment off: a cancelled range (for example the parent of a split range) no longer stops the coalescing to the right. There was no test for it.

Add a unit test with a recording file. The range after a cancelled range, within the gap of `min_bytes_for_seek`, is read together with the first one in a single read, and a range beyond the gap is not. The first test fails (two reads instead of one) with the old `ranges[end_idx]`, the second one passes with both. It is a unit test because a `.sql` test cannot make a cancelled range appear to the right of the requested one: the `Prefetcher` requests the ranges in schema order, and the cancelled ranges are the parents of split ranges.

Co-authored-by: Cursor <cursoragent@cursor.com>
…with its subrange

When `Prefetcher::splitRange` gives a parent shorter than `min_bytes_for_seek` to `pickRangesAndCreateTaskIfNotExists` in splitting mode, the task covers only the subrange of the parent. The top-level cut decision used the subrange, but `alignmentPieceStart` walked left and read `ranges[earlier_idx]`, which for the initial range is the whole parent. The piece before the boundary was then measured from the start of the parent, so it looked longer than the part the task really reads, and the anti-fragmentation guard let a cut through that left a fragment below `input_format_parquet_read_alignment_min_bytes`.

Pass the initial range with the extents it is read with (`AlignmentInitialRange`) to `shouldCutForAlignment` and `alignmentPieceStart`, and use them for the initial range in the walk. The memo is unchanged: its key is the index and the later extents, which are fixed for one call.

The new gtest reproduces it: a parent `[6656, 7424)` KiB split to `[7300, 7424)`, with ranges `[7800, 8704)` and `[8704, 9216)` after it and the stride at 8192 KiB. The read must be one 1916 KiB read, as it is when the subrange is requested as a plain range. Without the fix, it is a 1404 KiB read.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 495f31bc25

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +428 to +429
cut = shouldCutForAlignment(
ranges, initial, earlier_idx, earlier_start, earlier_end, later_start, later_end, /*skipped_small=*/ nullptr, decisions);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Replace the unbounded recursive alignment look-back

With alignment enabled, a file containing many overlapping registered ranges can exhaust the parsing thread’s stack here. For example, ranges all covering [9.5 MiB, 10.5 MiB) with a 10 MiB stride and 1 MiB minimum keep piece_start above the 9 MiB lower bound, so requesting a high-index range recursively visits every preceding range before any decision is cached. Reader::initializePrefetches registers metadata-provided ranges, and registerRange checks file bounds but does not reject overlaps, making this reachable with an input file. Evaluate these dependencies iteratively or otherwise bound recursion independently of the number of ranges.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

antalya antalya-26.8 performance Antalya Roadmap: Performance port-antalya PRs to be ported to all new Antalya releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant