From 46f2b7e90d6aaad2a052b6cfa9e44221be6def14 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@pgaddict.com>
Date: Mon, 23 Mar 2015 13:55:28 +0100
Subject: [PATCH 06/24] Add column store catalogs

This commit adds two new system catalogs:

pg_cstore_am
------------
- Set of functions implementing the column store ("access method")

pg_cstore
---------
- information about a particular column store (part of a table)
- lists columns that are part of each column store
- references pg_cstore_am

Implementation notes
--------------------

- pg_cstore currently has OIDs, but we should remove them as they are
  not really necessary.  (It's not just a matter of adding the
  BKI_WITHOUT_OIDS token though, because the DROP code currently
  requires it.)

- pg_cstore_am will go away as soon as we can use pg_am for the task.
---
 src/backend/catalog/Makefile               |  2 +-
 src/include/catalog/indexing.h             | 12 ++++++
 src/include/catalog/pg_cstore.h            | 60 ++++++++++++++++++++++++++++++
 src/include/catalog/pg_cstore_am.h         | 53 ++++++++++++++++++++++++++
 src/test/regress/expected/sanity_check.out |  2 +
 5 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 src/include/catalog/pg_cstore.h
 create mode 100644 src/include/catalog/pg_cstore_am.h

diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index 25130ec..bdf4e35 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -41,7 +41,7 @@ POSTGRES_BKI_SRCS = $(addprefix $(top_srcdir)/src/include/catalog/,\
 	pg_foreign_data_wrapper.h pg_foreign_server.h pg_user_mapping.h \
 	pg_foreign_table.h pg_policy.h pg_replication_origin.h \
 	pg_default_acl.h pg_seclabel.h pg_shseclabel.h \
-	pg_collation.h pg_range.h pg_transform.h \
+	pg_collation.h pg_range.h pg_transform.h pg_cstore_am.h pg_cstore.h \
 	toasting.h indexing.h \
     )
 
diff --git a/src/include/catalog/indexing.h b/src/include/catalog/indexing.h
index c38958d..ec6a5a2 100644
--- a/src/include/catalog/indexing.h
+++ b/src/include/catalog/indexing.h
@@ -130,6 +130,18 @@ DECLARE_UNIQUE_INDEX(pg_conversion_name_nsp_index, 2669, on pg_conversion using
 DECLARE_UNIQUE_INDEX(pg_conversion_oid_index, 2670, on pg_conversion using btree(oid oid_ops));
 #define ConversionOidIndexId  2670
 
+DECLARE_UNIQUE_INDEX(pg_cstore_oid_index, 3398, on pg_cstore using btree(oid oid_ops));
+#define CStoreOidIndexId	3398
+DECLARE_INDEX(pg_cstore_cststoreid_index, 3399, on pg_cstore using btree(cststoreid oid_ops));
+#define CStoreStoreOidIndexId  3399
+DECLARE_UNIQUE_INDEX(pg_cstore_cstrelid_cstname_index, 3400, on pg_cstore using btree(cstrelid oid_ops, cstname name_ops));
+#define CStoreCstRelidCstnameIndexId  3400
+
+DECLARE_UNIQUE_INDEX(pg_cstore_am_oid_index, 3394, on pg_cstore_am using btree(oid oid_ops));
+#define CStoreAmOidIndexId	3394
+DECLARE_UNIQUE_INDEX(pg_cstore_am_name_index, 3395, on pg_cstore_am using btree(cstamname name_ops));
+#define CStoreAmNameIndexId  3395
+
 DECLARE_UNIQUE_INDEX(pg_database_datname_index, 2671, on pg_database using btree(datname name_ops));
 #define DatabaseNameIndexId  2671
 DECLARE_UNIQUE_INDEX(pg_database_oid_index, 2672, on pg_database using btree(oid oid_ops));
diff --git a/src/include/catalog/pg_cstore.h b/src/include/catalog/pg_cstore.h
new file mode 100644
index 0000000..4ef8d70
--- /dev/null
+++ b/src/include/catalog/pg_cstore.h
@@ -0,0 +1,60 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_cstore.h
+ *	  definition of column stores - groups of attributes stored in
+ *	  columnar orientation, along with the relation's initial contents.
+ *
+ * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/catalog/pg_cstore.h
+ *
+ * NOTES
+ *		the genbki.pl script reads this file and generates .bki
+ *		information from the DATA() statements.
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_CSTORE_H
+#define PG_CSTORE_H
+
+#include "catalog/genbki.h"
+
+/* ----------------
+ *		pg_cstore definition.  cpp turns this into
+ *		typedef struct FormData_pg_cstore
+ * ----------------
+ */
+#define CStoreRelationId	3397
+
+CATALOG(pg_cstore,3397)
+{
+	NameData	cstname;		/* name of the colstore */
+	Oid			cstrelid;		/* relation containing this cstore */
+	Oid			cststoreid;		/* pg_class OID of the cstore itself */
+	int16		cstnatts;		/* number of attributes in the cstore */
+
+	/* variable-length fields start here, but we allow direct access to cstatts */
+	int2vector	cstatts;		/* column numbers of cols in this store */
+
+} FormData_pg_cstore;
+
+/* ----------------
+ *		Form_pg_cstore corresponds to a pointer to a tuple with
+ *		the format of pg_cstore relation.
+ * ----------------
+ */
+typedef FormData_pg_cstore *Form_pg_cstore;
+
+/* ----------------
+ *		compiler constants for pg_cstore
+ * ----------------
+ */
+#define Natts_pg_cstore					5
+#define Anum_pg_cstore_cstname			1
+#define Anum_pg_cstore_cstrelid			2
+#define Anum_pg_cstore_cststoreid		3
+#define Anum_pg_cstore_cstnatts			4
+#define Anum_pg_cstore_cstatts			5
+
+#endif   /* PG_CSTORE_H */
diff --git a/src/include/catalog/pg_cstore_am.h b/src/include/catalog/pg_cstore_am.h
new file mode 100644
index 0000000..232b0b2
--- /dev/null
+++ b/src/include/catalog/pg_cstore_am.h
@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_cstore_am.h
+ *	  definition of the system "cstore access method" relation
+ *    (pg_cstore_am) along with the relation's initial contents.
+ *
+ *
+ * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/catalog/pg_cstore_am.h
+ *
+ * NOTES
+ *		the genbki.pl script reads this file and generates .bki
+ *		information from the DATA() statements.
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_CSTORE_AM_H
+#define PG_CSTORE_AM_H
+
+#include "catalog/genbki.h"
+
+/* ----------------
+ *		pg_cstore_am definition.  cpp turns this into
+ *		typedef struct FormData_pg_cstore_am
+ * ----------------
+ */
+#define CStoreAmRelationId	3396
+
+CATALOG(pg_cstore_am,3396)
+{
+	NameData	cstamname;		/* column store am name */
+	Oid			cstamhandler;	/* handler function */
+
+} FormData_pg_cstore_am;
+
+/* ----------------
+ *		Form_pg_cstore_am corresponds to a pointer to a tuple with
+ *		the format of pg_cstore_am relation.
+ * ----------------
+ */
+typedef FormData_pg_cstore_am *Form_pg_cstore_am;
+
+/* ----------------
+ *		compiler constants for pg_cstore_am
+ * ----------------
+ */
+#define Natts_pg_cstore_am					2
+#define Anum_pg_cstore_am_cstamname			1
+#define Anum_pg_cstore_am_cstamhandler		2
+
+#endif   /* PG_CSTORE_AM_H */
diff --git a/src/test/regress/expected/sanity_check.out b/src/test/regress/expected/sanity_check.out
index eb0bc88..b05061a 100644
--- a/src/test/regress/expected/sanity_check.out
+++ b/src/test/regress/expected/sanity_check.out
@@ -97,6 +97,8 @@ pg_class|t
 pg_collation|t
 pg_constraint|t
 pg_conversion|t
+pg_cstore|t
+pg_cstore_am|t
 pg_database|t
 pg_db_role_setting|t
 pg_default_acl|t
-- 
2.1.4

