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 1gV22S-0005Pl-U4 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 22:22:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gV22Q-0006AZ-Iv for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 22:22:30 +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 1gV22Q-0006AR-Bu for pgsql-hackers@lists.postgresql.org; Thu, 06 Dec 2018 22:22:30 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gV22M-0003EH-90 for pgsql-hackers@lists.postgresql.org; Thu, 06 Dec 2018 22:22:28 +0000 Received: by mail-qk1-x731.google.com with SMTP id w12so1345909qkb.9 for ; Thu, 06 Dec 2018 14:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=CXanrnSfLdpdXM/DlPJKC1ZP12T5Xxhc2GZWls3ibLs=; b=UgDImCr2RbAKxE/DoDJnDTAnYwf/v4UD4W02kqKFaakwA8UnnoSrFRRBo6QfgJHtbq bCgzWUX2xs/d26mDYe9zvQQ0SLGz2bky+afiTvuwYgoF9IqATxOKkJqs9q9bDcmHjpst WFgb6lUcg8p2E3qitw9R2jks+0RjfAv2UtV+FXGaalVGjr4joH2aBD9wofzsYZrBKdzC tIkMBEScAWGMxBpjENL3ztL4QLy3qFMC48NZftaTx22LURioagpWvK2pv+jtYENktGMD YvvTuHLMxRFoqAkn8xH0Dje/02oIVz8+ZwpsB15y2e6dFc3ifR4YGEaRret5gYEBC5dD jmeQ== 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:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=CXanrnSfLdpdXM/DlPJKC1ZP12T5Xxhc2GZWls3ibLs=; b=I3bC7hyKJ1QI7njr4zL8N+F6+F4Ie6ptxZUfUX8rLgJRwJeZD4DCs2aOp1JRyXFMN4 89MdSOp13cFjXUbHkvSjwSRRrRmuA5ViPaynAmuva54xzNFdDpWZWsj+kFCtg/598cSJ c/lCxPfQffH2prbXzCvSMqsIzB920lN4SRYs42OhazD2WWTroJylJYoGDbICB3kXtYL4 rf4SUYX4bVC3DrsDpn+U4UkKfV3OVoALlQMRGwI6/Shad/iwZfyDbhOqjJrFFGha57qB g15r6ESVQSJlXScwAwU/xurYvP3fX2l80fIb1fli8nAKlq9/sFz2eh9xQAOR9wcEQ0Pq Mh8Q== X-Gm-Message-State: AA+aEWZiwi9edZhrsJeojZnAVeZsfoFrjShunuhsPv6/XsSnLVN1fp/5 p6nuoB6YscFx5lAlUE5joLsaj4LJfM5OPEV2zCNNeyYCajImuMgWAo56h4qZ9KvYfmOoG80AG46 X6qFs8pMEmjvWF8p6KsjFHrAoxJNfGpGqjbnC4H5ooMsBo3G1cGwzM/7u3W3J/eNCDVgX6Lam4r ROK6eUOCgZf4kU8A== X-Google-Smtp-Source: AFSGD/WeDHwJX9BH9ghPmIEAcfMyChA+Qp/hB4Kjk8EgN2waDeObE6pFxlyVCLpc3QzpDVFm01dDMw== X-Received: by 2002:a37:360a:: with SMTP id d10mr27939324qka.40.1544134944301; Thu, 06 Dec 2018 14:22:24 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id b8sm1355108qka.79.2018.12.06.14.22.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Dec 2018 14:22:23 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 6BEEF71C; Thu, 6 Dec 2018 19:22:21 -0300 (-03) Date: Thu, 6 Dec 2018 19:22:21 -0300 From: Alvaro Herrera To: Pg Hackers Subject: rewrite ExecPartitionCheckEmitError Message-ID: <20181206222221.g5witbsklvqthjll@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ki3z2n5j73ow2eol" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ki3z2n5j73ow2eol Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Just on cleanliness grounds, I propose to rewrite the function in $SUBJECT. I came across this while reviewing some already-committed patch for partition pruning, and it's been sitting in my laptop ever since. I think the current coding is too convoluted and hard to follow. The patch makes it much simpler (IMO). -- Álvaro Herrera --ki3z2n5j73ow2eol Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-rewrite-ExecPartitionCheckEmitError.patch" From 8c8ac713ac168b2678925e58cdfc83694a8fa5b9 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 14 Nov 2018 20:57:19 -0300 Subject: [PATCH] rewrite ExecPartitionCheckEmitError --- src/backend/executor/execMain.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index d83d296d82..78c8ce4935 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1837,11 +1837,9 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate) { - Relation rel = resultRelInfo->ri_RelationDesc; - Relation orig_rel = rel; - TupleDesc tupdesc = RelationGetDescr(rel); - char *val_desc; - Bitmapset *modifiedCols; + Oid root_relid; + TupleDesc tupdesc; + char *valdsc; Bitmapset *insertedCols; Bitmapset *updatedCols; @@ -1851,11 +1849,13 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo, */ if (resultRelInfo->ri_PartitionRoot) { - TupleDesc old_tupdesc = RelationGetDescr(rel); + TupleDesc old_tupdesc; AttrNumber *map; - rel = resultRelInfo->ri_PartitionRoot; - tupdesc = RelationGetDescr(rel); + root_relid = RelationGetRelid(resultRelInfo->ri_PartitionRoot); + + old_tupdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc); + tupdesc = RelationGetDescr(resultRelInfo->ri_PartitionRoot); /* a reverse map */ map = convert_tuples_by_name_map_if_req(old_tupdesc, tupdesc, gettext_noop("could not convert row type")); @@ -1868,20 +1868,24 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo, slot = execute_attr_map_slot(map, slot, MakeTupleTableSlot(tupdesc, &TTSOpsVirtual)); } + else + { + root_relid = RelationGetRelid(resultRelInfo->ri_RelationDesc); + tupdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc); + } insertedCols = GetInsertedColumns(resultRelInfo, estate); updatedCols = GetUpdatedColumns(resultRelInfo, estate); - modifiedCols = bms_union(insertedCols, updatedCols); - val_desc = ExecBuildSlotValueDescription(RelationGetRelid(rel), - slot, - tupdesc, - modifiedCols, - 64); + valdsc = ExecBuildSlotValueDescription(root_relid, + slot, + tupdesc, + bms_union(insertedCols, updatedCols), + 64); ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("new row for relation \"%s\" violates partition constraint", - RelationGetRelationName(orig_rel)), - val_desc ? errdetail("Failing row contains %s.", val_desc) : 0)); + RelationGetRelationName(resultRelInfo->ri_RelationDesc)), + valdsc ? errdetail("Failing row contains %s.", valdsc) : 0)); } /* -- 2.11.0 --ki3z2n5j73ow2eol--