Re: cache table

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: cache table
Дата
Msg-id 87wu3sxdoo.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: cache table  (Joseph Shraibman <jks@selectacast.net>)
Список pgsql-performance
Joseph Shraibman <jks@selectacast.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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: Bug in optimizer
Следующее
От: Litao Wu
Дата:
Сообщение: pg_stat