pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: don't create storage when unnecessary
Date: Mon, 17 Dec 2018 16:42:50 -0300
Message-ID: <20181217194250.aa3v4hx5e6zc2wzb@alvherre.pgsql> (raw)
In-Reply-To: <20181216204716.jddzijk3fb2dpdk4@alvherre.pgsql>

Rebased over today's conflicting commits.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v3-0001-don-t-create-storage-when-not-necessary.patch (text/x-diff, 4.4K) download diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 4d5b82aaa9..b128959cb7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -324,16 +324,12 @@ heap_create(const char *relname, get_namespace_name(relnamespace), relname), errdetail("System catalog modifications are currently disallowed."))); - /* - * Decide if we need storage or not, and handle a couple other special - * cases for particular relkinds. - */ + /* Handle reltablespace for specific relkinds. */ switch (relkind) { case RELKIND_VIEW: case RELKIND_COMPOSITE_TYPE: case RELKIND_FOREIGN_TABLE: - create_storage = false; /* * Force reltablespace to zero if the relation has no physical @@ -342,17 +338,7 @@ heap_create(const char *relname, reltablespace = InvalidOid; break; - case RELKIND_PARTITIONED_TABLE: - case RELKIND_PARTITIONED_INDEX: - /* - * For partitioned tables and indexes, preserve tablespace so that - * it's used as the tablespace for future partitions. - */ - create_storage = false; - break; - case RELKIND_SEQUENCE: - create_storage = true; /* * Force reltablespace to zero for sequences, since we don't @@ -361,19 +347,21 @@ heap_create(const char *relname, reltablespace = InvalidOid; break; default: - create_storage = true; break; } /* - * Unless otherwise requested, the physical ID (relfilenode) is initially - * the same as the logical ID (OID). When the caller did specify a - * relfilenode, it already exists; do not attempt to create it. + * Decide whether to create storage. If caller passed a valid relfilenode, + * storage is already created, so don't do it here. Also don't create it + * for relkinds without physical storage. */ - if (OidIsValid(relfilenode)) + if (!RELKIND_CAN_HAVE_STORAGE(relkind) || OidIsValid(relfilenode)) create_storage = false; else + { + create_storage = true; relfilenode = relid; + } /* * Never allow a pg_class entry to explicitly specify the database's diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index c3071db1cd..a4c8a9e385 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1253,6 +1253,10 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) static void RelationInitPhysicalAddr(Relation relation) { + /* these relations kinds never have storage */ + if (!RELKIND_CAN_HAVE_STORAGE(relation->rd_rel->relkind)) + 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..393edd33d2 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -450,13 +450,12 @@ 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". + * True if the relation uses the relfilenode map. Note multiple eval + * of argument! */ #define RelationIsMapped(relation) \ - ((relation)->rd_rel->relfilenode == InvalidOid) + (RELKIND_CAN_HAVE_STORAGE((relation)->rd_rel->relkind) && \ + ((relation)->rd_rel->relfilenode == InvalidOid)) /* * RelationOpenSmgr diff --git a/src/test/regress/expected/sanity_check.out b/src/test/regress/expected/sanity_check.out index 009a89fc1a..89537bcfcf 100644 --- a/src/test/regress/expected/sanity_check.out +++ b/src/test/regress/expected/sanity_check.out @@ -224,3 +224,12 @@ SELECT relname, nspname ---------+--------- (0 rows) +-- check that relations without storage don't have relfilenode +SELECT relname, relkind + FROM pg_class + WHERE relkind IN ('v', 'c', 'f', 'p', 'I') + AND relfilenode <> 0; + relname | relkind +---------+--------- +(0 rows) + diff --git a/src/test/regress/sql/sanity_check.sql b/src/test/regress/sql/sanity_check.sql index a2feebc91b..a4ec00309f 100644 --- a/src/test/regress/sql/sanity_check.sql +++ b/src/test/regress/sql/sanity_check.sql @@ -31,3 +31,9 @@ SELECT relname, nspname AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE indrelid = c.oid AND indkey[0] = a.attnum AND indnatts = 1 AND indisunique AND indimmediate); + +-- check that relations without storage don't have relfilenode +SELECT relname, relkind + FROM pg_class + WHERE relkind IN ('v', 'c', 'f', 'p', 'I') + AND relfilenode <> 0;

view thread (11+ messages)  latest in thread

Message-ID: <20181217194250.aa3v4hx5e6zc2wzb@alvherre.pgsql>
Permalink:  ../20181217194250.aa3v4hx5e6zc2wzb@alvherre.pgsql/
Also on:    postgresql.org/message-id/20181217194250.aa3v4hx5e6zc2wzb@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, michael@paquier.xyz
  Subject: Re: don't create storage when unnecessary
  In-Reply-To: <20181217194250.aa3v4hx5e6zc2wzb@alvherre.pgsql>
  References: <20181216204716.jddzijk3fb2dpdk4@alvherre.pgsql> <20181217194250.aa3v4hx5e6zc2wzb@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