Re: []performance issues

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: []performance issues
Дата
Msg-id GNELIHDDFBOCMGBFGEFOIEHOCDAA.chriskl@familyhealth.com.au
обсуждение исходный текст
Ответ на []performance issues  (Yaroslav Dmitriev <yar@warlock.ru>)
Список pgsql-hackers
> Here we have  table "stats" with  something over one millon records.
> Obvious "SELECT COUNT(*) FROM stats " takes over 40 seconds to execute,
> and this amount of time does not shorten considerably in subsequent
> similar requests. All the databases are vacuumed nightly.

Doing a row count requires a sequential scan in Postgres.

Try creating another summary table that just has one row and one column and
is an integer.

Then, create a trigger on your stats table that fires whenever a new row is
added or deleted and updates the tally of rows in the summary table.

Then, just select from the summary table to get an instantaneous count.  Of
course, insert and deletes will be marginally slowed down.

Refer to the docs for CREATE TRIGGER, CREATE FUNCTION and PL/PGSQL for more
info on how to do this.

Regards,

Chris



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

Предыдущее
От: Yaroslav Dmitriev
Дата:
Сообщение: []performance issues
Следующее
От: Hannu Krosing
Дата:
Сообщение: Re: Open 7.3 items