Обсуждение: Not Picking Index

Поиск
Список
Период
Сортировка

Not Picking Index

От
"Gauri Kanekar"
Дата:

Hi List,
 
I want to run a Select Query on a table. But i dont want the query to pick a index defined on that table.
 
So can i instruct the planner not to pick that index.
 
--
Regards
Gauri

Re: Not Picking Index

От
Michael Fuhr
Дата:
On Fri, Feb 16, 2007 at 06:26:51PM +0530, Gauri Kanekar wrote:
> I want to run a Select Query on a table. But i dont want the query to pick a
> index defined on that table.
>
> So can i instruct the planner not to pick that index.

Why don't you want the planner to use the index?  Is there a specific
index you want to ignore or do you want the planner to ignore all
indexes?  What problem are you trying to solve?

--
Michael Fuhr

Re: Not Picking Index

От
"Gauri Kanekar"
Дата:

I want the planner to ignore a specific index.
I am testing some query output. For that purpose i dont want the index.
I that possible to ignore a index by the planner.
 
On 2/16/07, Michael Fuhr <mike@fuhr.org> wrote:
On Fri, Feb 16, 2007 at 06:26:51PM +0530, Gauri Kanekar wrote:
> I want to run a Select Query on a table. But i dont want the query to pick a
> index defined on that table.
>
> So can i instruct the planner not to pick that index.

Why don't you want the planner to use the index?  Is there a specific
index you want to ignore or do you want the planner to ignore all
indexes?  What problem are you trying to solve?

--
Michael Fuhr



--
Regards
Gauri

Re: Not Picking Index

От
Alvaro Herrera
Дата:
Gauri Kanekar escribió:
> I want the planner to ignore a specific index.
> I am testing some query output. For that purpose i dont want the index.
> I that possible to ignore a index by the planner.

Sure:

BEGIN
DROP INDEX foo
SELECT ....
ROLLBACK

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: Not Picking Index

От
Tom Lane
Дата:
"Gauri Kanekar" <meetgaurikanekar@gmail.com> writes:
> I want the planner to ignore a specific index.
> I am testing some query output. For that purpose i dont want the index.
> I that possible to ignore a index by the planner.

    begin;
    drop index soandso;
    explain analyze ...;
    rollback;

Note the DROP INDEX will acquire exclusive lock on the table, so this
might not be the greatest thing to do in a production environment.
In PG 8.2 and up there is a sneakier way to do it that won't acquire
any more lock than the statement-under-test does:

    begin;
    update pg_index set indisvalid = false
      where indexrelid = 'soandso'::regclass;
    explain analyze ...;
    rollback;

            regards, tom lane

Re: Not Picking Index

От
Brad Nicholson
Дата:
On Fri, 2007-02-16 at 20:01 +0530, Gauri Kanekar wrote:
>
> I want the planner to ignore a specific index.
> I am testing some query output. For that purpose i dont want the
> index.
> I that possible to ignore a index by the planner.

If the indexed field is an intger, add 0 to it.


--
Brad Nicholson  416-673-4106
Database Administrator, Afilias Canada Corp.


Re: Not Picking Index

От
"Steinar H. Gunderson"
Дата:
On Fri, Feb 16, 2007 at 01:27:46PM -0500, Brad Nicholson wrote:
> If the indexed field is an intger, add 0 to it.

Won't that also invalidate the statistics?

/* Steinar */
--
Homepage: http://www.sesse.net/

Re: Not Picking Index

От
"George Pavlov"
Дата:
> Note the DROP INDEX will acquire exclusive lock on the table, so this
> might not be the greatest thing to do in a production environment.
> In PG 8.2 and up there is a sneakier way to do it that won't acquire
> any more lock than the statement-under-test does:
>
>     begin;
>     update pg_index set indisvalid = false
>       where indexrelid = 'soandso'::regclass;
>     explain analyze ...;
>     rollback;

this really smacks of that four-letter word that starts with h... -- i
am glad we have finally come around on the subject :-)

seriously, this is a great technique and an enormous time saver during
query optimization. thanks for sharing!

george

Re: Not Picking Index

От
Tom Lane
Дата:
"George Pavlov" <gpavlov@mynewplace.com> writes:
>> In PG 8.2 and up there is a sneakier way to do it that won't acquire
>> any more lock than the statement-under-test does:
>>
>> begin;
>> update pg_index set indisvalid = false
>> where indexrelid = 'soandso'::regclass;
>> explain analyze ...;
>> rollback;

> this really smacks of that four-letter word that starts with h... -- i
> am glad we have finally come around on the subject :-)

indisvalid isn't a hint; it was necessary to make CREATE INDEX CONCURRENTLY
work.  But if you want to (mis?)use it as a hint, you can ...

            regards, tom lane