Re: Queries joining views

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Queries joining views
Дата
Msg-id 20119.1156195953@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Queries joining views  (DelGurth <delgurth@gmail.com>)
Ответы Re: Queries joining views  (DelGurth <delgurth@gmail.com>)
Re: Queries joining views  (Alban Hertroys <alban@magproductions.nl>)
Список pgsql-general
DelGurth <delgurth@gmail.com> writes:
> As you can see we tried some indexes, to see if we could
> get the queries on the views to become faster.

> Indexes:
>     "mm_insrel_table_pkey" PRIMARY KEY, btree (number)
>     "mm_insrel_dir_not_one_idx" btree (dnumber, snumber) WHERE dir <> 1
>     "mm_insrel_dnumber_dir_not_one_idx" btree (dnumber) WHERE dir <> 1
>     "mm_insrel_full_idx" btree (snumber, dnumber, rnumber, dir) WHERE dir <>
> 1
>     "mm_insrel_relation_idx" btree (snumber, dnumber, rnumber)

Hmph ... it certainly appears to be choosing the wrong index in the
second case.  I wonder why --- can you show the relpages and reltuples
stats from pg_class for these indexes?

It might be interesting also to examine the output of just

    explain select * from mm_insrel_table where dnumber=558332 and dir<>1

with different subsets of these indexes in place.  I'd like to see what
it's deriving as the cost estimates for these indexes.  If you can get
an EXPLAIN selecting each one of the indexes, that would help diagnose
what's going on.

Dunno if you know this trick already, but it's possible to experiment
with different index subsets without physically dropping and recreating
the indexes.  Try

    begin;
    drop [unwanted indexes]
    explain ...
    rollback;

This will hold exclusive lock on the table until you rollback, so if
it's a production database you want to be quick about it --- maybe put
the whole thing in a SQL script.  But it sure beats rebuilding indexes.

BTW, what PG version is this exactly?

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: DelGurth
Дата:
Сообщение: Re: Queries joining views
Следующее
От: elein
Дата:
Сообщение: Re: Best approach for a "gap-less" sequence