[
https://issues.apache.org/jira/browse/CALCITE-5913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17754038#comment-17754038
]
Thomas Rebele commented on CALCITE-5913:
----------------------------------------
[~jingda], could you give an example what you mean with returning
{{Set<ImmutableBitSet>}} for {{getFunctionalDependentColumns(ImmutableBitSet
columns)}} being helpful? Just returning an ImmutableBitSet should be enough,
as the following functional dependencies are equivalent, because of
[https://en.wikipedia.org/wiki/Armstrong%27s_axioms#Decomposition] and
[https://en.wikipedia.org/wiki/Armstrong%27s_axioms#Union_(Notation)]:
* X -> Y and X -> Z (represented as a {{{}Set<ImmutableBitSet>{}}})
* X -> YZ (represented as a {{{}ImmutableBitSet{}}})
About the usefulness of {{{}List<FunctionalDependency>
getNontrivialFunctionalDependencies(){}}}: I actually have an algorithm that
needs all the FDs to do some advanced optimizations. Reconstructing them from
{{boolean isFunctionallyDetermined(ImmutableBitSet columns, int column)}} would
be possible, but it does not have the best performance. Therefore I propose to
provide three methods in {{{}FunctionalDependencies{}}}. To make things easier
for the libraries that use Calcite, a class that implements the interface could
be provided. Here a pseudo-code example:
{code:java}
FDBuilder b = new FDBuilder();
b.addFD({empno}, {ssn, ename, sal, comm});
b.addFD({ssn}, {empno, ename, sal, comm});
FunctionalDependenciesImpl fds = b.build();{code}
The object is cached by the class generated by RelMetadataHandlerGeneratorUtil.
It could be cached at the schema level as well.
> Support to get functional dependency metadata in RelMetadataQuery
> -----------------------------------------------------------------
>
> Key: CALCITE-5913
> URL: https://issues.apache.org/jira/browse/CALCITE-5913
> Project: Calcite
> Issue Type: New Feature
> Reporter: JingDas
> Assignee: JingDas
> Priority: Major
>
> Functional dependency analysis can be applied to various problems in query
> optimization:
> selectivity estimation, estimation of (intermediate) result sizes, *order
> optimization*
> *(in particular sort avoidance),* cost estimation, and various problems in
> the area of semantic query optimization, as said in the book《[Exploiting
> Functional Dependence in Query
> Optimization》|https://cs.uwaterloo.ca/research/tr/2000/11/CS-2000-11.thesis.pdf]
>
> In calcite, it may be metadata that something like 'FunctionalDependency'
> BuiltInMetadata as following:
> {code:java}
> public abstract class BuiltInMetadata {
> // ...
> public interface FunctionalDependency extends Metadata {
> /** Returns whether column is functionally dependent on columns. */
> Boolean functionallyDetermine(ImmutableBitSet columns, int column);
> }
> } {code}
>
> As the above book said, functional dependency analysis is a valuable and
> challenging work. I think support order optimization
> (in particular sort avoidance) by the relevant functional dependency metadata
> firstly, and then get complete functional dependency function step by step.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)