Repository navigation
feat: report exact row counts for eager scans with no predicates or deletes - #137
Open
Richard-Durkee wants to merge 1 commit into
Open
Richard-Durkee wants to merge 1 commit into
Richard-Durkee wants to merge 1 commit into
Conversation
alexanderbianchi
left a comment
Contributor
There was a problem hiding this comment.
LGTM, would like a full harness test for the inexact path, thanks for following up.
| // Taxi has seven daily files of 25,000 rows and no deletes. | ||
| let (plan, _) = harness.query("SELECT count(*) FROM taxi").await?; | ||
| insta::assert_snapshot!(plan, @" | ||
| ProjectionExec: expr=[175000 as count(*)] |
Contributor
There was a problem hiding this comment.
Could we add a test for the inexact case that shows the full plan as well?
|
|
||
| /// Whether `task` reads a whole file with no row predicate and no deletes, so it | ||
| /// returns exactly its record count. | ||
| fn returns_every_record(task: &FileScanTask) -> bool { |
Contributor
There was a problem hiding this comment.
I checked if we could potentially use delete metadata do cover more cases, but it'd go beyond what other engines do. Makes sense to stick with this.
- Spark + Iceberg Java: For an eligible
COUNT(*), Spark evaluates the aggregate from Iceberg file metrics and returns a local result. If any planned task has an attached delete, it declines the pushdown for the whole aggregate. That includes both v2 position deletes and v3 deletion vectors. Spark scan builder · Java delete index - Trino: It keeps the aggregate in the plan. For a whole-file split with no residual filter or deletes,
COUNT(*)needs no data columns, so Trino can synthesize pages from the manifest’s row count. If a split has v2 position deletes or a v3 DV, it takes the regular reader path and applies the deletes. That decision is per split, so eligible clean files can still take the shortcut in the same query. Trino page source
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.
EagerFileScanTaskProvider::partition_statisticssums therecord_countof its tasks and reports the result asInexactwhenever it's above zero. DataFusion only answersCOUNT(*)from statistics when the row count is exact, so an unfiltered count still opens every data file. Follow-up to #125.A task returns exactly its
record_countwhen it reads the whole file and has no row predicate and no delete files. When that holds for every task in the requested partition, we now report the sum asExact. A task with a predicate or deletes keeps the sumInexact, and a missing record count still givesAbsent. Lazy scans are unchanged, because they don't know their files at planning time.The taxi test table has seven files of 25,000 rows and no deletes. With
iceberg.execution.eager_file_planningon:Before this PR:
With this PR:
The exact row count also turns the byte estimate into
Exact, becauseIcebergDataSource::partition_statisticsderives a missing byte size from the rows. Theeager_file_statistics_apply_fetch_per_partitionsnapshot shows it. I left that alone, but I can keep the bytesInexactif you'd prefer.The new test in
statistics.rscounts reads withReadCountingStorageFactory. It checks that the unfiltered count reads no data file, and that a count with a pushed-down predicate still does.