Class StatisticsDistinctnessSource

java.lang.Object
com.darkcollective.relix.cost.StatisticsDistinctnessSource
All Implemented Interfaces:
DistinctnessSource

public final class StatisticsDistinctnessSource extends Object implements DistinctnessSource
A DistinctnessSource that reads duplicate-freeness off a leaf relation's declared keys — the base-relation half of the seam, complementing the generator-backed source that covers Range/Naturals/Primes.

A relation with at least one candidate key in its RelationStatistics is duplicate-free by definition: a key uniquely identifies a row, so no two rows can be equal. This is what lets DIST-001 remove a δ applied directly to a primary-keyed table.

The keys come from wherever the statistics did — for JDBC relations, the primary key read from DatabaseMetaData.getPrimaryKeys; for inline relations, single-column uniqueness computed exactly. A relation with statistics but no declared key reports false: a row count alone says nothing about duplicates. Sources that are never introspected (CSV, Mongo, HTTP) carry no statistics at all and so correctly report false.

Leaves only. This answers for a RelationNode as it stands; distinctness through a projection of a key is a separate and harder question that PropertyDeriver deliberately does not attempt.

See Also:
  • Constructor Details

    • StatisticsDistinctnessSource

      public StatisticsDistinctnessSource(StatisticsSource statistics)
      Creates a distinctness source over the given statistics.
      Parameters:
      statistics - the per-relation statistics lookup; must not be null (use StatisticsSource.NONE for none, which makes this source equivalent to DistinctnessSource.NONE)
  • Method Details

    • duplicateFreeLeaf

      public boolean duplicateFreeLeaf(String relationName)
      Specified by:
      duplicateFreeLeaf in interface DistinctnessSource
      Parameters:
      relationName - the leaf relation name; never null
      Returns:
      true when the named relation has at least one candidate key