[
https://issues.apache.org/jira/browse/CALCITE-5913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17754211#comment-17754211
]
Julian Hyde commented on CALCITE-5913:
--------------------------------------
[~thomas.rebele], I don't know the right interface. We need to balance ease of
use for consumers of the metadata with ease of implementation for producers,
and efficiency when caching and re-computing metadata.
The implementation of your proposed interface {{ImmutableBitSet
getFunctionalDependentColumns(ImmutableBitSet columns)}} would in most cases be
nothing more than calling seems to be no more than calling {{boolean
isFunctionallyDetermined(ImmutableBitSet columns, int column)}} for each
column, so there doesn't seem to be a clear performance win.
We will also want to ask which columns determine an expression ({{RexNode}}).
The hardest thing will be taking predicates into account. Those predicates are
expressions, and those expressions are made up of columns, so we may have to
deal with cycles. We may end up with an algorithm that iterates until it
reaches a fixed point. Or it may be simpler to compute pointwise (my original
proposed interface). When we have a corpus of tests in {{RelMetadataTest}} -
including some tough cases including predicates - we should reconsider the
interface.
> 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)