pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joseph Shraibman <jks@selectacast.net>
To: pgsql-performance@postgresql.org
Subject: cache table
Date: Mon, 03 May 2004 22:24:02 -0400
Message-ID: <c76urn$438$1@news.hub.org> (raw)

I have a big table with some int fields.  I frequently need to do 
queries like:

SELECT if2, count(*) FROM table WHERE if1 = 20 GROUP BY if2;

The problem is that this is slow and frequently requires a seqscan. I'd 
like to cache the results in a second table and update the counts with 
triggers, but this would a) require another UPDATE for each 
INSERT/UPDATE which would slow down adding and updating of data and b) 
produce a large amount of dead rows for vacuum to clear out.

It would also be nice if this small table could be locked into the pg 
cache somehow.  It doesn't need to store the data on disk because the 
counts can be generated from scratch?

So what is the best solution to this problem?  I'm sure it must come up 
pretty often.



view thread (4+ messages)  latest in thread

Message-ID: <c76urn$438$1@news.hub.org>
Permalink:  ../c76urn$438$1@news.hub.org/
Also on:    postgresql.org/message-id/c76urn$438$1@news.hub.org

 · 

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: jks@selectacast.net
  Subject: Re: cache table
  In-Reply-To: <c76urn$438$1@news.hub.org>

* 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