From 35a52a6fe16e2fa761b1df43c096b8af333731ac Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Wed, 9 Sep 2020 11:04:27 -0700 Subject: [PATCH] Use cstore namespace instead of pg_catalog. --- cstore_fdw--1.7.sql | 18 +++++++----------- cstore_metadata_tables.c | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cstore_fdw--1.7.sql b/cstore_fdw--1.7.sql index 726085b17..7a0c9c7b8 100644 --- a/cstore_fdw--1.7.sql +++ b/cstore_fdw--1.7.sql @@ -3,6 +3,8 @@ -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION cstore_fdw" to load this file. \quit +CREATE SCHEMA cstore; + CREATE FUNCTION cstore_fdw_handler() RETURNS fdw_handler AS 'MODULE_PATHNAME' @@ -58,7 +60,7 @@ CREATE EVENT TRIGGER cstore_drop_event ON SQL_DROP EXECUTE PROCEDURE cstore_drop_trigger(); -CREATE TABLE cstore_tables ( +CREATE TABLE cstore.cstore_tables ( relid oid NOT NULL, block_row_count int NOT NULL, version_major bigint NOT NULL, @@ -66,21 +68,17 @@ CREATE TABLE cstore_tables ( PRIMARY KEY (relid) ) WITH (user_catalog_table = true); -ALTER TABLE cstore_tables SET SCHEMA pg_catalog; - -CREATE TABLE cstore_stripes ( +CREATE TABLE cstore.cstore_stripes ( relid oid NOT NULL, stripe bigint NOT NULL, file_offset bigint NOT NULL, skiplist_length bigint NOT NULL, data_length bigint NOT NULL, PRIMARY KEY (relid, stripe), - FOREIGN KEY (relid) REFERENCES cstore_tables(relid) ON DELETE CASCADE INITIALLY DEFERRED + FOREIGN KEY (relid) REFERENCES cstore.cstore_tables(relid) ON DELETE CASCADE INITIALLY DEFERRED ) WITH (user_catalog_table = true); -ALTER TABLE cstore_stripes SET SCHEMA pg_catalog; - -CREATE TABLE cstore_stripe_attr ( +CREATE TABLE cstore.cstore_stripe_attr ( relid oid NOT NULL, stripe bigint NOT NULL, attr int NOT NULL, @@ -88,7 +86,5 @@ CREATE TABLE cstore_stripe_attr ( value_size bigint NOT NULL, skiplist_size bigint NOT NULL, PRIMARY KEY (relid, stripe, attr), - FOREIGN KEY (relid, stripe) REFERENCES cstore_stripes(relid, stripe) ON DELETE CASCADE INITIALLY DEFERRED + FOREIGN KEY (relid, stripe) REFERENCES cstore.cstore_stripes(relid, stripe) ON DELETE CASCADE INITIALLY DEFERRED ) WITH (user_catalog_table = true); - -ALTER TABLE cstore_stripe_attr SET SCHEMA pg_catalog; diff --git a/cstore_metadata_tables.c b/cstore_metadata_tables.c index 5c381a029..39e852c55 100644 --- a/cstore_metadata_tables.c +++ b/cstore_metadata_tables.c @@ -22,6 +22,7 @@ #include "catalog/pg_namespace.h" #include "catalog/pg_collation.h" #include "catalog/pg_type.h" +#include "catalog/namespace.h" #include "commands/defrem.h" #include "commands/trigger.h" #include "executor/executor.h" @@ -45,6 +46,7 @@ static Oid CStoreStripesRelationId(void); static Oid CStoreStripesIndexRelationId(void); static Oid CStoreTablesRelationId(void); static Oid CStoreTablesIndexRelationId(void); +static Oid CStoreNamespaceId(void); static void InsertStripeAttrRow(Oid relid, uint64 stripe, AttrNumber attr, uint64 existsSize, uint64 valuesSize, uint64 skiplistSize); @@ -494,7 +496,7 @@ ReadStripeFooter(Oid relid, uint64 stripe, int relationColumnCount) static Oid CStoreStripeAttrRelationId(void) { - return get_relname_relid("cstore_stripe_attr", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_stripe_attr", CStoreNamespaceId()); } @@ -505,7 +507,7 @@ CStoreStripeAttrRelationId(void) static Oid CStoreStripeAttrIndexRelationId(void) { - return get_relname_relid("cstore_stripe_attr_pkey", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_stripe_attr_pkey", CStoreNamespaceId()); } @@ -516,7 +518,7 @@ CStoreStripeAttrIndexRelationId(void) static Oid CStoreStripesRelationId(void) { - return get_relname_relid("cstore_stripes", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_stripes", CStoreNamespaceId()); } @@ -527,7 +529,7 @@ CStoreStripesRelationId(void) static Oid CStoreStripesIndexRelationId(void) { - return get_relname_relid("cstore_stripes_pkey", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_stripes_pkey", CStoreNamespaceId()); } @@ -538,7 +540,7 @@ CStoreStripesIndexRelationId(void) static Oid CStoreTablesRelationId(void) { - return get_relname_relid("cstore_tables", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_tables", CStoreNamespaceId()); } @@ -549,5 +551,12 @@ CStoreTablesRelationId(void) static Oid CStoreTablesIndexRelationId(void) { - return get_relname_relid("cstore_tables_pkey", PG_CATALOG_NAMESPACE); + return get_relname_relid("cstore_tables_pkey", CStoreNamespaceId()); +} + + +static Oid +CStoreNamespaceId(void) +{ + return get_namespace_oid("cstore", false); }