Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faDLO-0002KU-Br for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Jul 2018 04:55:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1faDLM-0005eC-TR for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Jul 2018 04:55:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faDLM-0005dy-IJ for pgsql-hackers@lists.postgresql.org; Tue, 03 Jul 2018 04:55:12 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faDLJ-0005qN-Vt for pgsql-hackers@postgresql.org; Tue, 03 Jul 2018 04:55:11 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 31C8E18D; Tue, 3 Jul 2018 00:55:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 03 Jul 2018 00:55:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=wxYLADjgyc5mJDc1S7TohMh7/xNDoN8tKQkL/9oaa1A=; b=YaEEulOz CuqVqpvSHfCTGWfZQY1ictD3vu+V+uclVvmyiwUeBhsUXDZmtFBuSEVaNIyexzGz xUZ36yFJ8DWLGzJBA2MRa4vrWcTdvOpv52zCkFhl5JY9vRlpVgvv333uiRXCHIrc +s2H7aQM3e61kN3V+NnJ+2xCoJVC91vRBwjVvMlrQC9wwQ1X7XvQ1d2qyku4IxCm QWP8XTyzkamNRQsRJJLHT/BxGmz6EajF0YEy5QxvZfN1gILaMNLxeTpj/gWtBTDX mo1/9qnZIZbm8MazgJobNXsQUp6nSB5Gz3nFFIF1kwP5DD/JoiTNPYOinipkn0Zm Hb4I3nUcffXIvg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=wxYLADjgyc5mJDc1S7TohMh7/xNDo N8tKQkL/9oaa1A=; b=lxvWYQPGqygjD4Py4JM7p7WXnU8CbOm4r1zu2d7egW6af buVzRuXu53pwPDODYdoD2wdST2mbVOKyZqtyNGJ7Rzc1s15u8NiJMvxhOr9MNJgE 1PLQRTBKIJyH5JPTL8GXHaOIleT7n/rGvXrWxZqVet1wiTpb29IDBgWpVQ3OO3ZY gsPh8fFGwOh5dAxyNjHaEkW57ijZcWKlojOZd5hMBKSMuZgQOxjymxbgXs2IThjJ m07QUMQWeFlVyVU12r5F7ZkVluOw8Kt4DG1XBJMUoIha0G+DzquGUeQVHgIREY1D abhsbcNn8fD5uKkmxaTm475Wq+l99jAcNvW1tiEBw== X-ME-Proxy: X-ME-Sender: Received: from paquier.xyz (mp76f1faf5.ap.nuro.jp [118.241.250.245]) by mail.messagingengine.com (Postfix) with ESMTPA id DEDBB1026C; Tue, 3 Jul 2018 00:55:05 -0400 (EDT) Date: Tue, 3 Jul 2018 13:55:02 +0900 From: Michael Paquier To: David Rowley Cc: Robert Haas , Postgres hackers Subject: Re: pgsql: Clarify use of temporary tables within partition trees Message-ID: <20180703045502.GA26236@paquier.xyz> References: <20180702221650.GA2159@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vGgW1X5XWziG23Ko" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --vGgW1X5XWziG23Ko Content-Type: multipart/mixed; boundary="5mCyUwZo2JvN/JJP" Content-Disposition: inline --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 03, 2018 at 12:59:33PM +1200, David Rowley wrote: > On 3 July 2018 at 10:16, Michael Paquier wrote: >> On Mon, Jul 02, 2018 at 02:07:37PM -0400, Robert Haas wrote: >>> I'd rather keep an elog(ERROR) than completely remove the check. >> >> +1. > > Attached Okay, the patch looks logically correct to me, I just tweaked the comments as per the attached. I would also back-patch that down to v11 to keep the code consistent with HEAD.. What do you think? -- Michael --5mCyUwZo2JvN/JJP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="remove_dead_code_from_expand_partitioned_rtentry_v3.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer= /prep/prepunion.c index 2d470240d5..71e256f8fd 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -1681,7 +1681,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTb= lEntry *parentrte, int i; RangeTblEntry *childrte; Index childRTindex; - bool has_child =3D false; PartitionDesc partdesc =3D RelationGetPartitionDesc(parentrel); =20 check_stack_depth(); @@ -1707,6 +1706,16 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeT= blEntry *parentrte, top_parentrc, parentrel, appinfos, &childrte, &childRTindex); =20 + /* + * If the partitioned table has no partitions, treat this as the + * non-inheritance case. + */ + if (partdesc->nparts =3D=3D 0) + { + parentrte->inh =3D false; + return; + } + for (i =3D 0; i < partdesc->nparts; i++) { Oid childOID =3D partdesc->oids[i]; @@ -1715,15 +1724,13 @@ expand_partitioned_rtentry(PlannerInfo *root, Range= TblEntry *parentrte, /* Open rel; we already have required locks */ childrel =3D heap_open(childOID, NoLock); =20 - /* As in expand_inherited_rtentry, skip non-local temp tables */ + /* + * Temporation partitions belonging to other sessions should have been + * disallowed at definition, but for paranoia's sake, let's double + * check. + */ if (RELATION_IS_OTHER_TEMP(childrel)) - { - heap_close(childrel, lockmode); - continue; - } - - /* We have a real partition. */ - has_child =3D true; + elog(ERROR, "temporary relation from another session found as partition= "); =20 expand_single_inheritance_child(root, parentrte, parentRTindex, parentrel, top_parentrc, childrel, @@ -1738,14 +1745,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeT= blEntry *parentrte, /* Close child relation, but keep locks */ heap_close(childrel, NoLock); } - - /* - * If the partitioned table has no partitions or all the partitions are - * temporary tables from other backends, treat this as non-inheritance - * case. - */ - if (!has_child) - parentrte->inh =3D false; } =20 /* --5mCyUwZo2JvN/JJP-- --vGgW1X5XWziG23Ko Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAls7AaYACgkQnvQgOdby QH2Grg/9Fe6TddIP9Ntk/nNU39AEIiKg7lvccdelnPzlrsmorQ+G4wkheg0ZF7BT HxIEDUDxrKQ2mU0pIRQOqt7PEkihbd/B+oEg2Tcq99skgCx/n41YicQOkBpI0B+m qkIC0dKDS6nNK7o7j8KSwRKWItKF/9U7grcrCuBcPSgRL6imyjEsKtkeiDtDRcp9 Uz6/e9npENax/ZYlB4G9+Iq6abhayVPU6+phwRDHJAGdaIn+50kWB//lb1yU7lbz McxPwpJxA0ZHUeb8OK1bVCtwwZGuar5q/fKKqaxZrmcpDGLN2J99CC0c968WD29c zAogW6MBGDFO7k/wUrokQT4OTCtxMewhVQtrpTKWjp6xKae/L9OGKe2Dgv+0ye68 j5W/7oAyhb3sFhGQf6uuUahOyghgLW5N6mjGz3tlQVd8BlhCcz5xVtEFy64UV2y/ dMW+yep3rL3M42RV6EYZ2kGwTrUkiUBEFex1EGb255HsutSKJS9ijvTdE4RTX1RQ YZMEzQXge62LTuogE828uZ2Qowc3zddMPMAvMXUEYpNc9FiIeyt9SuunBkv6KimZ f1ml/RM7eVe8PpZaJd6BhHAiLbbK3/b/g/+wIRz0D351NLdhVLWU2BRicGPeCYaf AWzN4Gj2FgGFKixfSoi+69Zx/EQi7dHQ9KwT9Btuababi2NUFV8= =ayII -----END PGP SIGNATURE----- --vGgW1X5XWziG23Ko--