Search Postgresql Archives

Forcing index usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks —

We’ve got several tables that are relatively large (~250-500GB in total size) that use very large (tens to hundreds of GB) GIN indexes for full-text search. We’ve set the column statistics for our tsvector columns as high as they go (10,000). We almost always order our search results by a separate date column (which has an index) and we almost always use a limit.

Whenever the query planner chooses to use the indexes, queries on these tables are somewhat fast, maxing out at a few hundred milliseconds per query (which is terrible, but acceptable to end users).

When the query planner chooses not to use the indexes, queries can take many tens of seconds if they ever finish at all. When this happens, the query planner usually chooses to use the date index instead of the GIN index, and that is almost always a bad idea. We have sometimes been able to trick it into a better query plan by also adding the tsvector column in the ORDER BY clause, but that has bad performance implications if the result set is large.

Is there a way to tell Postgres “please don’t use index X when queries that could use index Y instead occur?”

Thank you!





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux