pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: Dror Matalon <dror@zapatec.com>
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: Various performance questions
Date: 26 Oct 2003 22:49:29 -0500
Message-ID: <87u15vxrue.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <20031026194449.GD2979@rlx11.zapatec.com>
References: <20031026194449.GD2979@rlx11.zapatec.com>

Dror Matalon <dror@zapatec.com> writes:

> explain analyze select count(*) from items where channel < 5000;
>                                                         QUERY PLAN
> --------------------------------------------------------------------------------------------------------------------------
>  Aggregate  (cost=249141.54..249141.54 rows=1 width=0) (actual time=26224.603..26224.608 rows=1 loops=1)
>    ->  Seq Scan on items  (cost=0.00..245377.52 rows=1505605 width=0) (actual time=7.599..17686.869 rows=1632057 loops=1)
>          Filter: (channel < 5000)
>  Total runtime: 26224.703 ms
> 
> 
> How can it do a sequential scan and apply a filter to it in less time
> than the full sequential scan? Is it actually using an index without
> really telling me? 

It's not using the index and not telling you. 

It's possible the count(*) operator itself is taking some time. Postgres
doesn't have to call it on the rows that don't match the where clause. How
long does "explain analyze select 1 from items" with and without the where
clause take?

What version of postgres is this?. In 7.4 (and maybe 7.3?) count() uses an
int8 to store its count so it's not limited to 4 billion records.
Unfortunately int8 is somewhat inefficient as it has to be dynamically
allocated repeatedly. It's possible it's making a noticeable difference,
especially with all the pages in cache, though I'm a bit surprised. There's
some thought about optimizing this in 7.5.

-- 
greg




view thread (23+ messages)  latest in thread

Message-ID: <87u15vxrue.fsf@stark.dyndns.tv>
Permalink:  ../87u15vxrue.fsf@stark.dyndns.tv/
Also on:    postgresql.org/message-id/87u15vxrue.fsf@stark.dyndns.tv

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: gsstark@mit.edu, dror@zapatec.com
  Subject: Re: Various performance questions
  In-Reply-To: <87u15vxrue.fsf@stark.dyndns.tv>

* 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