From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | Joseph Shraibman <jks(at)selectacast(dot)net> |
Cc: | "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: cache table |
Date: | 2004-05-04 18:14:15 |
Message-ID: | 87wu3sxdoo.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Joseph Shraibman <jks(at)selectacast(dot)net> writes:
> scott.marlowe wrote:
>
> > I think you might be interested in materialized views. You could create this
> > as a materialized view which should be very fast to just select * from.
>
> That seems to be the count table I envisioned. It just hides the details for
> me. It still has the problems of an extra UPDATE every time the data table is
> updated and generating a lot of dead tuples.
The dead tuples is only going to be a problem if you have lots of updates. If
that's the case then you're also going to have problems with contention. This
trigger will essentially serialize all inserts, deletes, updates at least
within a group. If you use transactions with multiple such updates then you
will also risk creating deadlocks.
But I think these problems are fundamental to the problem you've described.
Keeping denormalized aggregate data like this inherently creates contention on
the data and generates lots of old data. It's only really useful when you have
few updates and many many reads.
If you know more about the behaviour of the updates then there might be other
options. Like, do you need precise data or only approximate data? If
approximate perhaps you could just do a periodic refresh of the denormalized
view and use that.
Are all the updates to the data you'll be querying coming from within the same
application context? In which case you can keep a cache locally in the
application and update it locally. I often do this when I have rarely updated
or insert-only data, I just do a lazy cache using a perl hash or equivalent.
If you're really happy with losing the cache, and you don't need complex
transactions or care about serializing updates then you could use something
like memcached (http://www.danga.com/memcached/) That might be your best fit
for how you describe your requirements.
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Litao Wu | 2004-05-04 18:44:16 | pg_stat |
Previous Message | Bruno Wolff III | 2004-05-04 16:36:19 | Re: Bug in optimizer |