Re: Using index name in select Query

From: Luca Ferrari <fluca1978(at)infinito(dot)it>
To: "naman(dot)iitb" <naman(dot)bbps(at)gmail(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Using index name in select Query
Date: 2013-10-21 16:05:22
Message-ID: CAKoxK+6DD82qYGoc8UsbJ-S-=bsNSj7rMqAg305vjc1sGO65+g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sat, Oct 19, 2013 at 4:28 PM, naman.iitb <naman(dot)bbps(at)gmail(dot)com> wrote:

> Now my requirement is if i know the index name i.e. index_abcd then is there
> a way by which i can use it in the select query so that i can be sure that
> optimizer will pick the index specified(i.e index_abcd) and no other.
>

What you want is called "query hints" and PostgreSQL, as pointed out
by others, do not support it by policy. The idea is that the planner
knows better than you what to do with your query. What you believe is
the better index today could be the bad index tomorrow, or even a few
seconds after you just told your boss how smart you have been
designing such index, and that is strictly tied to the workload of
your cluster.
The only way to force PostgreSQL using your own index is to disable
all other access methods (e.g., enabled_seqscan = off) and to make all
other indexes not available (via catalogs). But this will impact all
your cluster.

Any chance this is an homework?

Luca

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message James David Smith 2013-10-25 10:08:39 COUNT and GROUP BY performing strangely
Previous Message David Johnston 2013-10-19 16:36:38 Re: Using index name in select Query