Package org.apache.calcite.statistic
Class QuerySqlStatisticProvider
java.lang.Object
org.apache.calcite.statistic.QuerySqlStatisticProvider
- All Implemented Interfaces:
SqlStatisticProvider
Implementation of
SqlStatisticProvider
that generates and executes
SQL queries.-
Field Summary
Modifier and TypeFieldDescriptionstatic final SqlStatisticProvider
Instance that uses SQL to compute statistics, does not log SQL statements, and caches up to 1,024 results for up to 30 minutes.static final SqlStatisticProvider
AsSILENT_CACHING_INSTANCE
but prints SQL statements toSystem.out
. -
Constructor Summary
ConstructorDescriptionQuerySqlStatisticProvider
(Consumer<String> sqlConsumer) Creates a QuerySqlStatisticProvider. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
tableCardinality
(RelOptTable table) Returns an estimate of the number of rows intable
.protected String
toSql
(RelNode rel, SqlDialect dialect)
-
Field Details
-
SILENT_CACHING_INSTANCE
Instance that uses SQL to compute statistics, does not log SQL statements, and caches up to 1,024 results for up to 30 minutes. (That period should be sufficient for the duration of Calcite's tests, and many other purposes.) -
VERBOSE_CACHING_INSTANCE
AsSILENT_CACHING_INSTANCE
but prints SQL statements toSystem.out
.
-
-
Constructor Details
-
QuerySqlStatisticProvider
Creates a QuerySqlStatisticProvider.- Parameters:
sqlConsumer
- Called when each SQL statement is generated
-
-
Method Details
-
tableCardinality
Description copied from interface:SqlStatisticProvider
Returns an estimate of the number of rows intable
.- Specified by:
tableCardinality
in interfaceSqlStatisticProvider
-
isForeignKey
public boolean isForeignKey(RelOptTable fromTable, List<Integer> fromColumns, RelOptTable toTable, List<Integer> toColumns) Description copied from interface:SqlStatisticProvider
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
SqlStatisticProvider.isKey(org.apache.calcite.plan.RelOptTable, java.util.List<java.lang.Integer>)
.- Specified by:
isForeignKey
in interfaceSqlStatisticProvider
-
isKey
Description copied from interface:SqlStatisticProvider
Returns whether a collection of columns is a unique (or primary) key.For example,
isKey(EMP, [DEPTNO]
returns true;isKey(DEPT, [DEPTNO]
returns false.- Specified by:
isKey
in interfaceSqlStatisticProvider
-
toSql
-