Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc068f87

Browse files
committed
Improve bit perturbation in TupleHashTableHash.
The changes inb81b5a9 did not fullyaddress the issue, because the bit-mixing of the IV into the finalhash-key didn't prevent clustering in the input-data survive in theoutput data.This didn't cause a lot of problems because of the additional growthconditions addedd4c62a6. But as wewant to rein those in due to explosive growth in some edges, thisneeds to be fixed.Author: Andres FreundDiscussion:https://postgr.es/m/20171127185700.1470.20362@wrigleys.postgresql.orgBackpatch: 10, where simplehash was introduced
1 parent15be274 commitc068f87

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

‎src/backend/executor/execGrouping.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"executor/executor.h"
2424
#include"miscadmin.h"
2525
#include"utils/lsyscache.h"
26+
#include"utils/hashutils.h"
2627
#include"utils/memutils.h"
2728

2829
staticuint32TupleHashTableHash(structtuplehash_hash*tb,constMinimalTupletuple);
@@ -326,7 +327,7 @@ BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
326327
* underestimated.
327328
*/
328329
if (use_variable_hash_iv)
329-
hashtable->hash_iv=hash_uint32(ParallelWorkerNumber);
330+
hashtable->hash_iv=murmurhash32(ParallelWorkerNumber);
330331
else
331332
hashtable->hash_iv=0;
332333

@@ -510,7 +511,13 @@ TupleHashTableHash(struct tuplehash_hash *tb, const MinimalTuple tuple)
510511
}
511512
}
512513

513-
returnhashkey;
514+
/*
515+
* The way hashes are combined above, among each other and with the IV,
516+
* doesn't lead to good bit perturbation. As the IV's goal is to lead to
517+
* achieve that, perform a round of hashing of the combined hash -
518+
* resulting in near perfect perturbation.
519+
*/
520+
returnmurmurhash32(hashkey);
514521
}
515522

516523
/*

‎src/test/regress/expected/groupingsets.out

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,29 +1183,33 @@ explain (costs off)
11831183
-- simple rescan tests
11841184
select a, b, sum(v.x)
11851185
from (values (1),(2)) v(x), gstest_data(v.x)
1186-
group by grouping sets (a,b);
1186+
group by grouping sets (a,b)
1187+
order by 1, 2, 3;
11871188
a | b | sum
11881189
---+---+-----
1189-
2 | | 6
11901190
1 | | 3
1191+
2 | | 6
1192+
| 1 | 3
11911193
| 2 | 3
11921194
| 3 | 3
1193-
| 1 | 3
11941195
(5 rows)
11951196

11961197
explain (costs off)
11971198
select a, b, sum(v.x)
11981199
from (values (1),(2)) v(x), gstest_data(v.x)
1199-
group by grouping sets (a,b);
1200-
QUERY PLAN
1201-
------------------------------------------
1202-
HashAggregate
1203-
Hash Key: gstest_data.a
1204-
Hash Key: gstest_data.b
1205-
-> Nested Loop
1206-
-> Values Scan on "*VALUES*"
1207-
-> Function Scan on gstest_data
1208-
(6 rows)
1200+
group by grouping sets (a,b)
1201+
order by 3, 1, 2;
1202+
QUERY PLAN
1203+
---------------------------------------------------------------------
1204+
Sort
1205+
Sort Key: (sum("*VALUES*".column1)), gstest_data.a, gstest_data.b
1206+
-> HashAggregate
1207+
Hash Key: gstest_data.a
1208+
Hash Key: gstest_data.b
1209+
-> Nested Loop
1210+
-> Values Scan on "*VALUES*"
1211+
-> Function Scan on gstest_data
1212+
(8 rows)
12091213

12101214
select *
12111215
from (values (1),(2)) v(x),

‎src/test/regress/sql/groupingsets.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,13 @@ explain (costs off)
342342

343343
select a, b,sum(v.x)
344344
from (values (1),(2)) v(x), gstest_data(v.x)
345-
group by grouping sets (a,b);
345+
group by grouping sets (a,b)
346+
order by1,2,3;
346347
explain (costs off)
347348
select a, b,sum(v.x)
348349
from (values (1),(2)) v(x), gstest_data(v.x)
349-
group by grouping sets (a,b);
350-
350+
group by grouping sets (a,b)
351+
order by3,1,2;
351352
select*
352353
from (values (1),(2)) v(x),
353354
lateral (select a, b,sum(v.x)from gstest_data(v.x)group by grouping sets (a,b)) s;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp