Re: Forcing index usage

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Jonathan Marks <jonathanaverymarks(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Forcing index usage
Date: 2019-04-24 22:03:02
Message-ID: CAMkU=1z5aDi6ujzDFWk4DhUdz6BJD9pKMkUFh+i24q+wkTnqCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 3, 2019 at 12:13 PM Jonathan Marks <jonathanaverymarks(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message pabloa98 2019-04-24 22:11:04 Re: how to add more than 1600 columns in a table?
Previous Message Joe Conway 2019-04-24 20:47:16 Re: how to add more than 1600 columns in a table?