Re: Issue in pg_catalog.pg_indexes view definition

Поиск
Список
Период
Сортировка
От Amit Langote
Тема Re: Issue in pg_catalog.pg_indexes view definition
Дата
Msg-id f7854e9a-019e-52e9-d1d5-c08818f49bef@lab.ntt.co.jp
обсуждение исходный текст
Ответ на Issue in pg_catalog.pg_indexes view definition  (Dilip Kumar <dilipbalaut@gmail.com>)
Ответы Re: Issue in pg_catalog.pg_indexes view definition  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
Re: Issue in pg_catalog.pg_indexes view definition  (Dilip Kumar <dilipbalaut@gmail.com>)
Список pgsql-hackers
On 2016/07/14 16:08, Dilip Kumar wrote:
> Query:
> postgres=# select * from pg_catalog.pg_indexes where indexdef is not null;
> ERROR:  cache lookup failed for index 2619
> 
> If we see the plan for the same:
> -------------------------------------------
> Nested Loop Left Join
>    Join Filter: (t.oid = i.reltablespace)
>    ->  Hash Left Join
>          Hash Cond: (c.relnamespace = n.oid)
>          ->  Hash Join
>                Hash Cond: (i.oid = x.indexrelid)
>   *             ->  Seq Scan on pg_class i*
> *                     Filter: ((pg_get_indexdef(oid) IS NOT NULL) AND
> (relkind = 'i'::"char"))*
>                      .......

...

> I am not sure what should be the correct fix for this problem.
> 
> I think even if we try to call this function on index oid *pg_get_indexdef(*
> x.indexrelid*) *AS indexdef, problem will not be solved, because both will
> fall in same equivalence class hence clause can be distributed to pg_class
> also.
> 
> Is this a bug ?
> If yes, what should be the right fix ?

Can we say that pg_get_indexdef() has "side-effects" because it can error
like this?  Shouldn't such a function be marked *volatile*?  Because if I
do so by updating pg_proc, the plan changes (perhaps) to a safe one in
this context:

explain (costs off) select * from pg_catalog.pg_indexes where indexdef is
not null;                                      QUERY PLAN

-----------------------------------------------------------------------------------------Subquery Scan on pg_indexes
Filter:(pg_indexes.indexdef IS NOT NULL)  ->  Nested Loop Left Join        Join Filter: (t.oid = i.reltablespace)
->  Hash Left Join              Hash Cond: (c.relnamespace = n.oid)              ->  Hash Join                    Hash
Cond:(i.oid = x.indexrelid)                    ->  Seq Scan on pg_class i                          Filter: (relkind =
'i'::"char")                   ->  Hash                          ->  Hash Join                                Hash
Cond:(x.indrelid = c.oid)                                ->  Seq Scan on pg_index x                                ->
Hash                                     ->  Seq Scan on pg_class c                                            Filter:
(relkind= ANY
 
('{r,m}'::"char"[]))              ->  Hash                    ->  Seq Scan on pg_namespace n        ->  Materialize
        ->  Seq Scan on pg_tablespace t
 
(21 rows)

Thanks,
Amit





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

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: pgbench - allow to store select results into variables
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Issue in pg_catalog.pg_indexes view definition