if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use raw page functions")));
page = get_page_from_raw(raw_page);
if (PageIsNew(page))
PG_RETURN_NULL();
/* verify the special space has the expected size */ if (PageGetSpecialSize(page) != MAXALIGN(sizeof(BrinSpecialSpace)))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input page is not a valid %s page", "BRIN"),
errdetail("Expected special size %d, got %d.",
(int) MAXALIGN(sizeof(BrinSpecialSpace)),
(int) PageGetSpecialSize(page))));
switch (BrinPageType(page))
{ case BRIN_PAGETYPE_META:
type = "meta"; break; case BRIN_PAGETYPE_REVMAP:
type = "revmap"; break; case BRIN_PAGETYPE_REGULAR:
type = "regular"; break; default:
type = psprintf("unknown (%02x)", BrinPageType(page)); break;
}
/* verify the special space has the expected size */ if (PageGetSpecialSize(page) != MAXALIGN(sizeof(BrinSpecialSpace)))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input page is not a valid %s page", "BRIN"),
errdetail("Expected special size %d, got %d.",
(int) MAXALIGN(sizeof(BrinSpecialSpace)),
(int) PageGetSpecialSize(page))));
/* verify the special space says this page is what we want */ if (BrinPageType(page) != type)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("page is not a BRIN page of type \"%s\"", strtype),
errdetail("Expected special type %08x, got %08x.",
type, BrinPageType(page))));
return page;
}
/* Number of output arguments (columns) for brin_page_items() */ #define BRIN_PAGE_ITEMS_V1_12 8
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use raw page functions")));
InitMaterializedSRF(fcinfo, 0);
/* *Version1.12addedanewoutputcolumnfortheemptyrangeflag.Butas *itwasaddedinthemiddle,itmaycausecrasheswithfunction *definitionsfromolderversionsoftheextension. * *Thereisnowaytoreliablyavoidtheproblemscreatedbytheold *functiondefinitionatthispoint,soinsistthattheuserupdatethe *extension.
*/ if (rsinfo->setDesc->natts < BRIN_PAGE_ITEMS_V1_12)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("function has wrong number of declared columns"),
errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version.")));
if (!IS_BRIN(indexRel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
RelationGetRelationName(indexRel), "BRIN")));
bdesc = brin_build_desc(indexRel);
/* minimally verify the page we got */
page = verify_brin_page(raw_page, BRIN_PAGETYPE_REGULAR, "regular");
if (PageIsNew(page))
{
brin_free_desc(bdesc);
index_close(indexRel, AccessShareLock);
PG_RETURN_NULL();
}
/* *Initializeoutputfunctionsforallindexeddatatypes;simplifies *callingthemlater.
*/
columns = palloc(sizeof(brin_column_state *) * RelationGetDescr(indexRel)->natts); for (attno = 1; attno <= bdesc->bd_tupdesc->natts; attno++)
{
Oid output; bool isVarlena;
BrinOpcInfo *opcinfo; int i;
brin_column_state *column;
/* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
tupdesc = BlessTupleDesc(tupdesc);
/* Extract values from the metapage */
meta = (BrinMetaPageData *) PageGetContents(page);
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
values[1] = Int32GetDatum(meta->brinVersion);
values[2] = Int32GetDatum(meta->pagesPerRange);
values[3] = Int64GetDatum(meta->lastRevmapPage);
htup = heap_form_tuple(tupdesc, values, nulls);
PG_RETURN_DATUM(HeapTupleGetDatum(htup));
}
/* *ReturntheTIDarraystoredinaBRINrevmappage
*/
Datum
brin_revmap_data(PG_FUNCTION_ARGS)
{ struct
{
ItemPointerData *tids; int idx;
} *state;
FuncCallContext *fctx;
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use raw page functions")));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.