Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4vk4-0003Wb-5u for pgsql-admin@arkaria.postgresql.org; Wed, 18 Oct 2017 21:19:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e4vk3-0000VT-K6 for pgsql-admin@arkaria.postgresql.org; Wed, 18 Oct 2017 21:19:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e4viC-0002a8-FL for pgsql-admin@postgresql.org; Wed, 18 Oct 2017 21:17:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e4vi9-0003ul-Tg for pgsql-admin@postgresql.org; Wed, 18 Oct 2017 21:17:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v9ILH6Vu022676; Wed, 18 Oct 2017 17:17:07 -0400 From: Tom Lane To: "Hartranft, Robert M. (GSFC-423.0)[RAYTHEON CO]" cc: "pgsql-admin@postgresql.org" Subject: Re: question on hash joins In-reply-to: <63F14C4C-1518-4EAA-9EBE-87222988F073@nasa.gov> References: <60286BB5-0A38-42C8-A673-5289CA6D2354@nasa.gov> <63F14C4C-1518-4EAA-9EBE-87222988F073@nasa.gov> Comments: In-reply-to "Hartranft, Robert M. (GSFC-423.0)[RAYTHEON CO]" message dated "Wed, 18 Oct 2017 20:00:14 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22674.1508361426.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 18 Oct 2017 17:17:06 -0400 Message-ID: <22675.1508361426@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org "Hartranft, Robert M. (GSFC-423.0)[RAYTHEON CO]" writes: > explain select count(1) from table1 g join table2 x on x.granuleid =3D g.= granuleid where g.collectionid =3D 22467; > QUERY PLAN > -------------------------------------------------------------------------= ------------------------------------------------------ > Aggregate (cost=3D18200480.80..18200480.81 rows=3D1 width=3D8) > -> Hash Join (cost=3D103206.82..18190602.43 rows=3D3951347 width=3D0) > Hash Cond: (x.granuleid =3D g.granuleid) > -> Seq Scan on table2 x (cost=3D0.00..10596253.01 rows=3D64424= 1901 width=3D8) > -> Hash (cost=3D92363.72..92363.72 rows=3D660888 width=3D8) > -> Index Only Scan using idx_table1 on table1 g (cost=3D= 0.57..92363.72 rows=3D660888 width=3D8) > Index Cond: (collectionid =3D '22467'::bigint) > (7 rows) > My question is, what gets put into the Hash? > I assume the with "width=3D8" must refer to the size of the key. It's the data payload width, but there's some per-row overhead too, which is more than 8 bytes ... don't recall how much more at the moment. > The reason I ask is because, when I try to run the query it fails due to > temp file use over 10GB. What have you got work_mem set to? If the hashed table exceeds that, you're going to end up with a multi-batch join, in which case most of the outer table is going to get written into temp files as well. I don't think it's a good idea to have such a small temp_file_limit when you're working with such huge tables. Either a merge or hash join is likely to require temp file space similar to the table size, and you do *not* want a nestloop join, at least not if you want your answers in reasonable time. regards, tom lane --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin