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 1gV1cn-0004Pl-48 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 21:56:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gV1cl-00045f-JC for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Dec 2018 21:55:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gV1cl-00045X-4V for pgsql-hackers@lists.postgresql.org; Thu, 06 Dec 2018 21:55:59 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gV1ch-0005m6-JI for pgsql-hackers@lists.postgresql.org; Thu, 06 Dec 2018 21:55:57 +0000 Received: by mail-qt1-x844.google.com with SMTP id n21so2335977qtl.6 for ; Thu, 06 Dec 2018 13:55:55 -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=aUj5B0cuEVleFWzK2S6Xp+euvTv8ryB1r9HexTczl9Y=; b=c0+9ynuq/ad2hEpAD1iRI4iP+tGUHcGXX2TIhg7UZIj6ey8XOe5vyxsxeHcelu4LFU zohnMAq72viANwlLWl2wlYckl9tYtiY/Mh1h3sCa2+Xul0VSSvVS0TN5eiq/1d/cX/Gg aZfWscq6ixDd759bwyPZHWjed9Gtiaw8+4AvQQKfAdNHW8JW89z7BUuj3QFhuXhmOop3 SYXe2p9SkximOaN+tCjCKvBKtN1iGiTUdxYUOOnXpylSMYQl3+nfmT4NS+F0zvDMnXa4 G5Y6slv4JY3H+lDN7VKorrV5b6eX4dw+p844y8EUCmi3MwkFCI6y4VH1OHa8yiTkWF61 HoUw== 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=aUj5B0cuEVleFWzK2S6Xp+euvTv8ryB1r9HexTczl9Y=; b=B1jgemC1fZfdbMuba1eLYYkzz3/8V2RRy6Gimuvf6cIvwNd1Nd8TX+3eM/p9SzBNmK qH9M6LPKSPjKiW7kJiOR8Lu25c58HjX0ys1Ncz0dKZu3knKxQZRLuDN3wvV9YhMW8z0b tabr/r6+NSRC9vTu2Ro1PtRm8I467DhpKJxAdwuhwlg7uEoOHMDsmQSz5TQO2DWZZW0e hOHtFHqduwrTzJf0DMhQ5vVKuticC1lzV3l6ZZU2SDr2aAv464nU4OVYciSGIMcZapLy BxAUyZFiKK6RCOJgaWbErcRhiNogHBUPPD9f+yBVSMLfE2EMOCbEqZtW6GjWymEyxuCJ s7mA== X-Gm-Message-State: AA+aEWaXpsuc6VwmZ599xXrkTJwQS+K+0a2d3YQiU10Aw8JhR9MBUtXZ gK5R40GDcfoBIKu0EaKcmaelQYxuDJtNORncrNPZUatLhW8VOpEsdTt2GJVMtj+y1Z1NZ1bNhs7 61EMo4rckY7MTncW1/Kw87nIz8Vd4s1IM+ysQ0vyA4bHiyfct2WBgfZl45UJ8WNMfrjFLZY9wm1 GWKgLy8ykxc/cUfQ== X-Google-Smtp-Source: AFSGD/XNP3Dm+K56XoaOEvkPdGqxcVajZWCp2B8iKcTOd7WIJ8HQ7zjuMfBLNxFgMPhQavWJyZySRw== X-Received: by 2002:aed:2342:: with SMTP id i2mr29764691qtc.341.1544133354500; Thu, 06 Dec 2018 13:55:54 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id p47sm1299611qta.36.2018.12.06.13.55.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Dec 2018 13:55:53 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 2449072F; Thu, 6 Dec 2018 18:55:52 -0300 (-03) Date: Thu, 6 Dec 2018 18:55:52 -0300 From: Alvaro Herrera To: Pg Hackers Subject: don't create storage when unnecessary Message-ID: <20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="a5halhhl2a7qjpqc" 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 --a5halhhl2a7qjpqc Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Some time ago, after partitioned indexes had been pushed, I realized that even though I didn't want them to have relfilenodes, they did. And looking closer I noticed that *a lot* of relation kinds that didn't need relfilenodes, had them anyway. This patch fixes that; if no relfilenode is needed, it's not created. I didn't verify pg_upgrade behavior across this commit. Maybe something needs tweaking there. PS: I think it'd be worth following up with this ... https://postgr.es/m/CAFjFpRcfzs+yst6YBCseD_orEcDNuAr9GUTraZ5GC=AvCYh55Q@mail.gmail.com -- Álvaro Herrera --a5halhhl2a7qjpqc Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-don-t-create-storage-when-not-necessary.patch" From 25d80040ffe2fa4fa173b4db7a6e91461542fef3 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 9 Aug 2018 16:18:08 -0400 Subject: [PATCH] don't create storage when not necessary --- src/backend/catalog/heap.c | 2 +- src/backend/utils/cache/relcache.c | 8 ++++++++ src/include/utils/rel.h | 10 ++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 11debaa780..6f73ff4fcf 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -372,7 +372,7 @@ heap_create(const char *relname, */ if (OidIsValid(relfilenode)) create_storage = false; - else + else if (create_storage) relfilenode = relid; /* diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index c3071db1cd..76a4cc65be 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1253,6 +1253,14 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) static void RelationInitPhysicalAddr(Relation relation) { + /* these relations kinds have no storage */ + if (relation->rd_rel->relkind == RELKIND_VIEW || + relation->rd_rel->relkind == RELKIND_COMPOSITE_TYPE || + relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE || + relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE || + relation->rd_rel->relkind == RELKIND_PARTITIONED_INDEX) + return; + if (relation->rd_rel->reltablespace) relation->rd_node.spcNode = relation->rd_rel->reltablespace; else diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 2217081dcc..6ac40fd84c 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -451,12 +451,14 @@ typedef struct ViewOptions /* * RelationIsMapped * True if the relation uses the relfilenode map. - * - * NB: this is only meaningful for relkinds that have storage, else it - * will misleadingly say "true". */ #define RelationIsMapped(relation) \ - ((relation)->rd_rel->relfilenode == InvalidOid) + (((relation)->rd_rel->relfilenode == InvalidOid) && \ + ((relation)->rd_rel->relkind == RELKIND_RELATION || \ + (relation)->rd_rel->relkind == RELKIND_INDEX || \ + (relation)->rd_rel->relkind == RELKIND_SEQUENCE || \ + (relation)->rd_rel->relkind == RELKIND_TOASTVALUE || \ + (relation)->rd_rel->relkind == RELKIND_MATVIEW)) /* * RelationOpenSmgr -- 2.11.0 --a5halhhl2a7qjpqc--