pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Carey <scott@richrelevance.com>
To: Nikolas Everett <nik9000@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Why does this query write to the disk?
Date: Thu, 18 Sep 2008 11:30:23 -0700
Message-ID: <a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com> (raw)
In-Reply-To: <d4e11e980809181030t3f09db94vd5b69d7868271906@mail.gmail.com>
References: <d4e11e980809181030t3f09db94vd5b69d7868271906@mail.gmail.com>

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
>

view thread (7+ messages)  latest in thread

Message-ID: <a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com>
Permalink:  ../a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com/
Also on:    postgresql.org/message-id/a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: scott@richrelevance.com, nik9000@gmail.com
  Subject: Re: Why does this query write to the disk?
  In-Reply-To: <a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com>
  References: <d4e11e980809181030t3f09db94vd5b69d7868271906@mail.gmail.com> <a1ec7d000809181130y45153205k3c6388608d186e76@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox