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 1fwwZD-0007Pf-6X for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Sep 2018 21:39:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwwZB-00015Z-GR for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Sep 2018 21:39:25 +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 1fwwZA-00015N-Dr for pgsql-hackers@lists.postgresql.org; Mon, 03 Sep 2018 21:39:25 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwwZ6-000072-AA for pgsql-hackers@postgresql.org; Mon, 03 Sep 2018 21:39:23 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5D57421B4F for ; Mon, 3 Sep 2018 17:39:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 03 Sep 2018 17:39:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=tHIDctkrU3GrKfeTKTspf2xFjIfc0 5yU5lsM/J46N5c=; b=jh7X3f2C3YfM9zngjiKrf01CDqXwkrl2E9b0UXB5xfThQ /EoW3KaWPiMo6Ro6GGBJTurW9iAEySAZMMD+sX11owKW7yGq9MAh2elKbPtRuDTT K2+qVp7Uu9NwSfoCPBxM3u2tfTmXu/YIFzJ9bB7pM0QY8VaakdkW1QqRflY0aJLH zHnNBwNXQMccHKb4tUd/tR5a6UawaJYUVd/IV9Vd8GNwUsgzh/ulul78Ye3ifUlR pwp+mQ8s/UHNrP/aHaP4aY/LkoZmwPbLHVdelt1RHPqs/QsxGhefNIqf15nICmEC 8m8ytysO3eVfXOtDSWMo8k2vz8n2dAfg9YMYzWIEA== X-ME-Proxy: X-ME-Sender: Received: from alvin.alvh.no-ip.org (unknown [190.121.29.3]) by mail.messagingengine.com (Postfix) with ESMTPA id A5891E40D1 for ; Mon, 3 Sep 2018 17:39:18 -0400 (EDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 427A27D0; Mon, 3 Sep 2018 18:39:16 -0300 (-03) Date: Mon, 3 Sep 2018 18:39:16 -0300 From: Alvaro Herrera To: Pg Hackers Subject: pointless check in RelationBuildPartitionDesc Message-ID: <20180903213916.hh6wasnrdg6xv2ud@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wytugto5aytronr4" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --wytugto5aytronr4 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit I noticed this strange hack in RelationBuildPartitionDesc: /* * It is possible that the pg_class tuple of a partition has not been * updated yet to set its relpartbound field. The only case where * this happens is when we open the parent relation to check using its * partition descriptor that a new partition's bound does not overlap * some existing partition. */ if (!((Form_pg_class) GETSTRUCT(tuple))->relispartition) { ReleaseSysCache(tuple); continue; } After looking, it seems that this is just self-inflicted pain: for some reason, we store the pg_inherits row for a partition, and immediately afterwards compute and store its partition bound, which requires the above hack. But if we do things in the opposite order, this is no longer needed. I propose to remove it, as in the attached patch. -- Álvaro Herrera Developer, https://www.PostgreSQL.org/ --wytugto5aytronr4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ispartition.patch" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f46af41b56..089e9f1b20 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -773,9 +773,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, InvalidOid, typaddress); - /* Store inheritance information for new rel. */ - StoreCatalogInheritance(relationId, inheritOids, stmt->partbound != NULL); - /* * We must bump the command counter to make the newly-created relation * tuple visible for opening. @@ -869,6 +866,9 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, heap_close(parent, NoLock); } + /* Store inheritance information for new rel. */ + StoreCatalogInheritance(relationId, inheritOids, stmt->partbound != NULL); + /* * Process the partitioning specification (if any) and store the partition * key information into the catalog. diff --git a/src/backend/utils/cache/partcache.c b/src/backend/utils/cache/partcache.c index 115a9fe78f..e3cd65b33a 100644 --- a/src/backend/utils/cache/partcache.c +++ b/src/backend/utils/cache/partcache.c @@ -302,19 +302,6 @@ RelationBuildPartitionDesc(Relation rel) if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for relation %u", inhrelid); - /* - * It is possible that the pg_class tuple of a partition has not been - * updated yet to set its relpartbound field. The only case where - * this happens is when we open the parent relation to check using its - * partition descriptor that a new partition's bound does not overlap - * some existing partition. - */ - if (!((Form_pg_class) GETSTRUCT(tuple))->relispartition) - { - ReleaseSysCache(tuple); - continue; - } - datum = SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound, &isnull); --wytugto5aytronr4--