Re: Forcing index usage - Mailing list pgsql-general

From Jeff Janes
Subject Re: Forcing index usage
Date
Msg-id CAMkU=1z5aDi6ujzDFWk4DhUdz6BJD9pKMkUFh+i24q+wkTnqCw@mail.gmail.com
Whole thread Raw
In response to Forcing index usage  (Jonathan Marks <jonathanaverymarks@gmail.com>)
List pgsql-general
On Wed, Apr 3, 2019 at 12:13 PM Jonathan Marks <jonathanaverymarks@gmail.com> wrote:

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

Late to the party here, but...

Not directly.  I've had luck in changing the procost of functions (or the functions which back the operators) which are frequently executed in the slower plan, but not frequently executed in the faster plan.  For example, walking the time index executing @@ on each row until it finds enough is probably going to involve a lot more @@ than using the full text index and invoking @@ only on the recheck rows.  The cost of @@ (via "ts_match_vq") is probably way too low, especially if it has to fish an argument out of TOAST.

If that doesn't work, you can just change the query to prevent the bad index from being used.

For example, PostgreSQL is not currently smart enough to use an index on "mtime" to support the ordering of a query that is written as:

ORDER BY mtime + interval '0 seconds'

Cheers,

Jeff

pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: how to add more than 1600 columns in a table?
Next
From: pabloa98
Date:
Subject: Re: how to add more than 1600 columns in a table?