Skip to content

feat(scan): add opt-in planning object limits - #592

Open
realAaronWu wants to merge 1 commit into
apache:mainfrom
realAaronWu:codex/paimon-435-planning-controls
Open

realAaronWu wants to merge 1 commit into
apache:mainfrom
realAaronWu:codex/paimon-435-planning-controls

Conversation

@realAaronWu

@realAaronWu realAaronWu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Refs #435.

Add opt-in object limits to full-snapshot batch planning for managed append-only tables using uncached Avro manifests. Base and delta tasks share the manifest-list allowance. Manifest reads share the entry allowance, and the scan checks the packed split count before constructing splits. Exceeding a configured count returns CapacityError without publishing a plan.

The scan uses the existing parallel executor and accepted-task cleanup. The counts apply before data-column pruning or SQL row-limit pushdown can reduce the result. Decoder buffers, variable-length values, and total memory require separate accounting.

Tests

Cover parallel allowance sharing, cumulative reads across many manifests, refusal before decoding an over-budget entry into an object, data-column pruning, packed split limits with and without a SQL row limit, and accepted-task cleanup. Retain regression coverage for the default scan and ListFiles().

API and Format

Adds the opt-in TableScan::Create(context, PlanningLimits) overload. Unspecified counts are unlimited. The existing factory and storage format are unchanged.

Documentation

The public header describes the supported scan profile, count boundaries, and allocations outside this API.

Generative AI tooling

Generated-by: OpenAI Codex (GPT-6)

@realAaronWu

realAaronWu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve the fork workflows for the revised head 5f787937? The Build and Test run is waiting for approval, with zero jobs started. The focused Linux CPU suite and external C++17 probe passed locally.

@realAaronWu
realAaronWu marked this pull request as ready for review November 23, 2026 12:16
@lxy-9602

Copy link
Copy Markdown
Member

The change seems a little invasive for this feature. Could we first consider:

  1. Periodically compacting manifests through Java’s existing compactManifests() API to reduce manifest fragmentation and redundant entries.
  2. Adding Java-like LIMIT pushdown to paimon-cpp, stopping further manifest reads once enough live rows are found, while correctly accounting for DELETE entries.

Could we evaluate these two approaches first before introducing broader changes to the planning APIs and executor?

@realAaronWu

realAaronWu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

The patch now limits only opt-in CreatePlan() calls. The calling thread reads manifests serially. The shared executor and ListFiles() keep their existing behavior.

  • Java manifest compaction creates a new snapshot. A scan pinned to an older snapshot still reads the original manifests, so compaction cannot enforce a per-scan quota there. Compaction implementation
  • Java's LIMIT optimization cut ADD-manifest reads from 20 to 1 for LIMIT 1. It still processes the manifest lists and required DELETE metadata. Full scans without LIMIT use the regular path. Java #10153

Our C++ regression uses pinned snapshot 2 without LIMIT. A data-column predicate prunes all output, yet an entry budget of five returns CapacityError and six succeeds. A selective predicate on the same snapshot retains the expected three files. The quota applies before data pruning, so it protects planning even when the result is empty. Regression

All 39 focused Linux x86-64 tests and the external C++17 probe passed on this revision.

@lxy-9602

Copy link
Copy Markdown
Member

Hi @realAaronWu, introducing a new LIMIT semantic may lead to some behavioral differences, as mentioned in #588, we recommend adding a plan limit in your implementation to minimize changes to the original execution path. If you’re considering contribute a Java-like LIMIT pushdown to paimon-cpp we talk above, we’re very welcome that approach too.

@realAaronWu

Copy link
Copy Markdown
Contributor Author

The current revision adds a separate, opt-in plan limit. On a pinned Avro snapshot without a SQL LIMIT, an entry budget of 5 returns CapacityError, and 6 succeeds with the same predicate. The packed split count is checked before constructing the split objects. The existing row LIMIT keeps its current behavior. Regression tests

This bounds planning object counts for the opt-in path. Decoder memory and broader byte accounting are outside its scope. A Java-style LIMIT optimization would be a separate change.

When you recommend a plan limit, does this opt-in C++ API match what you had in mind, or would you prefer the limit to live entirely in the embedding code?

@lxy-9602

Copy link
Copy Markdown
Member

When you recommend a plan limit, does this opt-in C++ API match what you had in mind, or would you prefer the limit to live entirely in the embedding code?

Thanks for the quick reply! We suggest first landing this PR into your C++ integration code (e.g., via patch), while keeping an eye on the related issues. If there are similar needs, we can then reopen this PR and incorporate this part into paimon-cpp.

@realAaronWu

realAaronWu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Java-style LIMIT pushdown can stop reading manifests once enough live rows are found. We need a planning limit even for queries without a row LIMIT. In our regression, the predicate prunes every file, but planning still encounters six manifest entries. A budget of five returns CapacityError before materializing the over-budget batch. Regression

Would you consider narrowing #592 to opt-in checks before creating manifest-list records, manifest entries, and packed splits, using the existing executor and task cleanup?

@lucasfang

Copy link
Copy Markdown
Member

I’m concerned about how invasive this change is to the existing scan pipeline. It adds branches and state across the public API, manifest reading, and scan planning for a fairly narrow use case, which could increase maintenance costs.

Could we first follow Java Paimon’s approach and improve the existing LIMIT pushdown to avoid unnecessary manifest-entry and split materialization? If we also need separate planning resource limits, we could define their general semantics and scope before introducing them, keeping the API and implementation changes focused.

LIMIT cannot fully solve the memory problem, but the proposed limits do not provide a complete memory guarantee either.

Admit manifest-list records, manifest entries and packed splits before constructing them. Keep the existing parallel executor and accepted-task cleanup.

Refs apache#435
@realAaronWu
realAaronWu force-pushed the codex/paimon-435-planning-controls branch from 5f78793 to dbdca97 Compare November 26, 2026 09:20
@realAaronWu realAaronWu changed the title feat(scan): bound manifest planning and support cancellation feat(scan): add opt-in planning object limits Nov 26, 2026
@realAaronWu

Copy link
Copy Markdown
Contributor Author

Thanks @lxy-9602 and @lucasfang. I’ve pushed the narrower revision in dbdca97e. It removes the separate serial path and cancellation state, uses the existing executor and #462 cleanup, and checks only three opt-in counts before constructing objects: manifest-list records, manifest entries, and packed splits.

The counts also apply to full scans without a SQL LIMIT. Decoder allocations are outside their scope. The 40 focused Linux tests and the external C++17 check passed on these sources. Could you take another look at whether this narrower scope fits paimon-cpp?

@realAaronWu

realAaronWu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@lucasfang, Java-style LIMIT pushdown cannot meet our planning resource requirement. We need CreatePlan() to refuse over-budget work before constructing planning objects, including on scans without a row LIMIT. The Java regression opens all 20 manifests without LIMIT and also with a filtered LIMIT 10 that matches only four rows. Java regression

In our C++ regression, f3 > 100 yields zero splits, yet planning encounters six manifest entries. An allowance of five returns CapacityError before constructing the over-budget objects. Six returns the correct empty plan. A caller checking the result of CreatePlan() is already too late, so the check must run inside paimon-cpp. C++ regression

#592 is the smallest change we propose for that requirement. It checks three opt-in object counts before construction: manifest-list records, manifest entries, and packed splits. It reuses the existing executor and failure cleanup. Decoder memory needs separate accounting.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants