Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uXKYU-008YIr-HH for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Jul 2025 14:04:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uXKYR-00DguZ-Sv for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Jul 2025 14:04:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uXKYQ-00DguL-Pp for pgsql-hackers@lists.postgresql.org; Thu, 03 Jul 2025 14:04:48 +0000 Received: from m16.mail.163.com ([220.197.31.3]) by makus.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1uXKYK-005N2B-2c for pgsql-hackers@postgresql.org; Thu, 03 Jul 2025 14:04:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=spI9AtSkXLky+8E79Tms8Rp7Hrtr9QJMle8sdXk49h4=; b=KXyLPo3CvW1IzHncEGqtVJTfiWac2CDobFHtXBgiutCvtAwWQX27Sjkubfd5ej Y1krE4oLcUy0QLreb8g0cVOnpMFqkjFsLaIuo+xOhtVqVj4VKRGVMk5kAQXWgqsk 0iB2SWk7Mq+Sl/B1OP2w71/yby12qy1wmOW34OEGHIUpc= Received: from lovely-coding (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB306fmjWZozRh2CQ--.44284S3; Thu, 03 Jul 2025 22:04:22 +0800 (CST) From: Andy Fan To: James Coleman Cc: Tomas Vondra , vignesh C , Andres Freund , Robert Haas , pgsql-hackers , Amit Kapila , Tom Lane Subject: Re: Parallelize correlated subqueries that execute within each worker In-Reply-To: (James Coleman's message of "Wed, 18 Jan 2023 21:34:21 -0500") References: <20220322004805.vwmgjp62tq3mj2oq@alap3.anarazel.de> <1818a285-59b9-e028-c5a8-539f715b9371@enterprisedb.com> Date: Thu, 03 Jul 2025 14:04:22 +0000 Message-ID: <87frfd9xqx.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wB306fmjWZozRh2CQ--.44284S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr4fKrykZr1DZw15tF47Arb_yoW8Ww4UpF 98ta4j9F4UXryUXFsFqrW2vrZ8GryIvFy8trWrWasYkF43JrWqqasagr4UCr9Y9rW8G3y0 ya17trn8trWkAa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Uvg4hUUUUU= X-Originating-IP: [219.151.191.82] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBhQt-U2hmiG90DgAAsx List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi James: Very nice to find this topic, I am recently working on this topic [1] as well without finding this topic has been discussed before. I just go through this thread and find it goes with a different direction with mine. would you mind to check my soluation to see is there any case I can't cover? I suggested this because my soluation should be much easier than yours. But I'm not suprised to know I'm miss some obvious keypoint. > >> 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. > > Off the cuff that seems fine. I'll read it over again when I send the > updated series. I had a detailed explaination for this plan change in [1] and I think this could be amazing gain no matter which way we go finally. [1] https://www.postgresql.org/message-id/871pqzm5wj.fsf@163.com -- Best Regards Andy Fan