[ https://issues.apache.org/jira/browse/CALCITE-2658?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16708078#comment-16708078 ]
Julian Hyde edited comment on CALCITE-2658 at 12/4/18 2:03 AM: --------------------------------------------------------------- Reviewing PR 921 ExchangeRemoveConstantKeysRule: * You have mutable state inside the rule, {{hashDistribution}}. Can you remove that? Rule instances need to be thread-safe. * I think you should change Distributions.hash to return a singleton distribution if the keys are empty (and change its javadoc). * Can you add more description to the rules' javadoc about what 'removing constant keys' means. Maybe a SQL example. * Maybe I'm paranoid, but simplifyDistributionKeys seems to be allocating rather a lot of objects. Rather than speculatively creating {{RexInputRef}} objects, could you look for constants of type {{RexInputRef}} and then see whether that bit is a distribution key. And check whether you can simplify before you start to simplify. was (Author: julianhyde): Reviewing PR 921 ExchangeRemoveConstantKeysRule: * You have mutable state inside the rule, {{hashDistribution}}. Can you remove that? Rule instances need to be thread-safe. * I think you should change Distributions.hash to return a singleton distribution if the keys are empty (and change its javadoc). * Can you add more description to the rules' javadoc about what 'removing constant keys' means. Maybe a SQL example. * Maybe I'm paranoid, but simplifyDistributionKeys seems to be allocating rather a lot of objects. Rather than speculatively creating {{RexInputRef}}s, could you look for {{RexInputRef}}s that are constants and then see whether that bit is set in the distribution. And check whether you can simplify before you start to simplify. > Introducing more ReduceExpressionRules > -------------------------------------- > > Key: CALCITE-2658 > URL: https://issues.apache.org/jira/browse/CALCITE-2658 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.17.0 > Reporter: Chunwei Lei > Assignee: Julian Hyde > Priority: Major > Fix For: 1.18.0 > > > It is useful to have rules reducing Exchange/Sort/SortExchange keys, e.g., > SELECT key,value FROM (SELECT 1 AS key, value FROM src) r DISTRIBUTE BY key; > can be reduced to > SELECT 1 AS key, value FROM src; # Since singleton requirement may already > required by SELECT. > SELECT key,value FROM (SELECT 1 AS key, value FROM src) r ORDER BY key; > can be reduced to > SELECT 1 AS key, value FROM src; # Since ordering on constant is useless. -- This message was sent by Atlassian JIRA (v7.6.3#76005)