Re: Parallelize correlated subqueries that execute within each worker

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>, James Coleman <jtc331(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Parallelize correlated subqueries that execute within each worker
Date: 2023-01-18 19:09:21
Message-ID: 1818a285-59b9-e028-c5a8-539f715b9371@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

This patch hasn't been updated since September, and it got broken by
4a29eabd1d91c5484426bc5836e0a7143b064f5a which the incremental sort
stuff a little bit. But the breakage was rather limited, so I took a
stab at fixing it - attached is the result, hopefully correct.

I also added a couple minor comments about stuff I noticed while
rebasing and skimming the patch, I kept those in separate commits.
There's also a couple pre-existing TODOs.

James, what's your plan with this patch. Do you intend to work on it for
PG16, or are there some issues I missed in the thread?

One of the queries in in incremental_sort changed plans a little bit:

explain (costs off) select distinct
unique1,
(select t.unique1 from tenk1 where tenk1.unique1 = t.unique1)
from tenk1 t, generate_series(1, 1000);

switched from

Unique (cost=18582710.41..18747375.21 rows=10000 width=8)
-> Gather Merge (cost=18582710.41..18697375.21 rows=10000000 ...)
Workers Planned: 2
-> Sort (cost=18582710.39..18593127.06 rows=4166667 ...)
Sort Key: t.unique1, ((SubPlan 1))
...

to

Unique (cost=18582710.41..18614268.91 rows=10000 ...)
-> Gather Merge (cost=18582710.41..18614168.91 rows=20000 ...)
Workers Planned: 2
-> Unique (cost=18582710.39..18613960.39 rows=10000 ...)
-> Sort (cost=18582710.39..18593127.06 ...)
Sort Key: t.unique1, ((SubPlan 1))
...

which probably makes sense, as the cost estimate decreases a bit.

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
0001-Add-tests-before-change-v6.patch text/x-patch 7.2 KB
0002-Parallelize-correlated-subqueries-v6.patch text/x-patch 24.9 KB
0003-review-comments-v6.patch text/x-patch 2.0 KB
0004-Possible-additional-checks-v6.patch text/x-patch 2.9 KB
0005-review-comments-v6.patch text/x-patch 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mahmoud Sakr 2023-01-18 19:23:20 Re: Implement missing join selectivity estimation for range types
Previous Message Karl O. Pinc 2023-01-18 19:06:05 Re: Doc: Rework contrib appendix -- informative titles, tweaked sentences