Re: I/O on select count(*)

From: Doug Eck <deck1(at)yahoo(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: I/O on select count(*)
Date: 2008-05-14 21:23:49
Message-ID: 811584.85729.qm@web44806.mail.sp1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

----- Original Message ----
From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Doug Eck <deck1(at)yahoo(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Sent: Wednesday, May 14, 2008 3:38:23 PM
Subject: Re: [PERFORM] I/O on select count(*)

On Wed, May 14, 2008 at 4:09 PM, Doug Eck <deck1(at)yahoo(dot)com> wrote:
> I have a large table (~ 2B rows) that contains an indexed timestamp column.
> I am attempting to run a query to determine the number of rows for a given
> day using something like "select count(*) from tbl1 where ts between
> '2008-05-12 00:00:00.000' and '2008-05-12 23:59:59.999'". Explain tells me
> that the query will be done using an index scan (as I would expect), and I
> realize that it is going to take a while. My question concerns some unusual
> I/O activity on the box (SUSE) when I run the query.
>
> For the first couple of minutes I see reads only. After that vmstat shows
> mixed reads and writes in a ratio of about 1 block read to 5 blocks
> written. We have determined that files in our data and log partitions are
> being hit, but the file system itself is not growing during this time (it
> appears to be writing over the same chunk of space over and over again).
> Memory on the box is not being swapped while all of this is happening. I
> would have guessed that a "select count(*)" would not require a bunch of
> writes, and I can't begin to figure out why the number of blocks written are
> so much higher than the blocks read. If I modify the where clause to only
> count the rows for a given minute or two, I see the reads but I never see
> the unusual write behavior.
>
> Any thoughts into what could be going on? Thanks in advance for your help.

can you post the exact output of explain analyze? (or, at least,
explain if the query takes too long)

merlin

The query takes a long time to run, so I'll start with the explain output. I
can run explain analyze (given enough time) if you believe its output
could hold some clues.

db_2008=> explain select count(*) from ot_2008_05 where
transact_time between '2008-05-12 00:00:00.000' and '2008-05-12
23:59:59.999';
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=10368613.47..10368613.48 rows=1 width=0)
-> Index Scan using ot_2008_05_ak2 on ot_2008_05 (cost=0.00..10011333.27 rows=142912078 width=0)
Index Cond: ((transact_time >= '2008-05-12
00:00:00-04'::timestamp with time zone) AND (transact_time <=
'2008-05-12 23:59:59.999-04'::timestamp with time zone))
(3 rows)

db_2008=>

Doug

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2008-05-14 22:11:21 Re: I/O on select count(*)
Previous Message Merlin Moncure 2008-05-14 20:38:23 Re: I/O on select count(*)