Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B5EB564FCF9 for ; Thu, 18 Sep 2008 15:30:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 83576-09 for ; Thu, 18 Sep 2008 15:30:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f17.google.com (mail-gx0-f17.google.com [209.85.217.17]) by postgresql.org (Postfix) with ESMTP id 45B0A64FCCF for ; Thu, 18 Sep 2008 15:30:24 -0300 (ADT) Received: by gxk10 with SMTP id 10so29461020gxk.19 for ; Thu, 18 Sep 2008 11:30:23 -0700 (PDT) Received: by 10.142.213.10 with SMTP id l10mr954206wfg.221.1221762623218; Thu, 18 Sep 2008 11:30:23 -0700 (PDT) Received: by 10.143.39.19 with HTTP; Thu, 18 Sep 2008 11:30:23 -0700 (PDT) Message-ID: Date: Thu, 18 Sep 2008 11:30:23 -0700 From: "Scott Carey" To: "Nikolas Everett" Subject: Re: Why does this query write to the disk? Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_39854_1110312.1221762623223" References: X-Google-Sender-Auth: 3a3722c1dc47e468 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200809/182 X-Sequence-Number: 31495 ------=_Part_39854_1110312.1221762623223 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline How big is your work_mem setting, and is this behavior affected by its size? You can increase the work_mem on an individual connection before the test. Simply: set work_mem = '100MB' to set it to 100 Megabytes. If your issue is spilling data out of work_mem to the temp storage, this setting will affect that. On Thu, Sep 18, 2008 at 10:30 AM, Nikolas Everett wrote: > List, > > I'm a bit confused as to why this query writes to the disk: > SELECT count(*) > FROM bigbigtable > WHERE customerid IN (SELECT customerid FROM > smallcustomertable) > AND x != > 'special' > > AND y IS NULL > > It writes a whole bunch of data to the disk that has the tablespace where > bigbigtable lives as well as writes a little data to the main disk. It > looks like its is actually WAL logging these writes. > > Here is the EXPLAIN ANALYZE: > Aggregate (cost=46520194.16..46520194.17 rows=1 width=0) (actual > time=4892191.995..4892191.995 rows=1 loops=1) > -> Hash IN Join (cost=58.56..46203644.01 rows=126620058 width=0) > (actual time=2.938..4840349.573 rows=79815986 loops=1) > Hash Cond: ((bigbigtable.customerid)::text = > (smallcustomertable.customerid)::text) > -> Seq Scan on bigbigtable (cost=0.00..43987129.60 rows=126688839 > width=11) (actual time=0.011..4681248.143 rows=128087340 loops=1) > Filter: ((y IS NULL) AND ((x)::text <> 'special'::text)) > -> Hash (cost=35.47..35.47 rows=1847 width=18) (actual > time=2.912..2.912 rows=1847 loops=1) > -> Seq Scan on smallcustomertable (cost=0.00..35.47 > rows=1847 width=18) (actual time=0.006..1.301 rows=1847 loops=1) > Total runtime: 4892192.086 ms > > Can someone point me to some documentation as to why this writes to disk? > > Thanks, > Nik > ------=_Part_39854_1110312.1221762623223 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
How big is your work_mem setting, and is this behavior affected by its size?

You can increase the work_mem on an individual connection before the test.

Simply:

set work_mem = '100MB'

to set it to 100 Megabytes.  If your issue is spilling data out of work_mem to the temp storage, this setting will affect that.

On Thu, Sep 18, 2008 at 10:30 AM, Nikolas Everett <nik9000@gmail.com> wrote:
List,

I'm a bit confused as to why this query writes to the disk:
SELECT count(*)
FROM    bigbigtable
WHERE customerid IN (SELECT customerid FROM smallcustomertable)                                                        
AND x != 'special'                                                                               
AND y IS NULL 

It writes a whole bunch of data to the disk that has the tablespace where bigbigtable lives as well as writes a little data to the main disk.  It looks like its is actually WAL logging these writes.

Here is the EXPLAIN ANALYZE:
Aggregate  (cost=46520194.16..46520194.17 rows=1 width=0) (actual time=4892191.995..4892191.995 rows=1 loops=1)
  ->  Hash IN Join  (cost=58.56..46203644.01 rows=126620058 width=0) (actual time=2.938..4840349.573 rows=79815986 loops=1)
        Hash Cond: ((bigbigtable.customerid)::text = (smallcustomertable.customerid)::text)
        ->  Seq Scan on bigbigtable  (cost=0.00..43987129.60 rows=126688839 width=11) (actual time=0.011..4681248.143 rows=128087340 loops=1)
              Filter: ((y IS NULL) AND ((x)::text <> 'special'::text))
        ->  Hash  (cost=35.47..35.47 rows=1847 width=18) (actual time=2.912..2.912 rows=1847 loops=1)
              ->  Seq Scan on smallcustomertable  (cost=0.00..35.47 rows=1847 width=18) (actual time=0.006..1.301 rows=1847 loops=1)
Total runtime: 4892192.086 ms

Can someone point me to some documentation as to why this writes to disk?

Thanks,
Nik

------=_Part_39854_1110312.1221762623223--