Merge pull request #6380 from 4ertus2/perf

Hotfix for Decimal comparison
This commit is contained in:
alexey-milovidov 2019-08-08 03:04:07 +03:00 committed by GitHub
commit b06bb0a9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View File

@ -26,10 +26,12 @@ namespace ErrorCodes
template <typename T>
int ColumnDecimal<T>::compareAt(size_t n, size_t m, const IColumn & rhs_, int) const
{
auto other = static_cast<const Self &>(rhs_);
auto & other = static_cast<const Self &>(rhs_);
const T & a = data[n];
const T & b = other.data[m];
if (scale == other.scale)
return a > b ? 1 : (a < b ? -1 : 0);
return decimalLess<T>(b, a, other.scale, scale) ? 1 : (decimalLess<T>(a, b, scale, other.scale) ? -1 : 0);
}

View File

@ -0,0 +1,30 @@
<test>
<tags>
<tag>sorting</tag>
<tag>comparison</tag>
</tags>
<type>loop</type>
<stop_conditions>
<all_of>
<iterations>5</iterations>
<min_time_not_changing_for_ms>10000</min_time_not_changing_for_ms>
</all_of>
<any_of>
<iterations>50</iterations>
<total_time_ms>60000</total_time_ms>
</any_of>
</stop_conditions>
<query>SELECT toInt32(number) AS n FROM numbers(1000000) ORDER BY n DESC</query>
<query>SELECT toDecimal32(number, 0) AS n FROM numbers(1000000) ORDER BY n</query>
<query>SELECT toDecimal32(number, 0) AS n FROM numbers(1000000) ORDER BY n DESC</query>
<query>SELECT toDecimal64(number, 8) AS n FROM numbers(1000000) ORDER BY n DESC</query>
<query>SELECT toDecimal128(number, 10) AS n FROM numbers(1000000) ORDER BY n DESC</query>
<main_metric>
<min_time/>
</main_metric>
</test>

View File

@ -0,0 +1,2 @@
1000000
1000000

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1 (str String, dec Decimal64(8)) ENGINE = MergeTree ORDER BY str;
CREATE TABLE t2 (str String, dec Decimal64(8)) ENGINE = MergeTree ORDER BY dec;
INSERT INTO t1 SELECT toString(number), toDecimal64(number, 8) FROM system.numbers LIMIT 1000000;
SELECT count() FROM t1;
INSERT INTO t2 SELECT toString(number), toDecimal64(number, 8) FROM system.numbers LIMIT 1000000;
SELECT count() FROM t2;
DROP TABLE t1;
DROP TABLE t2;