# impala-reviews mailing list archives

##### Site index · List index
Message view
Top
From "Taras Bobrovytsky (Code Review)" <ger...@cloudera.org>
Subject [Impala-ASF-CR] IMPALA-4939, IMPALA-4939: Decimal V2 multiplication
Date Sat, 29 Jul 2017 01:59:20 GMT
```Taras Bobrovytsky has uploaded a new patch set (#4).

Change subject: IMPALA-4939, IMPALA-4939: Decimal V2 multiplication
......................................................................

IMPALA-4939, IMPALA-4939: Decimal V2 multiplication

Implement the new DECIMAL return type rules for multiply expressions,
active when query option DECIMAL_V2=1. The algorithm for determining
the type of the result of multiplication is described in the JIRA.

DECIMAL V1:

+-----------------------------------------------------------------------+
| typeof(cast('0.1' as decimal(38,38)) * cast('0.1' as decimal(38,38))) |
+-----------------------------------------------------------------------+
| DECIMAL(38,38)                                                        |
+-----------------------------------------------------------------------+

+-----------------------------------------------------------------------+
| typeof(cast('0.1' as decimal(38,15)) * cast('0.1' as decimal(38,15))) |
+-----------------------------------------------------------------------+
| DECIMAL(38,30)                                                        |
+-----------------------------------------------------------------------+

DECIMAL V2:

+-----------------------------------------------------------------------+
| typeof(cast('0.1' as decimal(38,38)) * cast('0.1' as decimal(38,38))) |
+-----------------------------------------------------------------------+
| DECIMAL(38,37)                                                        |
+-----------------------------------------------------------------------+

+-----------------------------------------------------------------------+
| typeof(cast('0.1' as decimal(38,15)) * cast('0.1' as decimal(38,15))) |
+-----------------------------------------------------------------------+
| DECIMAL(38,6)                                                         |
+-----------------------------------------------------------------------+

In this patch, we also fix the early multiplication overflow. We compute
an int256 intermediate value, which we then attempt to scale down and
round to int128.

Benchmarks:

Query:
select
sum(l_quantity * l_tax) +
sum(l_extendedprice * l_discount)
from lineitem_big;

Before:
DECIMAL_V2 disabled: 6.68s
DECIMAL_V2 enabled : 6.77s

After:
DECIMAL_V2 disabled: 6.66s
DECIMAL_V2 enabled : 6.58s

In the above benchmark, we are selecting from lineitem_big, which has
about 100 times as many rows as the normal lineitem.

Query:
select
sum(l_quantity * l_tax * cast(1 as decimal(38, 37))) +
sum(l_extendedprice * l_discount * cast(1 as decimal(38, 37)))
from lineitem

Before:
DECIMAL_V2 disabled: 0.23s
DECIMAL_V2 enabled : 0.45s

After:
DECIMAL_V2 disabled: 2.65s
DECIMAL_V2 enabled : 2.54s

The query is slower after the patch because the intermediate result is
int256.

Change-Id: I37ad6232d7953bd75c18dc86e665b2b501a1ebe1
---
M be/src/exprs/expr-test.cc
M be/src/runtime/decimal-value.inline.h
M be/src/util/bit-util.h
M fe/src/main/java/org/apache/impala/analysis/TypesUtil.java
4 files changed, 253 insertions(+), 58 deletions(-)

git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/38/7438/4
--
To view, visit http://gerrit.cloudera.org:8080/7438
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I37ad6232d7953bd75c18dc86e665b2b501a1ebe1
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Taras Bobrovytsky <tbobrovytsky@cloudera.com>
Gerrit-Reviewer: Dan Hecht <dhecht@cloudera.com>
Gerrit-Reviewer: Michael Ho <kwho@cloudera.com>
Gerrit-Reviewer: Taras Bobrovytsky <tbobrovytsky@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <tarmstrong@cloudera.com>
Gerrit-Reviewer: Zach Amsden <zamsden@cloudera.com>

```
Mime
View raw message