Re: CREATE TABLE .. PARTITION OF fails to preserve tgenabled for inherited row triggers
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgresql.org, Amit Langote <amitlangote09@gmail.com>
Date: 2021-07-17T01:02:59Z
Lists: pgsql-hackers
On Fri, Jul 16, 2021 at 06:01:12PM -0400, Alvaro Herrera wrote: > On 2021-Jul-16, Justin Pryzby wrote: > > CREATE TABLE p(i int) PARTITION BY RANGE(i); > > CREATE TABLE p1 PARTITION OF p FOR VALUES FROM (1)TO(2); > > CREATE FUNCTION foo() returns trigger LANGUAGE plpgsql AS $$begin end$$; > > CREATE TRIGGER x AFTER DELETE ON p1 EXECUTE FUNCTION foo(); > > CREATE TRIGGER x AFTER DELETE ON p EXECUTE FUNCTION foo(); > > Hmm, interesting -- those statement triggers are not cloned, so what is > going on here is just that the psql query to show them is tripping on > its shoelaces ... I'll try to find a fix. > > I *think* the problem is that the query matches triggers by name and > parent/child relationship; we're missing to ignore triggers by tgtype. > It's not great design that tgtype is a bitmask of unrelated flags ... I see it's the subquery Amit wrote and proposed here: https://www.postgresql.org/message-id/CA+HiwqEiMe0tCOoPOwjQrdH5fxnZccMR7oeW=f9FmgszJQbgFg@mail.gmail.com .. and I realize that I've accidentally succeeded in breaking what I first attempted to break 15 months ago: On Mon, Apr 20, 2020 at 02:57:40PM -0500, Justin Pryzby wrote: > I'm happy to see that this doesn't require a recursive cte, at least. > I was trying to think how to break it by returning multiple results or results > out of order, but I think that can't happen. If you assume that pg_partition_ancestors returns its results in order, I think you can fix it by adding LIMIT 1. Otherwise I think you need a recursive CTE, as I'd feared. Note also that I'd sent a patch to add newlines, to make psql -E look pretty. v6-0001-fixups-c33869cc3bfc42bce822251f2fa1a2a346f86cc5.patch -- Justin
Commits
-
Fix pg_dump for disabled triggers on partitioned tables
- f0e21f2f6167 15.0 landed
- ccfc3cbb341a 11.13 landed
- cc340af33453 13.4 landed
- 5992c94dc7e4 12.8 landed
- 3c5b7c628621 14.0 landed
-
Preserve firing-on state when cloning row triggers to partitions
- fed35bd4a650 11.13 landed
- eef92de11e50 14.0 landed
- df80fa2ee504 15.0 landed
- c31516ae5b43 13.4 landed
- 7584ec1f6098 12.8 landed
-
Fix ALTER TABLE .. ENABLE/DISABLE TRIGGER recursion
- bbb927b4db9b 14.0 landed
- a795f6782fa8 11.10 landed
- 5f6463a20af1 13.1 landed
- 0e6b6f8c7192 12.5 landed
-
psql \d: Display table where trigger is defined, if inherited
- c33869cc3bfc 13.0 cited
-
Fix cloning of row triggers to sub-partitions
- 1fa846f1c9af 13.0 cited
-
Make pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise)
- 33a53130a894 12.0 cited