pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Treat <xzilla@users.sourceforge.net>
To: Paul McKay <paul_mckay@clearwater-it.co.uk>
Cc: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Slow query performance on large table
Date: 04 Mar 2003 12:02:29 -0500
Message-ID: <1046797349.16957.20.camel@camel> (raw)
In-Reply-To: <000001c2e268$b1e47210$0c64a8c0@paulspc>
References: <000001c2e268$b1e47210$0c64a8c0@paulspc>

On Tue, 2003-03-04 at 11:11, Paul McKay wrote:
> The results were
> 
> clearview=# explain analyse
> clearview-# select assessment,time
> clearview-# from measurement
> clearview-# where assessment = 53661
> clearview-# and time between 1046184261 and 1046335461;
> 
> NOTICE:  QUERY PLAN:
> 
> Index Scan using idx_measurement_assessment on measurement
> (cost=0.00..34668.61 rows=261 width=8) (actual time=26128.07..220584.69
> rows=503 loops=1)
> Total runtime: 220587.06 msec
> 
> EXPLAIN
> 
> After adding the index kindly suggested by yourself and Tomasz I get,
> 
> clearview=# explain analyse
> clearview-# select assessment,time
> clearview-# from measurement
> clearview-# where assessment = 53661
> clearview-# and time between 1046184261 and 1046335461;
> NOTICE:  QUERY PLAN:
> 
> Index Scan using ind_measurement_ass_time on measurement
> (cost=0.00..1026.92 rows=261 width=8) (actual time=15.37..350.46
> rows=503 loops=1)
> Total runtime: 350.82 msec
> 
> EXPLAIN
> 
> 
> I vaguely recall doing a bit of a reorganize on this database a bit back
> and it looks like I lost the primary Key index. No wonder it was going
> slow.
> 

Maybe it's just me, but I get the feeling you need to work some regular
reindexing into your maintenance schedule. Given your query is using
between, I don't think it would use the index on the time field anyway
(and explain analyze seems to be supporting this). Rewrite it so that
you have a and time > foo and time < bar and I think you'll see a
difference. With that in mind, I think your speedier query results are 
due more to having a non-bloated index freshly created than the fact
that it being a dual column index.

Robert Treat 






view thread (18+ messages)  latest in thread

Message-ID: <1046797349.16957.20.camel@camel>
Permalink:  ../1046797349.16957.20.camel@camel/
Also on:    postgresql.org/message-id/1046797349.16957.20.camel@camel

 · 

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: xzilla@users.sourceforge.net, paul_mckay@clearwater-it.co.uk, tgl@sss.pgh.pa.us
  Subject: Re: Slow query performance on large table
  In-Reply-To: <1046797349.16957.20.camel@camel>
  References: <000001c2e268$b1e47210$0c64a8c0@paulspc> <1046797349.16957.20.camel@camel>

* 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