Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cb8b8db

Browse files
author
Commitfest Bot
committed
[CF 52/5482] v20250218 - handle batch explosion in hash joins
This commit was automatically generated by a robot at cfbot.cputube.org. It is based on patches submitted to the PostgreSQL mailing lists and registered in the PostgreSQL Commitfest application. This branch will be overwritten each time a new patch version is posted to the email thread, and also periodically to check for bitrot caused by changes on the master branch. Commitfest entry: https://commitfest.postgresql.org/52/5482 Patch(es): https://www.postgresql.org/message-id/310eeb10-1c75-4361-966a-33fa12970e6e@vondra.me Author(s):
2 parents c623e85 + 396f729 commit cb8b8db

14 files changed

+5635
-1
lines changed

patch/batch-explosion.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
drop table if exists t;
2+
3+
create table t (a int, b text);
4+
5+
copy t from '/tmp/hash-collisions.data';
6+
copy t from '/tmp/hash-collisions.data';
7+
copy t from '/tmp/hash-collisions.data';
8+
copy t from '/tmp/hash-collisions.data';
9+
copy t from '/tmp/hash-collisions.data';
10+
copy t from '/tmp/hash-collisions.data';
11+
copy t from '/tmp/hash-collisions.data';
12+
copy t from '/tmp/hash-collisions.data';
13+
copy t from '/tmp/hash-collisions.data';
14+
copy t from '/tmp/hash-collisions.data';
15+
16+
insert into t select i, md5(i::text) from generate_series(1,1000000) s(i);
17+
18+
create index on t (b);
19+
cluster t USING t_b_idx;
20+
21+
vacuum analyze;
22+
23+
set hash_mem_multiplier = 1.0;
24+
25+
set work_mem = '2MB';
26+
27+
explain select * from t t1 join t t2 on (t1.a = t2.a);
28+
explain analyze select * from t t1 join t t2 on (t1.a = t2.a);
29+
30+
31+
set work_mem = '1MB';
32+
33+
explain select * from t t1 join t t2 on (t1.a = t2.a);
34+
explain analyze select * from t t1 join t t2 on (t1.a = t2.a);
35+
36+
37+
set work_mem = '512kB';
38+
39+
explain select * from t t1 join t t2 on (t1.a = t2.a);
40+
explain analyze select * from t t1 join t t2 on (t1.a = t2.a);
41+
42+
43+
set work_mem = '768kB';
44+
45+
explain select * from t t1 join t t2 on (t1.a = t2.a);
46+
explain analyze select * from t t1 join t t2 on (t1.a = t2.a);

patch/disabled-growth.sql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
drop table if exists t;
2+
3+
create table t (a int, b text);
4+
5+
copy t from '/tmp/hash-collisions.data' ;
6+
7+
-- make it larger than 1MB
8+
insert into t select * from t;
9+
insert into t select * from t;
10+
insert into t select * from t;
11+
12+
-- add a couple redundant columns
13+
alter table t add column r1 double precision, add column r2 double precision, add column r3 double precision, add column r4 double precision;
14+
15+
update t set r1 = 0, r2 = 0, r3 = 0, r4 = 0;
16+
17+
vacuum full t;
18+
19+
insert into t select i, md5(i::text), r, r, r, r from (select i, random() as r from generate_series(1,1000000) s(i) where hashint4(i) > 1000000);
20+
21+
vacuum analyze t;
22+
23+
set max_parallel_workers_per_gather = 0;
24+
25+
set work_mem = '1MB';
26+
27+
explain analyze
28+
select * from t t1 join t t2 on (t1.a = t2.a)
29+
where t1.r1 + 0.0 < 1.0
30+
and t1.r2 + 0.0 < 1.0
31+
and t1.r3 + 0.0 < 1.0
32+
and t1.r4 + 0.0 < 1.0;
33+
34+
set work_mem = '512kB';
35+
36+
explain analyze
37+
select * from t t1 join t t2 on (t1.a = t2.a)
38+
where t1.r1 + 0.0 < 1.0
39+
and t1.r2 + 0.0 < 1.0
40+
and t1.r3 + 0.0 < 1.0
41+
and t1.r4 + 0.0 < 1.0;

patch/disabled-growth2.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
drop table if exists t;
2+
3+
create table t (a int, b text);
4+
5+
-- make sure the hash has first 3 bits set to 0
6+
insert into t select i a, md5(i::text) from generate_series(1,1000000) s(i) where hashint4(i)::bit(32) & 0x0000E000::bit(32) = 0x00000000::bit(32);
7+
8+
insert into t select * from t;
9+
insert into t select * from t;
10+
11+
alter table t add column r1 double precision, add column r2 double precision, add column r3 double precision, add column r4 double precision;
12+
update t set r1 = 0, r2 = 0, r3 = 0, r4 = 0;
13+
14+
vacuum full t;
15+
vacuum analyze t;
16+
17+
set max_parallel_workers_per_gather = 0;
18+
19+
set work_mem = '2MB';
20+
21+
explain analyze
22+
select * from t t1 join t t2 on (t1.a = t2.a)
23+
where t1.r1 + 0.0 < 1.0
24+
and t1.r2 + 0.0 < 1.0
25+
and t1.r3 + 0.0 < 1.0
26+
and t1.r4 + 0.0 < 1.0;
27+
28+
set work_mem = '1MB';
29+
30+
explain analyze
31+
select * from t t1 join t t2 on (t1.a = t2.a)
32+
where t1.r1 + 0.0 < 1.0
33+
and t1.r2 + 0.0 < 1.0
34+
and t1.r3 + 0.0 < 1.0
35+
and t1.r4 + 0.0 < 1.0;
36+
37+
set work_mem = '256kB';
38+
39+
explain analyze
40+
select * from t t1 join t t2 on (t1.a = t2.a)
41+
where t1.r1 + 0.0 < 1.0
42+
and t1.r2 + 0.0 < 1.0
43+
and t1.r3 + 0.0 < 1.0
44+
and t1.r4 + 0.0 < 1.0;

0 commit comments

Comments
 (0)