summaryrefslogtreecommitdiff
path: root/contrib/pageinspect/ginfuncs.c
diff options
context:
space:
mode:
authorPavan Deolasee2017-06-14 05:42:18 +0000
committerPavan Deolasee2017-06-14 05:42:18 +0000
commit15dd5274c323fb93e4e3ea9ad2185aaaec10f79c (patch)
tree9dafb4c7f735d9429ea461dc792933af87493c33 /contrib/pageinspect/ginfuncs.c
parentdfbb88e3bbb526dcb204b456b9e5cfd9d10d0d0a (diff)
parentd5cb3bab564e0927ffac7c8729eacf181a12dd40 (diff)
Merge from PG master upto d5cb3bab564e0927ffac7c8729eacf181a12dd40
This is the result of the "git merge remotes/PGSQL/master" upto the said commit point. We have done some basic analysis, fixed compilation problems etc, but bulk of the logical problems in conflict resolution etc will be handled by subsequent commits.
Diffstat (limited to 'contrib/pageinspect/ginfuncs.c')
-rw-r--r--contrib/pageinspect/ginfuncs.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index a2f119b02e..993fc2d9ae 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -2,13 +2,15 @@
* ginfuncs.c
* Functions to investigate the content of GIN indexes
*
- * Copyright (c) 2014-2016, PostgreSQL Global Development Group
+ * Copyright (c) 2014-2017, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/ginfuncs.c
*/
#include "postgres.h"
+#include "pageinspect.h"
+
#include "access/gin.h"
#include "access/gin_private.h"
#include "access/htup_details.h"
@@ -28,11 +30,11 @@ PG_FUNCTION_INFO_V1(gin_metapage_info);
PG_FUNCTION_INFO_V1(gin_page_opaque_info);
PG_FUNCTION_INFO_V1(gin_leafpage_items);
+
Datum
gin_metapage_info(PG_FUNCTION_ARGS)
{
bytea *raw_page = PG_GETARG_BYTEA_P(0);
- int raw_page_size;
TupleDesc tupdesc;
Page page;
GinPageOpaque opaq;
@@ -46,12 +48,7 @@ gin_metapage_info(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use raw page functions"))));
- raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
- if (raw_page_size < BLCKSZ)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);
+ page = get_page_from_raw(raw_page);
opaq = (GinPageOpaque) PageGetSpecialPointer(page);
if (opaq->flags != GIN_META)
@@ -94,13 +91,12 @@ Datum
gin_page_opaque_info(PG_FUNCTION_ARGS)
{
bytea *raw_page = PG_GETARG_BYTEA_P(0);
- int raw_page_size;
TupleDesc tupdesc;
Page page;
GinPageOpaque opaq;
HeapTuple resultTuple;
Datum values[3];
- bool nulls[10];
+ bool nulls[3];
Datum flags[16];
int nflags = 0;
uint16 flagbits;
@@ -110,12 +106,7 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use raw page functions"))));
- raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
- if (raw_page_size < BLCKSZ)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);
+ page = get_page_from_raw(raw_page);
opaq = (GinPageOpaque) PageGetSpecialPointer(page);
@@ -152,9 +143,9 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
memset(nulls, 0, sizeof(nulls));
values[0] = Int64GetDatum(opaq->rightlink);
- values[1] = Int64GetDatum(opaq->maxoff);
- values[2] = PointerGetDatum(
- construct_array(flags, nflags, TEXTOID, -1, false, 'i'));
+ values[1] = Int32GetDatum(opaq->maxoff);
+ values[2] = PointerGetDatum(construct_array(flags, nflags,
+ TEXTOID, -1, false, 'i'));
/* Build and return the result tuple. */
resultTuple = heap_form_tuple(tupdesc, values, nulls);
@@ -173,7 +164,6 @@ Datum
gin_leafpage_items(PG_FUNCTION_ARGS)
{
bytea *raw_page = PG_GETARG_BYTEA_P(0);
- int raw_page_size;
FuncCallContext *fctx;
gin_leafpage_items_state *inter_call_data;
@@ -182,8 +172,6 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use raw page functions"))));
- raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
-
if (SRF_IS_FIRSTCALL())
{
TupleDesc tupdesc;
@@ -191,11 +179,10 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
Page page;
GinPageOpaque opaq;
- if (raw_page_size < BLCKSZ)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("input page too small (%d bytes)", raw_page_size)));
- page = VARDATA(raw_page);
+ fctx = SRF_FIRSTCALL_INIT();
+ mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
+
+ page = get_page_from_raw(raw_page);
if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
ereport(ERROR,
@@ -214,9 +201,6 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
opaq->flags,
(GIN_DATA | GIN_LEAF | GIN_COMPRESSED))));
- fctx = SRF_FIRSTCALL_INIT();
- mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
-
inter_call_data = palloc(sizeof(gin_leafpage_items_state));
/* Build a tuple descriptor for our result type */