mirror of
https://github.com/postgres/postgres.git
synced 2025-06-04 00:02:37 -04:00
Clean up the messy semantics (not to mention inefficiency) of PageGetTempPage
by splitting it into three functions with better-defined behaviors. Zdenek Kotala
This commit is contained in:
parent
f0dae70431
commit
b4eae023bb
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/gindatapage.c,v 1.11 2008/06/19 00:46:03 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/gindatapage.c,v 1.12 2008/11/03 20:47:48 tgl Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@ -445,7 +445,7 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
|
||||
char *ptr;
|
||||
OffsetNumber separator;
|
||||
ItemPointer bound;
|
||||
Page lpage = GinPageGetCopyPage(BufferGetPage(lbuf));
|
||||
Page lpage = PageGetTempPageCopy(BufferGetPage(lbuf));
|
||||
ItemPointerData oldbound = *GinDataPageGetRightBound(lpage);
|
||||
int sizeofitem = GinSizeOfItem(lpage);
|
||||
OffsetNumber maxoff = GinPageGetOpaque(lpage)->maxoff;
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.17 2008/07/11 21:06:29 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.18 2008/11/03 20:47:48 tgl Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@ -458,7 +458,7 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR
|
||||
leftrightmost = NULL;
|
||||
static ginxlogSplit data;
|
||||
Page page;
|
||||
Page lpage = GinPageGetCopyPage(BufferGetPage(lbuf));
|
||||
Page lpage = PageGetTempPageCopy(BufferGetPage(lbuf));
|
||||
Page rpage = BufferGetPage(rbuf);
|
||||
Size pageSize = PageGetPageSize(lpage);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.17 2008/09/30 10:52:10 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.18 2008/11/03 20:47:48 tgl Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@ -310,21 +310,6 @@ extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *ne
|
||||
return entries;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's analog of PageGetTempPage(), but copies whole page
|
||||
*/
|
||||
Page
|
||||
GinPageGetCopyPage(Page page)
|
||||
{
|
||||
Size pageSize = PageGetPageSize(page);
|
||||
Page tmppage;
|
||||
|
||||
tmppage = (Page) palloc(pageSize);
|
||||
memcpy(tmppage, page, pageSize);
|
||||
|
||||
return tmppage;
|
||||
}
|
||||
|
||||
Datum
|
||||
ginoptions(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.24 2008/10/31 15:04:59 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.25 2008/11/03 20:47:48 tgl Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@ -546,7 +546,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
|
||||
* On first difference we create temporary page in memory
|
||||
* and copies content in to it.
|
||||
*/
|
||||
tmppage = GinPageGetCopyPage(origpage);
|
||||
tmppage = PageGetTempPageCopy(origpage);
|
||||
|
||||
if (newN > 0)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.152 2008/09/30 10:52:10 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.153 2008/11/03 20:47:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -343,7 +343,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
|
||||
* we must create temporary page to operate
|
||||
*/
|
||||
dist->buffer = state->stack->buffer;
|
||||
dist->page = PageGetTempPage(BufferGetPage(dist->buffer), sizeof(GISTPageOpaqueData));
|
||||
dist->page = PageGetTempPageCopySpecial(BufferGetPage(dist->buffer));
|
||||
|
||||
/* clean all flags except F_LEAF */
|
||||
GistPageGetOpaque(dist->page)->flags = (is_leaf) ? F_LEAF : 0;
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.39 2008/10/31 15:04:59 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.40 2008/11/03 20:47:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -144,18 +144,6 @@ gistDeleteSubtree(GistVacuum *gv, BlockNumber blkno)
|
||||
UnlockReleaseBuffer(buffer);
|
||||
}
|
||||
|
||||
static Page
|
||||
GistPageGetCopyPage(Page page)
|
||||
{
|
||||
Size pageSize = PageGetPageSize(page);
|
||||
Page tmppage;
|
||||
|
||||
tmppage = (Page) palloc(pageSize);
|
||||
memcpy(tmppage, page, pageSize);
|
||||
|
||||
return tmppage;
|
||||
}
|
||||
|
||||
static ArrayTuple
|
||||
vacuumSplitPage(GistVacuum *gv, Page tempPage, Buffer buffer, IndexTuple *addon, int curlenaddon)
|
||||
{
|
||||
@ -325,7 +313,7 @@ gistVacuumUpdate(GistVacuum *gv, BlockNumber blkno, bool needunion)
|
||||
addon = (IndexTuple *) palloc(sizeof(IndexTuple) * lenaddon);
|
||||
|
||||
/* get copy of page to work */
|
||||
tempPage = GistPageGetCopyPage(page);
|
||||
tempPage = PageGetTempPageCopy(page);
|
||||
|
||||
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.167 2008/06/11 08:38:56 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.168 2008/11/03 20:47:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -793,7 +793,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
|
||||
|
||||
rbuf = _bt_getbuf(rel, P_NEW, BT_WRITE);
|
||||
origpage = BufferGetPage(buf);
|
||||
leftpage = PageGetTempPage(origpage, sizeof(BTPageOpaqueData));
|
||||
leftpage = PageGetTempPage(origpage);
|
||||
rightpage = BufferGetPage(rbuf);
|
||||
|
||||
_bt_pageinit(leftpage, BufferGetPageSize(buf));
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.80 2008/07/13 21:50:04 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.81 2008/11/03 20:47:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -254,28 +254,59 @@ PageAddItem(Page page,
|
||||
|
||||
/*
|
||||
* PageGetTempPage
|
||||
* Get a temporary page in local memory for special processing
|
||||
* Get a temporary page in local memory for special processing.
|
||||
* The returned page is not initialized at all; caller must do that.
|
||||
*/
|
||||
Page
|
||||
PageGetTempPage(Page page, Size specialSize)
|
||||
PageGetTempPage(Page page)
|
||||
{
|
||||
Size pageSize;
|
||||
Page temp;
|
||||
|
||||
pageSize = PageGetPageSize(page);
|
||||
temp = (Page) palloc(pageSize);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*
|
||||
* PageGetTempPageCopy
|
||||
* Get a temporary page in local memory for special processing.
|
||||
* The page is initialized by copying the contents of the given page.
|
||||
*/
|
||||
Page
|
||||
PageGetTempPageCopy(Page page)
|
||||
{
|
||||
Size pageSize;
|
||||
Page temp;
|
||||
PageHeader thdr;
|
||||
|
||||
pageSize = PageGetPageSize(page);
|
||||
temp = (Page) palloc(pageSize);
|
||||
thdr = (PageHeader) temp;
|
||||
|
||||
/* copy old page in */
|
||||
memcpy(temp, page, pageSize);
|
||||
|
||||
/* set high, low water marks */
|
||||
thdr->pd_lower = SizeOfPageHeaderData;
|
||||
thdr->pd_upper = pageSize - MAXALIGN(specialSize);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* clear out the middle */
|
||||
MemSet((char *) temp + thdr->pd_lower, 0, thdr->pd_upper - thdr->pd_lower);
|
||||
/*
|
||||
* PageGetTempPageCopySpecial
|
||||
* Get a temporary page in local memory for special processing.
|
||||
* The page is PageInit'd with the same special-space size as the
|
||||
* given page, and the special space is copied from the given page.
|
||||
*/
|
||||
Page
|
||||
PageGetTempPageCopySpecial(Page page)
|
||||
{
|
||||
Size pageSize;
|
||||
Page temp;
|
||||
|
||||
pageSize = PageGetPageSize(page);
|
||||
temp = (Page) palloc(pageSize);
|
||||
|
||||
PageInit(temp, pageSize, PageGetSpecialSize(page));
|
||||
memcpy(PageGetSpecialPointer(temp),
|
||||
PageGetSpecialPointer(page),
|
||||
PageGetSpecialSize(page));
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Copyright (c) 2006-2008, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.25 2008/10/20 13:39:44 teodor Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.26 2008/11/03 20:47:49 tgl Exp $
|
||||
*--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@ -246,7 +246,6 @@ extern int compareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a,
|
||||
extern Datum *extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value,
|
||||
int32 *nentries, bool *needUnique);
|
||||
extern Datum *extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries);
|
||||
extern Page GinPageGetCopyPage(Page page);
|
||||
|
||||
extern Datum gin_index_getattr(GinState *ginstate, IndexTuple tuple);
|
||||
extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple);
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.83 2008/07/14 03:22:32 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.84 2008/11/03 20:47:49 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -362,7 +362,9 @@ extern void PageInit(Page page, Size pageSize, Size specialSize);
|
||||
extern bool PageHeaderIsValid(PageHeader page);
|
||||
extern OffsetNumber PageAddItem(Page page, Item item, Size size,
|
||||
OffsetNumber offsetNumber, bool overwrite, bool is_heap);
|
||||
extern Page PageGetTempPage(Page page, Size specialSize);
|
||||
extern Page PageGetTempPage(Page page);
|
||||
extern Page PageGetTempPageCopy(Page page);
|
||||
extern Page PageGetTempPageCopySpecial(Page page);
|
||||
extern void PageRestoreTempPage(Page tempPage, Page oldPage);
|
||||
extern void PageRepairFragmentation(Page page);
|
||||
extern Size PageGetFreeSpace(Page page);
|
||||
|
Loading…
x
Reference in New Issue
Block a user