Postgres Indexing? Postgres Indexing? postgresql postgresql

Postgres Indexing?


Assuming you're doing exact matches, you should just be able to create the index and leave it:

CREATE INDEX host_index ON table_name (host)

The query optimizer should just use that automatically.

You may wish to specify other options such as the collation to use.

See the PostgreSQL docs for CREATE INDEX for more information.


I'd suggest using BRIN Index since its introduction from PostgreSQL 9.5 rather than the conventional btree index.


For text search, it is recommended that you use GIN or GiST index types.

https://www.postgresql.org/docs/9.5/static/textsearch-indexes.html

Another possibility is that if you were only performing exact matching in the host column, i.e., no inequality comparisons (>, <) and partial matching (like, wildcard) involved, you may consider converting host to a hash integer to speed up the search significantly.