Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name by Mytherin · Pull Request #21345 · duckdb/duckdb · GitHub
Skip to content

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name - #21345

Merged
Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
Mytherin:improveparquetcardinality
Mar 13, 2026
Merged

Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
Mytherin:improveparquetcardinality

Conversation

@Mytherin

Copy link
Copy Markdown
Member

Currently when reading Parquet files we depend heavily on the cardinality of the first Parquet file for our cardinality estimate (initial_file_cardinality).

When that estimate is very low, we can be off by a lot. For example, if the first Parquet file has a single row, and we are reading 2000 files, we would currently estimate the table cardinality to be 2000 rows. This PR makes this a bit more robust by setting the estimate to at least 1000 rows per file if the first file is almost empty.

In addition, when running with union_by_name = true, we have already read the metadata of all of the Parquet files and can therefore just use that cardinality instead of relying only on the first file. This gives us an exact cardinality for Parquet files read using union_by_name = true.

…ct cardinality count when we are using union by name
@Mytherin
Mytherin merged commit 66a910f into duckdb:v1.5-variegata Mar 13, 2026
57 of 59 checks passed
github-actions Bot pushed a commit to duckdb/duckdb-r that referenced this pull request Mar 18, 2026
Date: 2026-03-13 10:09:43 +0100

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name (duckdb/duckdb#21345)
CLI: Make bail on error the default in more situations (duckdb/duckdb#21344)
Fixup 401bcf041f36f3abc39ecc6d50ba3dd336fc79d7: "When stress testing … (duckdb/duckdb#21329)
CLI: Explicitly clean up shell state instead of letting static destructor order determine when it gets destroyed (duckdb/duckdb#21315)
github-actions Bot added a commit to duckdb/duckdb-r that referenced this pull request Mar 18, 2026
Date: 2026-03-13 10:09:43 +0100

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name (duckdb/duckdb#21345)
CLI: Make bail on error the default in more situations (duckdb/duckdb#21344)
Fixup 401bcf041f36f3abc39ecc6d50ba3dd336fc79d7: "When stress testing … (duckdb/duckdb#21329)
CLI: Explicitly clean up shell state instead of letting static destructor order determine when it gets destroyed (duckdb/duckdb#21315)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request Mar 22, 2026
Date: 2026-03-13 10:09:43 +0100

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name (duckdb/duckdb#21345)
CLI: Make bail on error the default in more situations (duckdb/duckdb#21344)
Fixup 401bcf041f36f3abc39ecc6d50ba3dd336fc79d7: "When stress testing … (duckdb/duckdb#21329)
CLI: Explicitly clean up shell state instead of letting static destructor order determine when it gets destroyed (duckdb/duckdb#21315)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Mar 22, 2026
Date: 2026-03-13 10:09:43 +0100

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name (duckdb/duckdb#21345)
CLI: Make bail on error the default in more situations (duckdb/duckdb#21344)
Fixup 401bcf041f36f3abc39ecc6d50ba3dd336fc79d7: "When stress testing … (duckdb/duckdb#21329)
CLI: Explicitly clean up shell state instead of letting static destructor order determine when it gets destroyed (duckdb/duckdb#21315)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
krlmlr added a commit to krlmlr/duckdb-r-old that referenced this pull request Mar 22, 2026
Date: 2026-03-13 10:09:43 +0100

Improve estimate when first Parquet file is almost empty, and get exact cardinality count when we are using union by name (duckdb/duckdb#21345)
CLI: Make bail on error the default in more situations (duckdb/duckdb#21344)
Fixup 401bcf041f36f3abc39ecc6d50ba3dd336fc79d7: "When stress testing … (duckdb/duckdb#21329)
CLI: Explicitly clean up shell state instead of letting static destructor order determine when it gets destroyed (duckdb/duckdb#21315)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
@Mytherin
Mytherin deleted the improveparquetcardinality branch April 28, 2026 07:50
kaka11chen pushed a commit to AstroVela/vane that referenced this pull request Aug 14, 2026
…ct cardinality count when we are using union by name (duckdb/duckdb#21345)

Currently when reading Parquet files we depend heavily on the
cardinality of the first Parquet file for our cardinality estimate
(`initial_file_cardinality`).

When that estimate is very low, we can be off by a lot. For example, if
the first Parquet file has a single row, and we are reading 2000 files,
we would currently estimate the table cardinality to be 2000 rows. This
PR makes this a bit more robust by setting the estimate to at least 1000
rows per file if the first file is almost empty.

In addition, when running with `union_by_name = true`, we have already
read the metadata of all of the Parquet files and can therefore just use
that cardinality instead of relying only on the first file. This gives
us an exact cardinality for Parquet files read using `union_by_name =
true`.

Upstream-Commit: duckdb/duckdb@66a910f
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.

1 participant