Re: Why does a simple query not use an obvious index?
В списке pgsql-performance по дате отправления:
| От | Pierre-Frédéric Caillaud |
|---|---|
| Тема | Re: Why does a simple query not use an obvious index? |
| Дата | |
| Msg-id | opsdj8ke1rcq72hf@musicbox обсуждение исходный текст |
| Ответ на | Re: Why does a simple query not use an obvious index? (Tom Lane <tgl@sss.pgh.pa.us>) |
| Список | pgsql-performance |
Another primary key trick :
If you insert records with a serial primary key, and rarely delete them
or update the timestamp, you can use the primary key to compute an
approximate number of rows.
a := SELECT pkey FROM table WHERE timestamp() > threshold ORDER BY
timestamp ASC LIMIT 1;
b := SELECT pkey FROM table WHERE ORDER BY pkey DESC LIMIT 1;
(b-a) is an approximate count.
Performance is great because you only fetch two rows. Index scan is
guaranteed (LIMIT 1). On the downside, you get an approximation, and this
only works for tables where timestamp is a date of INSERT, timestamp
worrelated wiht pkey) not when timestamp is a date of UPDATE (uncorrelated
with pkey).
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера