Can I add a hint clause to a materialized view in postgreSQL?

186 views Asked by At

Can I add a hint clause to a materialized view in PostgreSQL as follows? or is there another way?

ex1.

CREATE MATERIALIZED VIEW MV1
/*+
IndexScan(tableA)
*/
SELECT...

ex2.

/*+
IndexScan(tableA)
*/
REFRESH MATERIALIZED VIEW MV1

I tried both, but ex1 didn't work.

If possible, I'd like to do it ex1 way (include hint_plan in CREATE MATERIALIZED VIEW query).

Thanks for your help.

2

There are 2 answers

1
Maimoona Abid On

Hint clauses are not directly supported by PostgreSQL in CREATE MATERIALIZED VIEW. Usually, hints are included in the question, like:

SELECT /*+ IndexScan(tableA) */ columns FROM MV1;
0
jjanes On

Experimentally, the hint works when the query is run upon initial construction, but then is ignored upon refresh. Maybe this would best be addressed to pg_hint_plan's issue tracker.