Declare ctid uniqueness and non-null system column constraints to DataFusion
What feature are you requesting?
Declare ctid (and DeferredCtid) as a unique constraint (Constraint::PrimaryKey) in PgSearchTableProvider::constraints(), propagate constraints through physical scan EquivalenceProperties, recognize ctid in deferred_placement_rule.rs, and reflect non-nullability for system columns and attnotnull heap attributes in Arrow schemas.
Why are you requesting this feature?
In PostgreSQL, physical ctid (BlockId, OffsetNumber) uniquely identifies each tuple on the heap. Unlike user-defined columns, ctid is never duplicated in a single table scan: even across unvacuumed MVCC update chains, each tuple version receives a distinct physical ctid. This makes ctid uniqueness unconditionally sound across both VisibilityMode::Eager and VisibilityMode::Deferred.
Additionally, ctid, DeferredCtid, and tableoid are never NULL in PostgreSQL, yet pg_search/src/index/fast_fields_helper.rs hardcodes is_nullable = true for every field. In DataFusion, Filter::is_scalar() requires non-nullable unique keys to deduce that WHERE ctid = ... produces at most one row (max_rows == Some(1)).
Declaring ctid uniqueness and accurate nullability unlocks:
EliminateJoin: Inner joins onctid(such as self-joins, heap fetches, or cross-index scans) can be rewritten to semi-joins, or redundant outer joins can be eliminated when one side is unreferenced.ReplaceDistinctWithAggregate: Eliminates redundantDISTINCTnodes when querying or grouping byctid.Filter::is_scalar(): Enablesmax_rows == Some(1)on scalarctidequality filters.optimize_projections: Prunes non-grouping columns inGROUP BY ctid, ...when unneeded by parent nodes, becausectidfunctionally determines all columns in that table scan.deferred_placement_rule: Recognizes that joins onctiddo not fan out rows, allowing column materialization to be deferred across the join.
What is your proposed implementation for this feature?
- System column and attribute nullability: In
build_arrow_schema(pg_search/src/index/fast_fields_helper.rs), reflect non-nullability for system fields (Ctid,DeferredCtid,TableOid) and heap attributes markedattnotnullrather than marking all Arrow fields nullable. - TableProvider constraints: Implement
TableProvider::constraintsonPgSearchTableProvider(pg_search/src/scan/table_provider.rs) to declarectid/DeferredCtidas aConstraint::PrimaryKey. - Physical plan propagation: Ensure
PgSearchScanPlan(pg_search/src/scan/execution_plan.rs) and physical helpers likepreserved_ordering(pg_search/src/scan/deferred_lookup.rs) carry constraints throughEquivalencePropertiesso downstream physical operators retain them. - Placement rule: Update
is_uniqueinpg_search/src/scan/deferred_placement_rule.rsto treatctidcolumns as unique when evaluating join fan-out.
Source: paradedb/paradedb