summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAlvaro Herrera2015-03-10 15:26:34 +0000
committerAlvaro Herrera2015-03-10 15:27:15 +0000
commite491bd2ee34860b14ff18abc5602f9aa5b197a2d (patch)
treeb6b2bde52149169db4b0c666bce203c7d8da1820 /src/include
parent865f14a2d31af23a05bbf2df04c274629c5d5c4d (diff)
Move BRIN page type to page's last two bytes
... which is the usual convention among AMs, so that pg_filedump and similar utilities can tell apart pages of different AMs. It was also the intent of the original code, but I failed to realize that alignment considerations would move the whole thing to the previous-to-last word in the page. The new definition of the associated macro makes surrounding code a bit leaner, too. Per note from Heikki at http://www.postgresql.org/message-id/546A16EF.9070005@vmware.com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/brin_page.h38
-rw-r--r--src/include/access/gin_private.h8
-rw-r--r--src/include/access/spgist_private.h2
3 files changed, 35 insertions, 13 deletions
diff --git a/src/include/access/brin_page.h b/src/include/access/brin_page.h
index 44ce5f6d1a4..6c645b34b24 100644
--- a/src/include/access/brin_page.h
+++ b/src/include/access/brin_page.h
@@ -20,24 +20,44 @@
#include "storage/block.h"
#include "storage/itemptr.h"
+/*
+ * Special area of BRIN pages.
+ *
+ * We define it in this odd way so that it always occupies the last
+ * MAXALIGN-sized element of each page.
+ */
+typedef struct BrinSpecialSpace
+{
+ uint16 vector[MAXALIGN(1) / sizeof(uint16)];
+} BrinSpecialSpace;
+
+/*
+ * Make the page type be the last half-word in the page, for consumption by
+ * pg_filedump and similar utilities. We don't really care much about the
+ * position of the "flags" half-word, but it's simpler to apply a consistent
+ * rule to both.
+ *
+ * See comments above GinPageOpaqueData.
+ */
+#define BrinPageType(page) \
+ (((BrinSpecialSpace *) \
+ PageGetSpecialPointer(page))->vector[MAXALIGN(1) / sizeof(uint16) - 1])
+
+#define BrinPageFlags(page) \
+ (((BrinSpecialSpace *) \
+ PageGetSpecialPointer(page))->vector[MAXALIGN(1) / sizeof(uint16) - 2])
+
/* special space on all BRIN pages stores a "type" identifier */
#define BRIN_PAGETYPE_META 0xF091
#define BRIN_PAGETYPE_REVMAP 0xF092
#define BRIN_PAGETYPE_REGULAR 0xF093
-#define BRIN_PAGE_TYPE(page) \
- (((BrinSpecialSpace *) PageGetSpecialPointer(page))->type)
-#define BRIN_IS_REVMAP_PAGE(page) (BRIN_PAGE_TYPE(page) == BRIN_PAGETYPE_REVMAP)
-#define BRIN_IS_REGULAR_PAGE(page) (BRIN_PAGE_TYPE(page) == BRIN_PAGETYPE_REGULAR)
+#define BRIN_IS_REVMAP_PAGE(page) (BrinPageType(page) == BRIN_PAGETYPE_REVMAP)
+#define BRIN_IS_REGULAR_PAGE(page) (BrinPageType(page) == BRIN_PAGETYPE_REGULAR)
/* flags for BrinSpecialSpace */
#define BRIN_EVACUATE_PAGE (1 << 0)
-typedef struct BrinSpecialSpace
-{
- uint16 flags;
- uint16 type;
-} BrinSpecialSpace;
/* Metapage definitions */
typedef struct BrinMetaPageData
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index c1a2049d08f..c9f20266f86 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -24,10 +24,10 @@
* Note: GIN does not include a page ID word as do the other index types.
* This is OK because the opaque data is only 8 bytes and so can be reliably
* distinguished by size. Revisit this if the size ever increases.
- * Further note: as of 9.2, SP-GiST also uses 8-byte special space. This is
- * still OK, as long as GIN isn't using all of the high-order bits in its
- * flags word, because that way the flags word cannot match the page ID used
- * by SP-GiST.
+ * Further note: as of 9.2, SP-GiST also uses 8-byte special space, as does
+ * BRIN as of 9.5. This is still OK, as long as GIN isn't using all of the
+ * high-order bits in its flags word, because that way the flags word cannot
+ * match the page IDs used by SP-GiST and BRIN.
*/
typedef struct GinPageOpaqueData
{
diff --git a/src/include/access/spgist_private.h b/src/include/access/spgist_private.h
index 0492ef6114b..413f71e7298 100644
--- a/src/include/access/spgist_private.h
+++ b/src/include/access/spgist_private.h
@@ -64,6 +64,8 @@ typedef SpGistPageOpaqueData *SpGistPageOpaque;
* 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 SPGIST_PAGE_ID 0xFF82