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 247A6200CE0 for ; Thu, 27 Jul 2017 03:03:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 23001169E4B; Thu, 27 Jul 2017 01:03:58 +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 67355169E4A for ; Thu, 27 Jul 2017 03:03:57 +0200 (CEST) Received: (qmail 97936 invoked by uid 500); 27 Jul 2017 01:03:56 -0000 Mailing-List: contact reviews-help@impala.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@impala.incubator.apache.org Received: (qmail 97912 invoked by uid 99); 27 Jul 2017 01:03:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Jul 2017 01:03:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 746AF1A0AB8 for ; Thu, 27 Jul 2017 01:03:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.362 X-Spam-Level: X-Spam-Status: No, score=0.362 tagged_above=-999 required=6.31 tests=[RDNS_DYNAMIC=0.363, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id fetWp79wvDZf for ; Thu, 27 Jul 2017 01:03:54 +0000 (UTC) Received: from ip-10-146-233-104.ec2.internal (ec2-75-101-130-251.compute-1.amazonaws.com [75.101.130.251]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id CB8F15F6C0 for ; Thu, 27 Jul 2017 01:03:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ip-10-146-233-104.ec2.internal (8.14.4/8.14.4) with ESMTP id v6R13plh017986; Thu, 27 Jul 2017 01:03:51 GMT Message-Id: <201707270103.v6R13plh017986@ip-10-146-233-104.ec2.internal> Date: Thu, 27 Jul 2017 01:03:51 +0000 From: "Zach Amsden (Code Review)" To: Taras Bobrovytsky , impala-cr@cloudera.com, reviews@impala.incubator.apache.org CC: Dan Hecht , Tim Armstrong , Michael Ho Reply-To: zamsden@cloudera.com X-Gerrit-MessageType: comment Subject: =?UTF-8?Q?=5BImpala-ASF-CR=5D_IMPALA-4939=2C_IMPALA-4939=3A_Decimal_V2_multiplication=0A?= X-Gerrit-Change-Id: I37ad6232d7953bd75c18dc86e665b2b501a1ebe1 X-Gerrit-ChangeURL: X-Gerrit-Commit: 1f53f6fbf0943643efba76065d095604f829d6ad In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/2.12.7 archived-at: Thu, 27 Jul 2017 01:03:58 -0000 Zach Amsden has posted comments on this change. Change subject: IMPALA-4939, IMPALA-4939: Decimal V2 multiplication ...................................................................... Patch Set 1: (5 comments) http://gerrit.cloudera.org:8080/#/c/7438/1/be/src/exprs/expr-test.cc File be/src/exprs/expr-test.cc: Line 1554: } > I think we aren't using 128 bit literals in that many places in our codebas Agreed, this is fine for now. http://gerrit.cloudera.org:8080/#/c/7438/1/be/src/runtime/decimal-value.inline.h File be/src/runtime/decimal-value.inline.h: Line 301: needs_int256 = DecimalUtil::MAX_UNSCALED_DECIMAL16 / abs(y) < abs(x); > Are you talking about using some existing special functions for counting th A while loop will perform terribly, but there are intrinsics that can be used to count the zeros efficiently. If we do that, this division can be optimized away if we note the number of zeros in the absolute value of the multiplicands is greater than 128. We still need to check for a value > MAX_UNSCALED_DECIMAL16, but I think this could be a win over the division. Maybe just adding a note or TODO for this for now. http://gerrit.cloudera.org:8080/#/c/7438/1/be/src/util/bit-util.h File be/src/util/bit-util.h: Line 65: return value < 0 ? -1 : 1; > The way it was written before didn't work with int256, so I made this chang I think we want to think carefully about using the Sign function with int256. That boost type is likely to do something crazy here no matter what we code. It's also always signed, and shifting it is a really bad idea. Doing anything with it at all aside from the multiplication is going to be less than optimal. Can we cheat and round in 128 bit precision instead? I.e... int256 prod = x * y; result = prod / scale_multiplier; remainder = prod % scale_multiplier; // scale multiplier is always a power of 2, so if (remainder > scale_multiplier >> 1) result = RoundAwayFromZero(result) If we can get both remainder and quotient together without added cost from Boost, that is. Worth running a simple benchmark to test, how about using TPC-DS and running: sum(l_quantity * l_tax) | sum(l_extendedprice * l_discount) http://gerrit.cloudera.org:8080/#/c/7438/1/be/src/util/decimal-util.h File be/src/util/decimal-util.h: Line 336: if (LIKELY(scale < 77)) return values[scale]; > It is possible to get large values, but when we are Dividing, not multiplyi Really? That's crazy. Can we actually kill GetScaleMultiplier then? http://gerrit.cloudera.org:8080/#/c/7438/1/fe/src/main/java/org/apache/impala/analysis/TypesUtil.java File fe/src/main/java/org/apache/impala/analysis/TypesUtil.java: Line 260: resultPrecision = p1 + p2 + 1; > I agree that the +1 is messy, but to be compatible with other systems and f I think the 0.999 * 0.999 case is a fluke - we are sacrificing precision for every single other maximum precision case just for the 1e-74 chance that this one case rounds nicely. I'd strongly prefer to see the crazy +1 go the way of the dodo, understand the compatibility argument, but wonder how important that actually is. -- To view, visit http://gerrit.cloudera.org:8080/7438 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-MessageType: comment Gerrit-Change-Id: I37ad6232d7953bd75c18dc86e665b2b501a1ebe1 Gerrit-PatchSet: 1 Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-Owner: Taras Bobrovytsky Gerrit-Reviewer: Dan Hecht Gerrit-Reviewer: Michael Ho Gerrit-Reviewer: Taras Bobrovytsky Gerrit-Reviewer: Tim Armstrong Gerrit-Reviewer: Zach Amsden Gerrit-HasComments: Yes