Skip to content

[core] Avoid eager manifest reads for append-only LIMIT scans - #10153

Merged
JingsongLi merged 1 commit into
apache:masterfrom
beinan:codex/paimon-limit-manifest-planning
Sep 24, 2026
Merged

JingsongLi merged 1 commit into
apache:masterfrom
beinan:codex/paimon-limit-manifest-planning

Conversation

@beinan

@beinan beinan commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Avoid scheduling every manifest read before an append-only LIMIT scan can stop.

AppendOnlyFileStoreScan.readManifestEntries already stops consuming entries once it has enough rows, but its normal planning path first calls super.readManifestEntries(..., false). That eagerly submits reads for all candidate manifests, so even LIMIT 1 can perform table-wide manifest I/O.

Use the existing sequential batched reader when the scan is eligible for limit pruning. The batch size continues to follow scan.manifest.parallelism; no new option is introduced. Scans with no positive limit, data predicates, deletion vectors, or data evolution keep their existing path. Primary-key scans are unchanged.

The normal ADD/DELETE merge is preserved: manifests containing DELETE entries are still processed before selecting live ADD entries. Manifest lists and required deletion metadata are still read, and the current batch may finish after the limit is reached. This change bounds ADD-manifest scheduling rather than promising exactly one physical read for every LIMIT query.

Tests

Add AppendOnlyLimitManifestReadTest, which writes real Avro data and manifests, counts manifest input-stream opens, and reads the planned data. It covers partitioned/unpartitioned tables, limits of 1/10/larger than the table, no limit, partition/data predicates, later deletion entries, and an empty table. The consuming reader enforces the global limit, as scan pruning retains whole files.

With 20 manifests, four rows per data file, and scan.manifest.parallelism=1:

Query shape Before After
LIMIT 1 20 manifest reads 1
LIMIT 10 20 manifest reads 3
Unpartitioned LIMIT 10 20 manifest reads 3
Partition predicate + LIMIT 10 10 manifest reads 3

Negative control: all four I/O regressions fail with the original implementation, with no test errors. All nine new test cases pass with the fix.

The final focused suite passed 56 tests, zero failures/errors/skips, including existing table-scan, append-only, primary-key, deletion-vector, and data-evolution LIMIT cases. The run used the normal Maven profile, so Checkstyle, Spotless, and enforcer checks also passed.

# The codegen loader embeds classes during prepare-package; do this once on a fresh checkout.
mvn -B -pl paimon-core -am -Pfast-build -DskipTests package
mvn -B -pl paimon-core -am \
  -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -DwildcardSuites=none \
  '-Dtest=AppendOnlyLimitManifestReadTest,TableScanTest,AppendOnlySimpleTableTest#testLimit*,PrimaryKeySimpleTableTest#testLimitPushDownInDeletionVectorMode+testReadWithLimit*,KeyValueFileStoreScanTest#*Limit*,DataEvolutionTableTest#testLimit*,DataEvolutionDeletionVectorTest#testLimit*' \
  test

Validation used JDK 17 targeting Java 8, with actual local filesystem data. It did not run a StarRocks SQL cluster or object-store performance benchmark. Downstream engines such as StarRocks must consume a release/backport containing this SDK change to benefit.

Signed-off-by: Beinan <soros.wang@yahoo.com>
@JingsongLi

Copy link
Copy Markdown
Contributor

Requirement fit: SUPPORTED. Avoiding eager reads of all ADD manifests for an append-only LIMIT scan has a direct planning benefit, and this uses the existing bounded reader without adding an option.

Implementation: CLEAN in the changed path. I checked normal scan and iterator callers, the ADD/DELETE merge path, and fallbacks for data predicates, deletion vectors, and data evolution. I found no actionable regression.

Verification: the 9 new real-file/manifest tests and the core reactor package build passed locally (JDK 8, offline). In a broader TableScanTest run, 20/23 passed; three unrelated postpone-merge cases hit a local AvroSchemaConverter NoSuchMethodError from a preinstalled dependency mismatch. CI was still running when reviewed. The local base predates this PR base by about two days, so green CI on the current base remains necessary.

@Akash3121 Akash3121 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The optimization is correct because readAndMergeFileEntries  still reads all DELETE identifiers first, before lazily consuming ADD manifests. Later DELETE entries therefore continue to invalidate earlier ADDs. Only eligible append-only LIMIT scans switch to the bounded sequential reader; scans with data predicates, deletion vectors, data evolution, no limit, or a non-positive limit retain the previous path. Partition-only predicates remain safe because they filter manifests/files before row-count accumulation.

@JingsongLi
JingsongLi merged commit 3624f03 into apache:master Sep 24, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants