Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 97CAC200C30 for ; Tue, 7 Mar 2017 08:40:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 964EB160B74; Tue, 7 Mar 2017 07:40:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E205B160B68 for ; Tue, 7 Mar 2017 08:40:32 +0100 (CET) Received: (qmail 99052 invoked by uid 500); 7 Mar 2017 07:40:32 -0000 Mailing-List: contact dev-help@quickstep.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@quickstep.incubator.apache.org Delivered-To: mailing list dev@quickstep.incubator.apache.org Received: (qmail 99041 invoked by uid 99); 7 Mar 2017 07:40:31 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2017 07:40:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 5A41CC00B6 for ; Tue, 7 Mar 2017 07:40:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.02 X-Spam-Level: X-Spam-Status: No, score=-4.02 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id GRZgly_SajXo for ; Tue, 7 Mar 2017 07:40:30 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 396915F1EE for ; Tue, 7 Mar 2017 07:40:29 +0000 (UTC) Received: (qmail 99031 invoked by uid 99); 7 Mar 2017 07:40:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2017 07:40:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4706CDFC4A; Tue, 7 Mar 2017 07:40:28 +0000 (UTC) From: zuyu To: dev@quickstep.incubator.apache.org Reply-To: dev@quickstep.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-quickstep pull request #181: Added limited optimizer support for P... Content-Type: text/plain Message-Id: <20170307074028.4706CDFC4A@git1-us-west.apache.org> Date: Tue, 7 Mar 2017 07:40:28 +0000 (UTC) archived-at: Tue, 07 Mar 2017 07:40:33 -0000 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 &lhs_ranges = + static_cast(lhs_partition_header).getPartitionRangeBoundaries(); + const vector &rhs_ranges = + static_cast(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 &join_attributes) { + size_t chose_attr_index = static_cast(-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(-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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---