CREATE INDEX
is strongly recommended.
Please see index tuning for details.search_idx
over multiple columns of the mock_items
table.
All columns that are relevant to the search query, including columns used for sorting and filtering, should be indexed for optimal performance.
CURRENT SCHEMA
is used.key_field
. Text, numeric, datetime, boolean, range, enum, and JSON types can be indexed.key_field
must have a UNIQUE
constraint. A non-unique key field is likely to lead to undefined behavior
or incorrect search results.
While the key field can be any unique text, numeric, or datetime value, an integer key field will be the most
performant. The Postgres SERIAL
type is an easy way to create a unique integer column.
Finally, the key field must be the first column in the target list.
@@@
operator must be used
in order for filtering to be optimized by the index.CREATE INDEX
to construct a partial index. Partial
indexes are useful for reducing index size on disk and improving update speeds over non-indexed rows.
_pg_search_{i}
where {i}
is the 0-based ordinal position
of the expression in the index definition. In the example above, the lowercase version
of the description
field will be referred to as _pg_search_2
.
CONCURRENTLY
keyword:
pg_search
can only use a single BM25 index per table - the most recently created one will automatically be used for queries. After creating a new index concurrently and verifying it works as expected, you can safely drop the old index: