Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

Started by Kirill Reshke27 days ago9 messageshackers
Jump to latest
#1Kirill Reshke
reshkekirill@gmail.com

Hi,

Small documentation omission found while testing event triggers on:
the Event Triggers chapter says in "table_rewrite" section:

The table_rewrite event occurs just before a table is rewritten by
some actions of the commands ALTER TABLE and ALTER TYPE.

but ALTER MATERIALIZED VIEW ... SET ACCESS METHOD also fires
table_rewrite, with TG_TAG = 'ALTER MATERIALIZED VIEW'

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
    <para>
     The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

--
Best regards,
Kirill Reshke

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Kirill Reshke (#1)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.
sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a
table is
-    rewritten by some actions of the commands <literal>ALTER
TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER
TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Probably should also edit: …just before a table [or materialized view] is
rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to
typed tables explicitly.

David J.

#3Kirill Reshke
reshkekirill@gmail.com
In reply to: David G. Johnston (#2)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Mon, 26 Oct 2026 at 09:29, David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Hi, thats for looking.

Probably should also edit: …just before a table [or materialized view] is rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to typed tables explicitly.

Did that, PFA my version of wording. Applicable from master down to v18.

David J.

--
Best regards,
Kirill Reshke

Attachments:

t254384_3
v2-master-18-19-table-rewrite.diffapplication/octet-stream; name=v2-master-18-19-table-rewrite.diffDownload+7-5
#4David G. Johnston
david.g.johnston@gmail.com
In reply to: Kirill Reshke (#3)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Mon, Oct 26, 2026 at 4:39 AM Kirill Reshke <reshkekirill@gmail.com>
wrote:

Did that, PFA my version of wording. Applicable from master down to v18.

LGTM

Thanks!

David J.

#5Chao Li
li.evan.chao@gmail.com
In reply to: Kirill Reshke (#3)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Oct 26, 2026, at 19:39, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Mon, 26 Oct 2026 at 09:29, David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Hi, thats for looking.

Probably should also edit: …just before a table [or materialized view] is rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to typed tables explicitly.

Did that, PFA my version of wording. Applicable from master down to v18.

David J.

--
Best regards,
Kirill Reshke
<v2-master-18-19-table-rewrite.diff>

While verifying the behaviors that this patch describes, I noticed an existing test case:
```
-- matview rewrite when changing access method
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT 1 AS a;
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
NOTICE: Table 'heapmv' is being rewritten (reason = 8)
```

The NOTICE is generated by a test function:
```
-- test with more than one reason to rewrite a single table
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
LANGUAGE plpgsql AS $$
BEGIN
RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
pg_event_trigger_table_rewrite_oid()::regclass,
pg_event_trigger_table_rewrite_reason();
END;
$$;
```

As you have replaced “table” with “relation” in the doc, maybe also update this NOTICE message?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#6Kirill Reshke
reshkekirill@gmail.com
In reply to: Chao Li (#5)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Tue, 27 Oct 2026 at 06:14, Chao Li <li.evan.chao@gmail.com> wrote:

On Oct 26, 2026, at 19:39, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Mon, 26 Oct 2026 at 09:29, David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Hi, thats for looking.

Probably should also edit: …just before a table [or materialized view] is rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to typed tables explicitly.

Did that, PFA my version of wording. Applicable from master down to v18.

David J.

--
Best regards,
Kirill Reshke
<v2-master-18-19-table-rewrite.diff>

While verifying the behaviors that this patch describes, I noticed an existing test case:
```
-- matview rewrite when changing access method
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT 1 AS a;
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
NOTICE: Table 'heapmv' is being rewritten (reason = 8)
```

The NOTICE is generated by a test function:
```
-- test with more than one reason to rewrite a single table
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
LANGUAGE plpgsql AS $$
BEGIN
RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
pg_event_trigger_table_rewrite_oid()::regclass,
pg_event_trigger_table_rewrite_reason();
END;
$$;
```

As you have replaced “table” with “relation” in the doc, maybe also update this NOTICE message?

Yep, can you do some legwork for me please?Can't find my cycles for
this right now

--
Best regards,
Kirill Reshke

#7Chao Li
li.evan.chao@gmail.com
In reply to: Kirill Reshke (#6)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Oct 27, 2026, at 13:15, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Tue, 27 Oct 2026 at 06:14, Chao Li <li.evan.chao@gmail.com> wrote:

On Oct 26, 2026, at 19:39, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Mon, 26 Oct 2026 at 09:29, David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Hi, thats for looking.

Probably should also edit: …just before a table [or materialized view] is rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to typed tables explicitly.

Did that, PFA my version of wording. Applicable from master down to v18.

David J.

--
Best regards,
Kirill Reshke
<v2-master-18-19-table-rewrite.diff>

While verifying the behaviors that this patch describes, I noticed an existing test case:
```
-- matview rewrite when changing access method
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT 1 AS a;
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
NOTICE: Table 'heapmv' is being rewritten (reason = 8)
```

The NOTICE is generated by a test function:
```
-- test with more than one reason to rewrite a single table
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
LANGUAGE plpgsql AS $$
BEGIN
RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
pg_event_trigger_table_rewrite_oid()::regclass,
pg_event_trigger_table_rewrite_reason();
END;
$$;
```

As you have replaced “table” with “relation” in the doc, maybe also update this NOTICE message?

Yep, can you do some legwork for me please?Can't find my cycles for
this right now

Sure, more than happy to help.

See the attached v3 diff. Please take a look when you get a chance.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t254384_7
v3-master-18-19-table-rewrite.diffapplication/octet-stream; name=v3-master-18-19-table-rewrite.diff; x-unix-mode=0644Download+14-10
#8surya poondla
suryapoondla4@gmail.com
In reply to: Chao Li (#7)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

Hi Chao, Kirill,

Thank you for reporting and fixing the docs.

v3 change looks good to me.

Regards,
Surya Poondla

#9Kirill Reshke
reshkekirill@gmail.com
In reply to: Chao Li (#7)
Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case

On Tue, 27 Oct 2026 at 11:16, Chao Li <li.evan.chao@gmail.com> wrote:

On Oct 27, 2026, at 13:15, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Tue, 27 Oct 2026 at 06:14, Chao Li <li.evan.chao@gmail.com> wrote:

On Oct 26, 2026, at 19:39, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Mon, 26 Oct 2026 at 09:29, David G. Johnston
<david.g.johnston@gmail.com> wrote:

On Sunday, October 25, 2026, Kirill Reshke <reshkekirill@gmail.com> wrote:

Suggested fix:

diff --git a/doc/src/sgml/event-trigger.sgml b/doc/src/sgml/event-trigger.sgml
--- a/doc/src/sgml/event-trigger.sgml
+++ b/doc/src/sgml/event-trigger.sgml
@@ -150,7 +150,8 @@
<para>
The <literal>table_rewrite</literal> event occurs just before a table is
-    rewritten by some actions of the commands <literal>ALTER TABLE</literal>
-    and <literal>ALTER TYPE</literal>.  While other
+    rewritten by some actions of the commands <literal>ALTER TABLE</literal>,
+    <literal>ALTER MATERIALIZED VIEW</literal> and <literal>ALTER
TYPE</literal>.
+    While other

Hi, thats for looking.

Probably should also edit: …just before a table [or materialized view] is rewritten…

This seems like it should be back-patched thru v15.

I’d be a bit more wordy here to connect the unexpected alter type action to typed tables explicitly.

Did that, PFA my version of wording. Applicable from master down to v18.

David J.

--
Best regards,
Kirill Reshke
<v2-master-18-19-table-rewrite.diff>

While verifying the behaviors that this patch describes, I noticed an existing test case:
```
-- matview rewrite when changing access method
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT 1 AS a;
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
NOTICE: Table 'heapmv' is being rewritten (reason = 8)
```

The NOTICE is generated by a test function:
```
-- test with more than one reason to rewrite a single table
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
LANGUAGE plpgsql AS $$
BEGIN
RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
pg_event_trigger_table_rewrite_oid()::regclass,
pg_event_trigger_table_rewrite_reason();
END;
$$;
```

As you have replaced “table” with “relation” in the doc, maybe also update this NOTICE message?

Yep, can you do some legwork for me please?Can't find my cycles for
this right now

Sure, more than happy to help.

See the attached v3 diff. Please take a look when you get a chance.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

LGTM
--
Best regards,
Kirill Reshke