Dandandan opened a new pull request, #24520: URL: https://github.com/apache/datafusion/pull/24520
## Which issue does this PR close? - Closes #. ## Rationale for this change A join estimates how many rows it produces from the number of distinct values in each side's key. No file format records a distinct count, so a scan reports it as unknown and the estimate falls back to a guess — even when the table declares the column unique. TPC-H and TPC-DS both declare their primary keys (`benchmarks/src/tpch/mod.rs`, `benchmarks/src/tpcds/run.rs`), and the constraints do reach the scan's `EquivalenceProperties`, but nothing turns them into statistics. So today `orders(o_orderkey)` is known to be unique and still reports no distinct count. ## What changes are included in this PR? A single-column `PrimaryKey` or `Unique` constraint sets the column's distinct count to the row count, less the nulls a unique column may repeat. Left alone: - composite keys, which say nothing about their columns on their own - columns that already have a distinct count The count is inexact: constraints are `new_unverified`, so the data may not honour them. ## Are these changes tested? Yes, a unit test covers a primary key, a unique column with nulls, a composite key, and that the count survives the scan's projection. ## Are there any user-facing changes? `EXPLAIN` with `datafusion.explain.show_statistics` reports a distinct count for key columns, and plans that depend on cardinality estimates may change for tables that declare constraints. No API change. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
