Re: Inconsistency with EXPLAIN ANALYZE CREATE MATERIALIZED VIEW

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Subject: Re: Inconsistency with EXPLAIN ANALYZE CREATE MATERIALIZED VIEW
Date: 2026-11-19 09:44:00
Message-ID: CAN4CZFPY2uHkSZYS_n72jZ1aR=29fv93N7P=54_gWCsFjGLsrQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

I ran into this while working on an event trigger issue in the same
code path [1], and only found this thread after writing a fix, so here
is a patch for option 2.

It follows the previously discussed approach: with ANALYZE, EXPLAIN
first creates the empty view with create_ctas_nodata(), in the
caller's context,. Then it plans and runs the query as a
security-restricted operation with a restricted search_path, so it
also covers functions executed by the planner. A new IntoClause field
tells the intorel receiver to fill the existing relation instead of
creating it. Like RefreshMatViewByOid(), it keeps the view open while
filling it, otherwise a function evaluated by the planner could, for
example, create an index on it that intorel_receive() doesn't
maintain.

[1]: https://postgr.es/m/CAN4CZFOycbakF5swg0i_hH2dZTkMP2%2BoA%3DnoU0VFFFe3687ojw%40mail.gmail.com

Attachment Content-Type Size
v1-0001-Restrict-EXPLAIN-ANALYZE-CREATE-MATERIALIZED-VIEW.patch application/octet-stream 13.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-11-19 09:51:55 EXPLAIN ANALYZE CREATE TABLE AS EXECUTE runs non-SELECT prepared statements
Previous Message Zsolt Parragi 2026-11-19 09:37:35 Fire event triggers for relations created by EXPLAIN ANALYZE (CTAS, SELECT INTO, MAT VIEW)