Re: best index for timestamp field null and not null queries
В списке pgsql-novice по дате отправления:
| От | Gavin Flower |
|---|---|
| Тема | Re: best index for timestamp field null and not null queries |
| Дата | |
| Msg-id | 5039EDE1.4050903@archidevsys.co.nz обсуждение исходный текст |
| Ответ на | best index for timestamp field null and not null queries (Jeremy Wells <jemmyw@gmail.com>) |
| Список | pgsql-novice |
Hi, I've got a database table with a datetime column "deleted_at". I'll be running lots of queries against the table but they'll all be of the nature "deleted_at IS NULL" and "deleted_at IS NOT NULL".What's the best index to place on this column? I assume if I add just a straight index then it'll index all of the values that go into it.
Not tested! How about the following partial index? CREATE INDEX deleted_at_is_null ON my_table WHERE deleted_at IS NULL; SELECT count(*) FROM my_table WHERE deleted_at IS NULL; The index should be substantially smaller than one storing dates, as the field will be small and you will have fewer rows. If the NULL value is the most common, then use the predicate deleted_at IS NOT NULL (and change the index name accordingly!). Cheers, Gavin
В списке pgsql-novice по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера