Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X2LFu-0001ww-Nd for pgsql-performance@arkaria.postgresql.org; Wed, 02 Jul 2014 14:11:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X2LFu-0007tx-87 for pgsql-performance@arkaria.postgresql.org; Wed, 02 Jul 2014 14:11:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X2LFt-0007tp-Hi for pgsql-performance@postgresql.org; Wed, 02 Jul 2014 14:11:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X2LFq-0006NM-Fa for pgsql-performance@postgresql.org; Wed, 02 Jul 2014 14:11:24 +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 s62EBJ9F001559; Wed, 2 Jul 2014 10:11:19 -0400 From: Tom Lane To: Dave Roberge cc: pgsql-performance@postgresql.org Subject: Re: Hash Join node sometimes slow In-reply-to: References: Comments: In-reply-to Dave Roberge message dated "Wed, 02 Jul 2014 13:01:47 -0000" Date: Wed, 02 Jul 2014 10:11:19 -0400 Message-ID: <1558.1404310279@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Dave Roberge writes: > For example, running explain (analyze, buffers) with the query, 4/5 times we > will see the following: > -> Hash Join (cost=16385.76..103974.09 rows=523954 width=64) (actual > time=532.634..4018.678 rows=258648 loops=1) > Hash Cond: (p.a = c.c) > Buffers: shared hit=4 read=29147, temp read=12943 written=12923 > -> Seq Scan on p (cost=0.00..38496.88 rows=1503188 width=60) (actual > time=0.013..1388.205 rows=1503188 loops=1) > Buffers: shared hit=1 read=23464 > -> Hash (cost=15382.47..15382.47 rows=57703 width=12) (actual > time=527.237..527.237 rows=57789 loops=1) > Buckets: 4096 Batches: 4 Memory Usage: 632kB > Buffers: shared hit=3 read=5683, temp read=617 written=771 > The other times, we will see something like this: > -> Hash Join (cost=16385.76..103974.09 rows=523954 width=64) (actual > time=587.277..15208.621 rows=258648 loops=1) > Hash Cond: (p.a = c.c) > Buffers: shared hit=26 read=29125, temp read=12943 written=12923 > -> Seq Scan on p (cost=0.00..38496.88 rows=1503188 width=60) (actual > time=0.013..1525.608 rows=1503188 loops=1) > Buffers: shared hit=22 read=23443 > -> Hash (cost=15382.47..15382.47 rows=57703 width=12) (actual > time=581.638..581.638 rows=57789 loops=1) > Buckets: 4096 Batches: 4 Memory Usage: 632kB > Buffers: shared hit=4 read=5682, temp read=617 written=771 > Does anyone have ideas on what might be causing the difference in timing for > the hash join node? I'd bet on the extra time being in I/O for the per-batch temp files, since it's hard to see what else would be different if the data were identical in each run. Maybe the kernel is under memory pressure and is dropping the file data from in-memory disk cache. Or maybe it's going to disk all the time but the slow runs face more I/O congestion. Personally, for a problem of this size I'd increase work_mem enough so you don't get multiple batches in the first place. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance