Interface SqlStatisticProvider

All Known Implementing Classes:
CachingSqlStatisticProvider, MapSqlStatisticProvider, QuerySqlStatisticProvider

public interface SqlStatisticProvider
Estimates row counts for tables and columns, and whether combinations of columns form primary/unique and foreign keys.

Unlike LatticeStatisticProvider, works on raw tables and columns and does not need a Lattice.

It uses RelOptTable because that contains enough information to generate and execute SQL, while not being tied to a lattice.

The main implementation, QuerySqlStatisticProvider, executes queries on a populated database. Implementations that use database statistics (from ANALYZE TABLE, etc.) and catalog information (e.g. primary and foreign key constraints) would also be possible.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isForeignKey(RelOptTable fromTable, List<Integer> fromColumns, RelOptTable toTable, List<Integer> toColumns)
    Returns whether a join is a foreign key; that is, whether every row in the referencing table is matched by at least one row in the referenced table.
    boolean
    isKey(RelOptTable table, List<Integer> columns)
    Returns whether a collection of columns is a unique (or primary) key.
    double
    Returns an estimate of the number of rows in table.
  • Method Details

    • tableCardinality

      double tableCardinality(RelOptTable table)
      Returns an estimate of the number of rows in table.
    • isForeignKey

      boolean isForeignKey(RelOptTable fromTable, List<Integer> fromColumns, RelOptTable toTable, List<Integer> toColumns)
      Returns whether a join is a foreign key; that is, whether every row in the referencing table is matched by at least one row in the referenced table.

      For example, isForeignKey(EMP, [DEPTNO], DEPT, [DEPTNO]) returns true.

      To change "at least one" to "exactly one", you also need to call isKey(org.apache.calcite.plan.RelOptTable, java.util.List<java.lang.Integer>).

    • isKey

      boolean isKey(RelOptTable table, List<Integer> columns)
      Returns whether a collection of columns is a unique (or primary) key.

      For example, isKey(EMP, [DEPTNO] returns true; isKey(DEPT, [DEPTNO] returns false.