view selection during query rewrite

Поиск
Список
Период
Сортировка
От Vamsi Meduri
Тема view selection during query rewrite
Дата
Msg-id CAB8vO9Sw7K2VWHz+Z3SqFJFzFG8zYyZTzNHqiXcnfzcR5yNYxw@mail.gmail.com
обсуждение исходный текст
Ответы Re: view selection during query rewrite
Список pgsql-general
Suppose I have the following query and a view v1 defined as follows:
Q1: SELECT * FROM Table1 WHERE Table1.col1 = 5 and Table1.col2 LIKE '%abc%';
create view v1 as select * from Table1 where Table1.col1 = 5;

An effective way to execute Q1 would be to re-write it as: select * from v1 where col2 LIKE '%abc%'; provided that the selection predicates are highly selective and also if it is cheaper in execution time of the query.

However I see that postgres does not automatically perform query rewriting using view. I have looked at the plan using explain (analyze) and I see that Q1 is always executed using the base tables unless I explicitly mention the view in the query instead of the base table.

Is there a way to enforce automatic view selection in postgres or is it up to the user to write the query optimally?



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

Предыдущее
От: Andy Fan
Дата:
Сообщение: Re: Check what has been done for a uncommitted prepared transaction
Следующее
От: Tom Lane
Дата:
Сообщение: Re: view selection during query rewrite