Skip to content

[improvement](fe) Reuse external scan tasks within a statement - #66473

Open
924060929 wants to merge 2 commits into
apache:branch-4.1from
924060929:fix/cir-21262-iceberg-split-reuse
Open

[improvement](fe) Reuse external scan tasks within a statement#66473
924060929 wants to merge 2 commits into
apache:branch-4.1from
924060929:fix/cir-21262-iceberg-split-reuse

Conversation

@924060929

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

Queries with repeated equivalent external-table relations, such as UNION branches over the same table snapshot, independently plan the same remote files for every branch. On metadata-heavy Iceberg tables this repeats manifest planning and can add seconds to FE planning time; Paimon, Hudi, and Hive have the same class of duplicated split-planning work.

This change introduces a statement-execution-scoped, single-flight external scan-task cache. Each connector builds a semantic key from the facts that affect its split set:

  • Iceberg: catalog/table identity, snapshot, schema, predicate, case sensitivity, and task type.
  • Paimon: relation/target identity, snapshot/schema, effective options, projection, and predicate.
  • Hudi: query/incremental instant, reader mode, partition identity, runtime-prune mode, and Hudi parameters.
  • Hive: catalog/table identity and immutable partition/file-listing inputs.

Equivalent scans reuse connector-native tasks within one statement execution. Iceberg streaming/lazy batch paths and transactional Hive paths remain uncached to preserve their memory and transaction semantics. Mutable Hudi/Hive scheduling objects are copied before use so one scan cannot mutate cached state observed by another scan.

The cache is represented by an execution-generation handle captured by each ScanNode. PreparedStatement execution reset swaps in a new generation and invalidates the old one, so delayed workers cannot repopulate or block the next execution. Statement close and binary prepared-execution completion invalidate and clear retained task lists, preventing idle PreparedStatements from retaining split metadata. Loader failures are propagated to all waiters and are not cached, allowing retry.

Release note

Reuse equivalent Iceberg, Paimon, Hudi, and Hive scan-planning results within one statement execution to reduce repeated external metadata work.

Check List (For Author)

  • Test: Unit Test
    • IcebergScanNodeTest
    • PaimonScanNodeTest
    • HudiScanNodeTest
    • HiveScanNodeTest
    • StatementContextTest
    • 103 tests passed on the latest branch-4.1 base
    • FE reactor build and Checkstyle passed
  • Behavior changed: Yes. Equivalent external scans reuse statement-scoped planning results; transactional Hive and streaming Iceberg paths retain their previous behavior.
  • Does this need documentation: No

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@924060929
924060929 force-pushed the fix/cir-21262-iceberg-split-reuse branch from b848439 to cecc334 Compare August 5, 2026 06:46
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/30982580110

Please trigger /review again after that time.

@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 64.50% (238/369) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 8.76% (168/1918) 🎉
Increment coverage report
Complete coverage report

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31063625786

Please trigger /review again after that time.

@924060929
924060929 force-pushed the fix/cir-21262-iceberg-split-reuse branch from ff12490 to 7327aa2 Compare August 6, 2026 02:04
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929
924060929 force-pushed the fix/cir-21262-iceberg-split-reuse branch from 7327aa2 to adc7745 Compare August 7, 2026 02:33
@924060929
924060929 marked this pull request as ready for review August 7, 2026 02:42
@924060929
924060929 requested a review from yiguolei as a code owner August 7, 2026 02:42
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31142080349

Please trigger /review again after that time.

@924060929
924060929 force-pushed the fix/cir-21262-iceberg-split-reuse branch from adc7745 to 01b5a68 Compare August 7, 2026 02:53
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31142650247

Please trigger /review again after that time.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 45.53% (168/369) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Queries with repeated equivalent external-table relations, such as UNION branches over the same snapshot, plan the same remote files multiple times. This duplicates Iceberg, Paimon, Hudi, and Hive metadata work and can add seconds to FE planning. Reuse connector-native scan tasks with connector-specific semantic keys and single-flight loading within one statement execution. Keep Iceberg streaming batch paths and transactional Hive paths uncached to preserve their memory and transaction semantics. Isolate each prepared-statement execution with a generation handle and invalidate it when execution ends so delayed workers cannot pollute the next execution and idle prepared statements do not retain task lists.

### Release note

Reuse equivalent external-table scan planning results within one statement execution.

### Check List (For Author)

- Test: Unit Test
    - StatementContextTest
    - IcebergScanNodeTest
    - PaimonScanNodeTest
    - HiveScanNodeTest
    - HudiScanNodeTest
- Behavior changed: Yes, repeated equivalent external scans reuse statement-scoped planning results while transactional and streaming paths retain existing behavior
- Does this need documentation: No
Issue Number: None

Related PR: None

Problem Summary: Statement-scoped external scan task reuse lacked connector-level tests proving that equivalent scans share planning work while snapshots, options, predicates, projections, instants, partitions, reader modes, and transactional or streaming paths remain correctly isolated. Add production-entry coverage for Iceberg, Paimon, Hudi, Hive, and repeated prepared-statement executions, including mutable split isolation and cache cleanup behavior. The tests also exposed a nullable Hudi split weight copy that could unbox null after a cache hit; preserve the nullable field when copying cached splits. Expose the Iceberg manifest loader to a test subclass without changing runtime behavior so the production manifest cache wrapper is exercised directly.

None

- Test: Unit Test
    - run-fe-ut.sh: 122 targeted tests passed
    - run-fe-ut.sh: 12 strengthened Hive and Hudi tests passed
    - Maven Checkstyle: 0 violations
- Behavior changed: No, except preserving the existing standard split-weight fallback when a copied Hudi split has no explicit weight
- Does this need documentation: No
@924060929
924060929 force-pushed the fix/cir-21262-iceberg-split-reuse branch from 01b5a68 to 8db50d1 Compare August 7, 2026 09:35
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 45.53% (168/369) 🎉
Increment coverage report
Complete coverage report

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants