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 1oP9O4-0005Am-FH for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Aug 2022 21:18:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oP9O2-00053k-DO for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Aug 2022 21:18:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oP9O1-00052z-VT for pgsql-hackers@lists.postgresql.org; Fri, 19 Aug 2022 21:18:38 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oP9Ns-0000K8-6d for pgsql-hackers@postgresql.org; Fri, 19 Aug 2022 21:18:35 +0000 Received: by mail-io1-xd31.google.com with SMTP id d68so4218040iof.11 for ; Fri, 19 Aug 2022 14:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc; bh=bpG0zlSewBxDj7kxFbt9ChVMLkk7Mgr9Qvn9G83lRQA=; b=PX3Qg4rqRdcnr/ApWmVZyothNTKX2ZRKZsROSID9Zr8YcB9EY4GpQZcwZOVyb2AF16 llIQ/pJUB1mlDGZGaiBYQSlNbqzOKRKJ+MAZ6443J61DLg7yvoEtQCA4cfrUOHhHHpZd P7dKMZ2jT1SkVSgcTSVxDk/ylrJ3XyKJPcarqZt8ibP3yDjOTcj6eOkJpX3X4jFESG2F So99saDj+YSTOCFMSezOiY/Vn1ZD1FSciasINxEXh6IpmIWIZmRP6c3rPXIEXOK78Nla 9iBhBdGXGr6dbaoFInmTkKG1vX/Ig+18ZWzlDu1StYGpAJkqzdFRLiUB6Hi2rBFjznBn RFsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc; bh=bpG0zlSewBxDj7kxFbt9ChVMLkk7Mgr9Qvn9G83lRQA=; b=4mO+UN1FI53wx3XD50iuwt3k9jdgg2Lu5CGPnIAwOi34wXlRT1nZSH+R44Rh3pADh0 xxQjHTik80Um0dS35BCg6zV1i/OyojIv/paYwTKUhJF2dMDO4coTi5JXB6uIeV1hTUn9 nklOHBpXaUSeSkhJ1YJIF5bdCKVTg9myEK+RD+0yP1EMFIh09xE6DmBD8bhAO8HyllMP /2dCx4dO9g4E03E4uQZvCuknLE6+H81TjL4C9nNZd2BFFwa/YWE4X5RFxI9GyewUuFn9 oyfbXac/L09CSIivApWnaFS0+nKb84cHIwdR1oV91Xk5Jz+JmKljOaFPG8zYdwOssJXr 81YA== X-Gm-Message-State: ACgBeo1U5p9VEoPAlfqUx+EzX9+BdFshdov/O9AX8Ukhf71gpuWW+nsu qDiLHppg0u+ZkqjCKW62VkOGtg== X-Google-Smtp-Source: AA6agR4xv4N22nlhby6mchDjHWOSPtJ0lSkYNvK1q/kXpZh9j7geu3i2WzniC54jfzQUbVMb0zblsA== X-Received: by 2002:a5d:9616:0:b0:67c:2039:c88e with SMTP id w22-20020a5d9616000000b0067c2039c88emr4167776iol.68.1660943906160; Fri, 19 Aug 2022 14:18:26 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q4-20020a92c004000000b002e94f9175cdsm667558ild.71.2022.08.19.14.18.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Aug 2022 14:18:25 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 044DD800C2F; Fri, 19 Aug 2022 16:18:24 -0500 (CDT) Date: Fri, 19 Aug 2022 16:18:24 -0500 From: Justin Pryzby To: pgsql-hackers@postgresql.org Cc: Tomas Vondra , Peter Smith , David Rowley , Alvaro Herrera Subject: FOR EACH ROW triggers, on partitioend tables, with indexes? Message-ID: <20220819211824.GX26426@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Wed, Aug 17, 2022 at 09:54:34AM -0500, Justin Pryzby wrote: > But an unfortunate consequence of not fixing the historic issues is that it > precludes the possibility that anyone could be expected to notice if they > introduce more instances of the same problem (as in the first half of these > patches). Then the hole which has already been dug becomes deeper, further > increasing the burden of fixing the historic issues before being able to use > -Wshadow. > > The first half of the patches fix shadow variables newly-introduced in v15 > (including one of my own patches), the rest are fixing the lowest hanging fruit > of the "short list" from COPT=-Wshadow=compatible-local > > I can't see that any of these are bugs, but it seems like a good goal to move > towards allowing use of the -Wshadow* options to help avoid future errors, as > well as cleanliness and readability (rather than allowing it to get harder to > use -Wshadow). +Alvaro You wrote: |commit 86f575948c773b0ec5b0f27066e37dd93a7f0a96 |Author: Alvaro Herrera |Date: Fri Mar 23 10:48:22 2018 -0300 | | Allow FOR EACH ROW triggers on partitioned tables Which added: 1 + partition_recurse = !isInternal && stmt->row && 2 + rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE; 3 ... 4 + if (partition_recurse) 5 ... 6 + List *idxs = NIL; 7 + List *childTbls = NIL; 8 ... 9 + if (OidIsValid(indexOid)) 10 + { 11 + ListCell *l; 12 + List *idxs = NIL; 13 + 14 + idxs = find_inheritance_children(indexOid, ShareRowExclusiveLock); 15 + foreach(l, idxs) 16 + childTbls = lappend_oid(childTbls, 17 + IndexGetRelation(lfirst_oid(l), 18 + false)); 19 + } 20 ... 21 + for (i = 0; i < partdesc->nparts; i++) 22 ... 23 + if (OidIsValid(indexOid)) 24 ... 25 + forboth(l, idxs, l2, childTbls) The inner idxs is set at line 12, but the outer idxs being looped over at line 25 is still NIL, because the variable is shadowed. That would be a memory leak or some other bug, except that it also seems to be dead code ? https://coverage.postgresql.org/src/backend/commands/trigger.c.gcov.html#1166 Is it somwhow possible to call CreateTrigger() to create a FOR EACH ROW trigger, with an index, and not internally ? The comments say that a user's CREATE TRIGGER will not have a constraint, so won't have an index. * constraintOid is zero when * executing a user-entered CREATE TRIGGER command. * + * indexOid, if nonzero, is the OID of an index associated with the constraint. + * We do nothing with this except store it into pg_trigger.tgconstrindid. See also: <20220817145434.GC26426@telsasoft.com> Re: shadow variables - pg15 edition -- Justin