Flink: Enable Cost Based Optimizaton in Flink's planner for batch jobs - #17878
Open
talatuyarer wants to merge 1 commit into
Open
Flink: Enable Cost Based Optimizaton in Flink's planner for batch jobs#17878talatuyarer wants to merge 1 commit into
talatuyarer wants to merge 1 commit into
Conversation
Contributor
Author
|
To assist with the review process, I have created a demo using Google’s public Iceberg datasets. By using Flink’s EXPLAIN command, I have demonstrated how this feature significantly improves query plans. For example, the optimizer was able to reduce the estimated scan count from 323,000,000 to 12,919 rows and successfully chose a broadcast join over a costly shuffle for large datasets. You are welcome to explore these results and test the implementation yourself. Table Stats Demo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
SupportsStatisticReportinIcebergTableSourceso that in batch execution mode the Flink planner receives table statistics computed from Iceberg metadata: therow count, andper-column null counts,min/max values, andNDV. These feed Flink's cost-based optimizations to filter selectivity estimation, join reordering, and broadcast-join selection. previously code ran on defaults because the Iceberg source reported no statistics at all.All statistics come from metadata already maintained by Iceberg, no data files are read. For streaming reads, time-travel/incremental options, missing record counts, row-count overflow, and any exception I logged as
WARNlog and all reportTableStats.UNKNOWNrather than failing or misleading the planner.Because column statistics reporting is enabled by default, I measured the planning-time overhead with a local JMH benchmark to validate that default, I did not include for this PR. But If you want I can share.
Setup: metadata-only data files appended in ~1000-entry manifests, so manifest I/O is measured without writing actual data files; single-shot mode, since planning is a once-per-query cost:
The row-count-only path is constant time regardless of table size. Full column stats cost ~1 µs per data file single-digit milliseconds at typical table sizes, ~100 ms at 100K files, ~1 s at 1M files (warm-cache local FS, so this is manifest decode cost, a lower bound vs. object storage).
I consider this acceptable for a default configuration: tables where the cost is noticeable (100K+ files) are exactly the tables that benefit most from statistics-driven plans, and latency-sensitive users can opt out with
table.exec.iceberg.report-column-statistics=false. I am also happy your feedbacks. I dont have any strong preferences.