Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ikxxO-00030V-N4 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Dec 2019 22:19:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ikxwO-0004iL-EV for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Dec 2019 22:18:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ikxwO-0004fz-64 for pgsql-bugs@lists.postgresql.org; Fri, 27 Dec 2019 22:18:40 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ikxwG-0003os-TA for pgsql-bugs@postgresql.org; Fri, 27 Dec 2019 22:18:39 +0000 Received: by mail-pf1-x443.google.com with SMTP id q10so15328426pfs.6 for ; Fri, 27 Dec 2019 14:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=K1ltDW7IjsRb0aakndnEBKTiPIQdOeqihCs5PDWUvo8=; b=qZjLlOQyJy/0Nx1frdL6jFCc8gQ0xfP+0JR4ENOkdSfOdzlegV5LTcT2wwDxFLjpHZ szSoJpxoEeeJ6JhM9RmFDbzJTHL8m1eb2WZI0pDt1ZSesjXg7Y+tIzfwBqMtT8n1ERgt h00Ns9LV1H7qs2f84bOzj7oiHNXi5NQ/mbsgitjFUs9I1sIUV1UDDu2DhrymdC4MXLLZ VnKzpng8mZgyjxZjPOIns6nZQUcUpCZxLsu9krkN2HgzqX3pUM3puQ/0b+Hg8ZHJnvTX H0fIjfqeO6AgNrds0tpXWREMXSYRNvKBfnaezvi1CRYjvie3qyw/KS5FOF6F76HYczQ7 nicQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=K1ltDW7IjsRb0aakndnEBKTiPIQdOeqihCs5PDWUvo8=; b=CYFES7TMAzfRBKpBQIHgoGNR85Q04rcXMi+M55vqkoh0MnVg3vtCy2nzCHJwNNaik5 c6hDPx751ZUjaU5tSrUEZcYD/n4Ga/ow9X4OrBWiyaKsb0a13F3MH7k3WOdMuCvLLkKv KTp3crkIQ+LscKwDvoOjuh3b0ddrr4QJiUDoOW8iG2RTxorlw6HROTq12a1kudPMayjU jR+HiD4x/Lz5+yhhkN90iGM+DJ45QFRh9QciFjwZsUDyct1kv0gJuM5fXPk9wON3gTKo K0YslSd6SDEnPmTJyiVo6me761+92Qj13ZrL0Eal0trxojPOGlqO1pk7wW8cxDuaYrnf KSHQ== X-Gm-Message-State: APjAAAU//ImQ5Tz63ooA/hiP8U03BnFoBpglw74IAVfxZuGT+5cglh6H syBX6N/Tv8Nl5IugKX5eC3Mzpw== X-Google-Smtp-Source: APXvYqwTMtkMSx36pi5KkTgVN9uJACt7/R+PfqywP6qtT+hGbxZYwG20Qsf13WWR+9Tqt6g2NcuekA== X-Received: by 2002:a62:1746:: with SMTP id 67mr40475314pfx.45.1577485110408; Fri, 27 Dec 2019 14:18:30 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([179.56.30.174]) by smtp.gmail.com with ESMTPSA id c199sm42773484pfb.126.2019.12.27.14.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2019 14:18:29 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id DD140300801; Fri, 27 Dec 2019 19:18:26 -0300 (-03) Date: Fri, 27 Dec 2019 19:18:26 -0300 From: Alvaro Herrera To: Amit Langote Cc: Petr Fedorov , PostgreSQL mailing lists Subject: Re: A row-level trigger on a partitioned table is not created on a sub-partition created later Message-ID: <20191227221826.GA2547@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PEIAKu/WMn1b1Hv9" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191227213734.GA19021@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Dec-27, Alvaro Herrera wrote: > Working on getting your fix pushed now. Ran out of time for today, but I added this test that reproduces the issue -- fails without your patch, and works with it. One thing I just realized is that in next minors' release notes we should publish a recipe to fix catalogs for existing databases, unless we go for a fix that doesn't require changing the catalogs -- I don't know what that would be, though, but maybe it would not be totally insane to clone even internal triggers in the cases that matter. (I wonder if a better solution for the master branch would involve a new pg_trigger column that indicates the parent trigger for a cloned trigger. That would avoid pg_dump's new subquery. Also: would it be better to use pg_partition_ancestors instead of the sub-subquery? ... though that doesn't work in pg11 ...) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --PEIAKu/WMn1b1Hv9 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="trigtest.patch" commit 8a2318fcbdc501e6b230a22f6a6b1de57f871e74 Author: Alvaro Herrera AuthorDate: Fri Dec 27 18:56:05 2019 -0300 CommitDate: Fri Dec 27 18:59:25 2019 -0300 Add failed test that shows the issue diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out index 1e4053ceed..b91fbd0648 100644 --- a/src/test/regress/expected/triggers.out +++ b/src/test/regress/expected/triggers.out @@ -1981,15 +1981,22 @@ create trigger trg1 after insert on trigpart for each row execute procedure trig create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); +create table trigpart4 partition of trigpart for values from (3000) to (4000) partition by range (a); +create table trigpart41 partition of trigpart4 for values from (3000) to (3500); +create table trigpart42 (like trigpart); +alter table trigpart4 attach partition trigpart42 for values from (3500) to (4000); select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; - tgrelid | tgname | tgfoid ------------+--------+----------------- - trigpart | trg1 | trigger_nothing - trigpart1 | trg1 | trigger_nothing - trigpart2 | trg1 | trigger_nothing - trigpart3 | trg1 | trigger_nothing -(4 rows) + tgrelid | tgname | tgfoid +------------+--------+----------------- + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart2 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing + trigpart4 | trg1 | trigger_nothing + trigpart41 | trg1 | trigger_nothing + trigpart42 | trg1 | trigger_nothing +(7 rows) drop trigger trg1 on trigpart1; -- fail ERROR: cannot drop trigger trg1 on table trigpart1 because trigger trg1 on table trigpart requires it @@ -2003,12 +2010,15 @@ HINT: You can drop trigger trg1 on table trigpart instead. drop table trigpart2; -- ok, trigger should be gone in that partition select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; - tgrelid | tgname | tgfoid ------------+--------+----------------- - trigpart | trg1 | trigger_nothing - trigpart1 | trg1 | trigger_nothing - trigpart3 | trg1 | trigger_nothing -(3 rows) + tgrelid | tgname | tgfoid +------------+--------+----------------- + trigpart | trg1 | trigger_nothing + trigpart1 | trg1 | trigger_nothing + trigpart3 | trg1 | trigger_nothing + trigpart4 | trg1 | trigger_nothing + trigpart41 | trg1 | trigger_nothing + trigpart42 | trg1 | trigger_nothing +(6 rows) drop trigger trg1 on trigpart; -- ok, all gone select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql index c21b6c124e..7cd835449c 100644 --- a/src/test/regress/sql/triggers.sql +++ b/src/test/regress/sql/triggers.sql @@ -1366,6 +1366,10 @@ create trigger trg1 after insert on trigpart for each row execute procedure trig create table trigpart2 partition of trigpart for values from (1000) to (2000); create table trigpart3 (like trigpart); alter table trigpart attach partition trigpart3 for values from (2000) to (3000); +create table trigpart4 partition of trigpart for values from (3000) to (4000) partition by range (a); +create table trigpart41 partition of trigpart4 for values from (3000) to (3500); +create table trigpart42 (like trigpart); +alter table trigpart4 attach partition trigpart42 for values from (3500) to (4000); select tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text; drop trigger trg1 on trigpart1; -- fail --PEIAKu/WMn1b1Hv9--