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 1uBLe6-000Roz-Mb for pgsql-bugs@arkaria.postgresql.org; Sat, 03 May 2025 22:47:47 +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 1uBLe5-00GVxo-OP for pgsql-bugs@arkaria.postgresql.org; Sat, 03 May 2025 22:47:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uBLe5-00GVxc-GJ for pgsql-bugs@lists.postgresql.org; Sat, 03 May 2025 22:47:45 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uBLe2-0001JU-1r for pgsql-bugs@lists.postgresql.org; Sat, 03 May 2025 22:47:45 +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 543MlXpQ2221241; Sat, 3 May 2025 18:47:33 -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: 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> <2216372.1746309806@sss.pgh.pa.us> Comments: In-reply-to Sergey Koposov message dated "Sat, 03 May 2025 22:30:19 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2221239.1746312453.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 03 May 2025 18:47:33 -0400 Message-ID: <2221240.1746312453@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sergey Koposov writes: > wsdb=3D> set cursor_tuple_fraction TO 1; > SET > wsdb=3D> EXPLAIN DECLARE c CURSOR FOR select phot_g_mean_mag,phot_bp_m= ean_mag,phot_rp_mean_mag, > g.source_id,pmra,pmdec,parallax,parallax_error,d.ra,d.dec,d.ebv,d.gmeanp= sfmag,rmeanpsfmag,imeanpsfmag,gkronmag,rkronmag from disk_sample1 as d l= eft join > gaia_edr3_aux.panstarrs1bestneighbour as gaps1 on (gaps1.original_ext_so= urce_id=3Dd.objid) left join gaia_edr3.gaia_source as g on ( g.source_id = =3D gaps1.source_id > ) ; > QUERY PLAN > ------------------------------------------------------------------------= --------------------------------------- > Hash Right Join (cost=3D112529534.06..422118114.74 rows=3D65470868 wid= th=3D100) > Hash Cond: (g.source_id =3D gaps1.source_id) > -> Seq Scan on gaia_source g (cost=3D0.00..124645680.12 rows=3D1811= 786112 width=3D48) > -> Hash (cost=3D111007847.21..111007847.21 rows=3D65470868 width=3D= 60) > -> Hash Right Join (cost=3D3231089.53..111007847.21 rows=3D65= 470868 width=3D60) > Hash Cond: (gaps1.original_ext_source_id =3D d.objid) > -> Seq Scan on panstarrs1bestneighbour gaps1 (cost=3D0.= 00..17443258.96 rows=3D951450496 width=3D16) > -> Hash (cost=3D1709402.68..1709402.68 rows=3D65470868 = width=3D60) > -> Seq Scan on disk_sample1 d (cost=3D0.00..17094= 02.68 rows=3D65470868 width=3D60) Oh, *that* is interesting: now we have two hash joins, and neither one has panstarrs1bestneighbour as the table to hash, so it's not too clear which one is going crazy. But you showed the stats for disk_sample1.objid, and that looked pretty well distributed, so I'm going to guess that that hash is fine. That leaves the other join on panstarrs1bestneighbour.source_id as the one under suspicion. Can we see the stats for that column? regards, tom lane