#6505·paradedb

Declare ctid uniqueness and non-null system column constraints to DataFusion

Author: stuhoodCreated Sep 26, 2026Updated Sep 29, 2026
Labelsfeaturegood first issuepriority-mediumperformance

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 on ctid (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 redundant DISTINCT nodes when querying or grouping by ctid.
  • Filter::is_scalar(): Enables max_rows == Some(1) on scalar ctid equality filters.
  • optimize_projections: Prunes non-grouping columns in GROUP BY ctid, ... when unneeded by parent nodes, because ctid functionally determines all columns in that table scan.
  • deferred_placement_rule: Recognizes that joins on ctid do 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 marked attnotnull rather than marking all Arrow fields nullable.
  • TableProvider constraints: Implement TableProvider::constraints on PgSearchTableProvider (pg_search/src/scan/table_provider.rs) to declare ctid / DeferredCtid as a Constraint::PrimaryKey.
  • Physical plan propagation: Ensure PgSearchScanPlan (pg_search/src/scan/execution_plan.rs) and physical helpers like preserved_ordering (pg_search/src/scan/deferred_lookup.rs) carry constraints through EquivalenceProperties so downstream physical operators retain them.
  • Placement rule: Update is_unique in pg_search/src/scan/deferred_placement_rule.rs to treat ctid columns as unique when evaluating join fan-out.