PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Indice di testo completo corretto Rails/PostgreSQL/pg_search

Questa espressione:

to_tsvector('simple', (COALESCE(title::TEXT), ''))

non è sargable contro il tuo indice.

Dovresti dichiarare l'indice esattamente sull'espressione utilizzata nella query:

CREATE INDEX products_gin_title
ON products
USING GIN(to_tsvector('simple', COALESCE(title::TEXT,'')))

(oppure fai in modo che ruby ​​generi l'espressione usata nell'indice).

Se vuoi indicizzare più colonne, basta concatenarle:

CREATE INDEX products_gin_title
ON products
USING GIN(to_tsvector('simple', title || ' ' || product_type || ' ' || platform_id))

ma ancora, Ruby dovrebbe filtrare esattamente sulla stessa espressione affinché l'indice sia utile.