Имя: Пароль:
IT
Админ
Postgresql индекс gin работает через раз.
0 GANR
 
04.12.24
12:25
Есть индекс

CREATE INDEX IF NOT EXISTS idx_ui_timeline_gin_userfiotimestamp
ON timeline USING gin(
    ltrim(userfio) gin_trgm_ops,
    ltrim(entityname) gin_trgm_ops,
    entityname gin_trgm_ops,
    timestamp
);

статистика пересчитана

alter index idx_ui_timeline_gin_userfiotimestamp alter column 1 set statistics 1000;
alter index idx_ui_timeline_gin_userfiotimestamp alter column 2 set statistics 1000;

analyze timeline;

Есть запрос

SELECT
    timeline1.id
FROM
    timeline timeline1
WHERE
    ltrim(timeline1.userfio) ilike '%uploader'

Seq Scan on timeline as timeline1 (rows=8914724 loops=1)
Filter: (ltrim((userfio)::text) ~~* '%uploader'::text)
Rows Removed by Filter: 13910413

индекс не срабатывает

Правлю where
SELECT
    timeline1.id
FROM
    timeline timeline1
WHERE
    ltrim(timeline1.userfio) ilike '%uploader1'

индекс срабатывает

Bitmap Heap Scan on timeline as timeline1 (rows=0 loops=1)
Recheck Cond: (ltrim((userfio)::text) ~~* '%uploader1 '::text)
Heap Blocks: exact=1451696
0    1
2.     Bitmap Index Scan using idx_ui_timeline_gin_userfiotimestamp (rows=8918662 loops=1)
Index Cond: (ltrim((userfio)::text) ~~* '%uploader1'::text)

Как добиться стабильно быстрой работы запроса?