| From: | Alexandre Felipe <o(dot)alexandre(dot)felipe(at)gmail(dot)com> |
|---|---|
| To: | yanarnold5(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19708: Hash Join becomes about 300x slower with higher work_mem |
| Date: | 2026-09-20 20:05:17 |
| Message-ID: | CAE8JnxMt2Ve9fZBtT6uGJ6OEL_UX10173prEyu8VjHh1x91XFQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Iany,
Thank you for the report, and the nice reproduction script.
Your query grows with the 4th power of the number of rows, and the table
statistics
show 2910 rows for that table. So the plan estimates 211 quadrillion rows,
see
a decluttered plan showing the row estimates.
Hash Join (rows=211477613278003200) -- (m * n^2)^2 / (200)
Hash Cond: (l.g = r.g)
CTE x
-> Nested Loop (rows=6503500800) -- m * n ^2
-> Function Scan on generate_series g (rows=768) -- m
-> Materialize (rows=8468100) -- n^2
-> Nested Loop (rows=8468100) -- n^2
-> Seq Scan on a a1 (rows=2910) -- n
-> Materialize (rows=2910) -- n
-> Seq Scan on a a2 (rows=2910) -- n
-> CTE Scan on x l (rows=6503500800) -- m * n^2
-> Hash (rows=6503500800) -- m * n^2
-> CTE Scan on x r (rows=6503500800) -- m * n ^ 2
> CREATE TABLE a();
> INSERT INTO a DEFAULT VALUES;
If you run an analyse here you get an accurate estimate of the number rows
in the table.
If analyse your table before the table
----
CREATE TABLE a();
INSERT INTO a DEFAULT VALUES;
+ANALYSE a;
SET enable_mergejoin = off;
----
It uses the same plan
work_mem exec time
64 kB 0.271 ms
16 MB 0.227 ms
Would you be able to reproduce the issue having rows = actual rows in the
plans.
--
Alexandre
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexandre Felipe | 2026-09-20 20:35:48 | Re: BUG #19622: io_method=worker retains file descriptors on dropped relations |
| Previous Message | shihao zhong | 2026-09-20 19:29:28 | Re: BUG #19703: information_schema.usage_privileges omits a sequence owner's implicit USAGE privilege |