Forcing index usage - Mailing list pgsql-general

From Jonathan Marks
Subject Forcing index usage
Date
Msg-id 679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com
Whole thread Raw
Responses Re: Forcing index usage  (Michael Lewis <mlewis@entrata.com>)
Re: Forcing index usage  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-general
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
usea limit. 

Whenever the query planner chooses to use the indexes, queries on these tables are somewhat fast, maxing out at a few
hundredmilliseconds 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
almostalways a bad idea. We have sometimes been able to trick it into a better query plan by also adding the tsvector
columnin 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!


pgsql-general by date:

Previous
From: Lou Tseng
Date:
Subject: Lingering replication slots
Next
From: david moloney
Date:
Subject: PostgreSQL Windows 2019 support ?