pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Subject: don't create storage when unnecessary
Date: Thu, 6 Dec 2018 18:55:52 -0300
Message-ID: <20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql> (raw)

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

Attachments:

  [text/x-diff] 0001-don-t-create-storage-when-not-necessary.patch (2.4K, ../20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql/2-0001-don-t-create-storage-when-not-necessary.patch)
  download | inline diff:
From 25d80040ffe2fa4fa173b4db7a6e91461542fef3 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
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

view thread (11+ messages)  latest in thread

Message-ID: <20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql>
Permalink:  ../20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql/
Also on:    postgresql.org/message-id/20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: don't create storage when unnecessary
  In-Reply-To: <20181206215552.fm2ypuxq6nhpwjuc@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox