Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4YjT-00024C-Js for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Jul 2021 01:03:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m4YjS-0007DS-Ic for pgsql-hackers@arkaria.postgresql.org; Sat, 17 Jul 2021 01:03:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4YjS-0007DJ-8S for pgsql-hackers@lists.postgresql.org; Sat, 17 Jul 2021 01:03:06 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m4YjP-0000K4-Hz for pgsql-hackers@postgresql.org; Sat, 17 Jul 2021 01:03:05 +0000 Received: by mail-il1-x136.google.com with SMTP id b14so9948556ilf.7 for ; Fri, 16 Jul 2021 18:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XXfmHLh23G0Vw+MOckr+bJsmlPU+PNiMU41vg1fJOls=; b=B8yeQnsIIYgkX5mFd8wDRZ1kgmr0AX6n5ToTgiJ6xsqMfbEVpdd7gM1XXprLTsvt6B g32kIffVqlfH6eE5abjv+DvA2JcoTzlCx2BamnZv26AfDzC8Q/bvaaN3aGlh6gY5AQmy maPmM7JXTyEWD5i2+FHdDj0/b4eM8D8aN1PMJqQn+6xF8DDAEnAE8it1fqmx2eBErJdZ GHGoM7m1gKQqIflW9zWMK6e9XYznt8dZ6I6LEdqw7QQPhY/cDW3I3jnIO1PbqTKubgnf /8GPq8QRDWw85LyRRkFSnfJsYKeFy1PpGyjw4kPplIhD8J37kvTJGzX+Vr3Ukb6Dtkoh uUrg== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XXfmHLh23G0Vw+MOckr+bJsmlPU+PNiMU41vg1fJOls=; b=uIpvDkUEEDqU/fnFtJGyuTgxpkwEPkU1d5LUGSksRVok9txCHpe/5ebiGyqbIngYGv PQ6t2WQxrYojdbnf0Mv85KAaRf700Jmnd4bIdSGhnJU/qceLE4wNYM2qx25PQAFcCyTE Rkg8P0TshDeTJaPQ3lAYTwVhR10k06HryJMoYFBAogqm3FPFwuPYil1nqJlnjyh+OuYq i0RUVlTebwZ6/qipmH2mV0W007OEP4Myl3UKbjl/5p4uXOqTpRu11WeafYMAgIVnnlma ZAp2kbtm4mB0qkyt9bGZmM0d9S/l+Z/fp+irrTls80YVjRW4TJ5jciVpM/wH4n1+Jzmy VCVg== X-Gm-Message-State: AOAM532Og0Qe/jLkbF+X0A28FtdXP7wL1Nm31QqWQz0NhC8zwaIp7/2v k6RKQYf3bjvIplnDIBbE7DGB7w== X-Google-Smtp-Source: ABdhPJzRR35KuIbtmi7KTsNdSTFhq3Ho6Ml8pNETb+AJcRsFIodm5mqbHJK8Z+ZlBVhVONkkiWcnpQ== X-Received: by 2002:a92:c888:: with SMTP id w8mr8171350ilo.140.1626483781743; Fri, 16 Jul 2021 18:03:01 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id i7sm5357764ilb.67.2021.07.16.18.03.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 18:03:01 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id A989F800B38; Fri, 16 Jul 2021 20:02:59 -0500 (CDT) Date: Fri, 16 Jul 2021 20:02:59 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Tom Lane , pgsql-hackers@postgresql.org, Amit Langote Subject: Re: CREATE TABLE .. PARTITION OF fails to preserve tgenabled for inherited row triggers Message-ID: <20210717010259.GU20208@telsasoft.com> References: <20210716193319.GS20208@telsasoft.com> <202107162201.g243c7mnnxuy@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202107162201.g243c7mnnxuy@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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