Re: Forcing index usage

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Jonathan Marks <jonathanaverymarks(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Forcing index usage
Date: 2019-04-03 17:00:55
Message-ID: CAHOFxGrN659igBLGUh+DMvsrRiqBkO+Lr9sv1HSA81Y+YSmZCQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

No. But you could re-write the query to make the date index useless. The
simplest way that comes to mind is putting the query that does your
full-text search in a CTE (WITH keyword, it is an optimization boundary)
and then ordering and applying your limit to the materialized set that
comes out of that. eg.

WITH cte_full_text_results AS(
SELECT date, result FROM big_a_table WHERE text = 'whatever'
)
SELECT * FROM cte_full_text_results ORDER BY date DESC limit 10;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Perumal Raj 2019-04-03 17:02:00 Re: Recommendation to run vacuum FULL in parallel
Previous Message Tom Lane 2019-04-03 16:43:25 Re: PostgreSQL Windows 2019 support ?