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 1uBKxO-000Jj0-G9 for pgsql-bugs@arkaria.postgresql.org; Sat, 03 May 2025 22:03:38 +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 1uBKxN-00GMA4-C1 for pgsql-bugs@arkaria.postgresql.org; Sat, 03 May 2025 22:03:37 +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 1uBKxN-00GM9w-3T for pgsql-bugs@lists.postgresql.org; Sat, 03 May 2025 22:03:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uBKxK-0000tn-19 for pgsql-bugs@lists.postgresql.org; Sat, 03 May 2025 22:03:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 543M3Qgc2216373; Sat, 3 May 2025 18:03:26 -0400 From: Tom Lane To: Sergey Koposov cc: "lepihov@gmail.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #18909: Query creates millions of temporary files and stalls In-reply-to: <0ce957be37434cfca4820d1e89a70cb2b456d3db.camel@ed.ac.uk> References: <18909-e5e1b702c9441b8a@postgresql.org> <2051617.1746223978@sss.pgh.pa.us> <5e98fba645682c40bf5f88ef858963ade9681956.camel@ed.ac.uk> <2177960.1746289626@sss.pgh.pa.us> <80bab58be182e80e73b5d5f71664ede9ce58f957.camel@ed.ac.uk> <8fc51cd7-115a-425a-828e-c99defb5afef@gmail.com> <0ce957be37434cfca4820d1e89a70cb2b456d3db.camel@ed.ac.uk> Comments: In-reply-to Sergey Koposov message dated "Sat, 03 May 2025 21:50:04 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2216371.1746309806.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 03 May 2025 18:03:26 -0400 Message-ID: <2216372.1746309806@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sergey Koposov writes: > -> Parallel Hash Left Join (cost=3D14442102.04..22124798.60 r= ows=3D16367717 width=3D60) (actual time=3D209805.943..273008.489 rows=3D13= 102859 loops=3D5) > Hash Cond: (d.objid =3D gaps1.original_ext_source_id) > -> Parallel Seq Scan on disk_sample1 d (cost=3D0.00..12= 18371.17 rows=3D16367717 width=3D60) (actual time=3D37.353..25185.340 rows= =3D13095751 loops=3D5) > -> Parallel Hash (cost=3D10307380.24..10307380.24 rows=3D= 237862624 width=3D16) (actual time=3D169633.067..169633.068 rows=3D1902900= 95 loops=3D5) > Buckets: 67108864 Batches: 32 Memory Usage: 19199= 04kB > -> Parallel Seq Scan on panstarrs1bestneighbour ga= ps1 (cost=3D0.00..10307380.24 rows=3D237862624 width=3D16) (actual time=3D= 132.295..117548.803 > rows=3D190290095 loops=3D5) Hm, interesting. The number of batches stayed sane here (32), whereas it went crazy in the other run. I wonder if there's something nondeterministic about that choice in a parallel hash join. > I don't think I know how to see the plan of the declare cursor query. EXPLAIN DECLARE c CURSOR FOR SELECT ... regards, tom lane