Re: FW: view derived from view doesn't use indexes

Поиск
Список
Период
Сортировка
От Russell Keane
Тема Re: FW: view derived from view doesn't use indexes
Дата
Msg-id 8D0E5D045E36124A8F1DDDB463D548557CEF4D2D95@mxsvr1.is.inps.co.uk
обсуждение исходный текст
Ответ на Re: FW: view derived from view doesn't use indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi Tom,

Thanks for that, that was exactly the issue.
It absolutely is IMMUTABLE and changing it from VOLATILE has fixed the issue.

Much appreciated,

Russell,



-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: 26 July 2012 16:52
To: Russell Keane
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] FW: view derived from view doesn't use indexes

Russell Keane <Russell.Keane@inps.co.uk> writes:
> Using PG 9.0 and given the following definitions:

> CREATE OR REPLACE FUNCTION status_to_flag(status character) RETURNS
> integer AS $BODY$ ...
> $BODY$
> LANGUAGE plpgsql

> CREATE OR REPLACE VIEW test_view1 AS
> SELECT status_to_flag(test_table.status) AS flag, test_table.code_id
> FROM test_table;

> CREATE OR REPLACE VIEW test_view2 AS
> SELECT *
> FROM test_view1
> WHERE test_view1.flag = 1;

I think the reason why the planner is afraid to flatten this is that the function is (by default) marked VOLATILE.
Volatilefunctions in the select list are an optimization fence.  That particular function looks like it should be
IMMUTABLEinstead, since it depends on no database state.  If it does look at database state, you can probably use
STABLE.

http://www.postgresql.org/docs/9.0/static/xfunc-volatility.html
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: FW: view derived from view doesn't use indexes
Следующее
От: Andreas
Дата:
Сообщение: join against a function-result fails