From 813b456ea21d4cf57b124bf855ec019c7a8099a7 Mon Sep 17 00:00:00 2001
From: Teodor Sigaev <teodor@sigaev.ru>
Date: Tue, 12 Apr 2016 18:03:01 +0300
Subject: [PATCH] Add page id to bloom index

Added to ensure that bloom index pages can be distinguished from other pages
by pg_filedump. Because there wasn't any public/production versions before,
it doesn't pay attention to any compatibility issues.

Per notice from Tom Lane
---
 contrib/bloom/bloom.h   | 19 +++++++++++++++++--
 contrib/bloom/blutils.c |  1 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index d5284f37253..cbf2eb78927 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -31,8 +31,13 @@
 /* Opaque for bloom pages */
 typedef struct BloomPageOpaqueData
 {
-	OffsetNumber maxoff;
-	uint16		flags;
+	OffsetNumber	maxoff;			/* number of index tuples on page */
+	uint16			flags;			/* see bit definitions below */
+	uint16			unused;			/* placeholder to force maxaligning of size
+									 * of BloomPageOpaqueData and to place
+									 * bloom_page_id exactly at the end of page
+									 */
+	uint16			bloom_page_id;	/* for identification of BLOOM indexes */
 }	BloomPageOpaqueData;
 
 typedef BloomPageOpaqueData *BloomPageOpaque;
@@ -41,6 +46,16 @@ typedef BloomPageOpaqueData *BloomPageOpaque;
 #define BLOOM_META		(1<<0)
 #define BLOOM_DELETED	(2<<0)
 
+/*
+ * The page ID is for the convenience of pg_filedump and similar utilities,
+ * which otherwise would have a hard time telling pages of different index
+ * types apart.  It should be the last 2 bytes on the page.  This is more or
+ * less "free" due to alignment considerations.
+ *
+ * See comments above GinPageOpaqueData.
+ */
+#define BLOOM_PAGE_ID		0xFF83
+
 /* Macros for accessing bloom page structures */
 #define BloomPageGetOpaque(page) ((BloomPageOpaque) PageGetSpecialPointer(page))
 #define BloomPageGetMaxOffset(page) (BloomPageGetOpaque(page)->maxoff)
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index 6c7dc1d07d1..edfdfb934f6 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -359,6 +359,7 @@ BloomInitPage(Page page, uint16 flags)
 	opaque = BloomPageGetOpaque(page);
 	memset(opaque, 0, sizeof(BloomPageOpaqueData));
 	opaque->flags = flags;
+	opaque->bloom_page_id = BLOOM_PAGE_ID;
 }
 
 /*
-- 
GitLab