E
E
eldar_web2019-05-23 15:21:10
PostgreSQL
eldar_web, 2019-05-23 15:21:10

Why is GIN index not used in Postgresql with weight setting?

Why with GIN index (with weight setting):

CREATE INDEX search_idx ON price_items USING GIN (setweight(to_tsvector('russian', make_name), 'A'), setweight(to_tsvector('russian', detail_name), 'B'));

When requested:
SELECT * FROM price_items 
WHERE setweight(to_tsvector('russian', make_name), 'A') || setweight(to_tsvector('russian', detail_name), 'B') @@ plainto_tsquery('russian', 'отличное слово')
ORDER BY ts_rank(setweight(to_tsvector('russian', make_name), 'A') || setweight(to_tsvector('russian', detail_name), 'B'), plainto_tsquery('russian', 'отличное слово')) DESC;

Index not applied? What could be? How to decide?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-05-23
@eldar_web

index (func1, func2) is fundamentally different from func1 || func2
The expressions for the operator are different, so the index is discarded as invalid.
In general, an expression filter can only work on an index built exactly on the same expression.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question