pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jonathan Marks <jonathanaverymarks@gmail.com>
To: pgsql-general@postgresql.org
Subject: Forcing index usage
Date: Wed, 3 Apr 2019 12:13:22 -0400
Message-ID: <679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com> (raw)

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!




view thread (13+ messages)  latest in thread

Message-ID: <679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com>
Permalink:  ../679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com/
Also on:    postgresql.org/message-id/679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-general@postgresql.org
  Cc: jonathanaverymarks@gmail.com
  Subject: Re: Forcing index usage
  In-Reply-To: <679378F9-E085-4FE3-BC78-3073A4B86438@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox