Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/181#discussion_r104604315 --- Diff: query_optimizer/ExecutionGenerator.cpp --- @@ -679,13 +688,72 @@ void ExecutionGenerator::convertFilterJoin(const P::FilterJoinPtr &physical_plan std::piecewise_construct, std::forward_as_tuple(physical_plan), std::forward_as_tuple(probe_relation_info->producer_operator_index, - probe_relation_info->relation)); + probe_relation_info->relation, + probe_relation_info->output_destination_index)); DCHECK(lip_filter_generator_ != nullptr); lip_filter_generator_->addFilterJoinInfo(physical_plan, build_filter_operator_index); } +namespace { + +bool areSamePartitionSchemeHeaders(const PartitionSchemeHeader &lhs_partition_header, + const CatalogRelationSchema &lhs_scheme, + const PartitionSchemeHeader &rhs_partition_header, + const CatalogRelationSchema &rhs_scheme) { + if (lhs_partition_header.getPartitionType() != rhs_partition_header.getPartitionType()) { + return false; + } + + if (lhs_partition_header.getNumPartitions() != rhs_partition_header.getNumPartitions()) { + return false; + } + + // Check whether the underlying types in CatalogAttribute are the same. + if (!lhs_scheme.getAttributeById(lhs_partition_header.getPartitionAttributeId())->getType().equals( + rhs_scheme.getAttributeById(rhs_partition_header.getPartitionAttributeId())->getType())) { + return false; + } + + switch (lhs_partition_header.getPartitionType()) { + case PartitionSchemeHeader::PartitionType::kHash: + return true; + case PartitionSchemeHeader::PartitionType::kRange: { + const vector<TypedValue> &lhs_ranges = + static_cast<const RangePartitionSchemeHeader&>(lhs_partition_header).getPartitionRangeBoundaries(); + const vector<TypedValue> &rhs_ranges = + static_cast<const RangePartitionSchemeHeader&>(rhs_partition_header).getPartitionRangeBoundaries(); + + return lhs_ranges == rhs_ranges; + } + } + + return false; +} + + +// Note that this method will be deprecated once the partition scheme header +// supports multiple partition attributes. +size_t chooseBestRepartitionAttributeIndex(const CatalogRelationStatistics &stats, + const vector<attribute_id> &join_attributes) { + size_t chose_attr_index = static_cast<size_t>(-1); + size_t chose_attr_num_distinct_values = 0; + + for (std::size_t i = 0; i < join_attributes.size(); ++i) { + const attribute_id attr = join_attributes[i]; + if (stats.hasNumDistinctValues(attr) && + stats.getNumDistinctValues(attr) > chose_attr_num_distinct_values) { + chose_attr_index = i; + chose_attr_num_distinct_values = stats.getNumDistinctValues(attr); + } + } + + return (chose_attr_index != static_cast<size_t>(-1)) ? chose_attr_index : 0; --- End diff -- In a hash join, if both relations are using range partitions, we need to repartition both relations. Here we use this method to pick up the best single attribute for the new hash repartition. By best, we mean the maximum number of distinct values to minimize the hash collision. Finally, once we support multiple partition attributes, we don't need this method.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---