48 Assert(pageSize == BLCKSZ);
56 p->
pd_upper = pageSize - specialSize;
94 bool header_sane =
false;
95 bool all_zeroes =
false;
130 pagebytes = (
size_t *) page;
131 for (
i = 0;
i < (BLCKSZ /
sizeof(size_t));
i++)
133 if (pagebytes[
i] != 0)
152 errmsg(
"page verification failed, calculated checksum %u but expected %u",
206 bool needshuffle =
false;
217 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
231 if (offsetNumber < limit)
243 if (offsetNumber < limit)
262 offsetNumber < limit;
277 if (offsetNumber >= limit)
286 offsetNumber = limit;
291 if (offsetNumber > limit)
293 elog(
WARNING,
"specified item offset is too large");
300 elog(
WARNING,
"can't put more than MaxHeapTuplesPerPage items in a heap page");
310 if (offsetNumber == limit || needshuffle)
328 memmove(itemId + 1, itemId,
349 memcpy((
char *) page +
upper, item,
size);
390 memcpy(temp, page, pageSize);
429 memcpy((
char *) oldPage, (
char *) tempPage, pageSize);
489 #ifdef USE_ASSERT_CHECKING
499 itemidptr = &itemidbase[
i];
523 itemidptr = &itemidbase[
i];
543 itemidptr = &itemidbase[
i];
548 memmove((
char *) page +
upper,
550 copy_tail - copy_head);
562 copy_head = itemidptr->
itemoff;
569 memmove((
char *) page +
upper,
571 copy_tail - copy_head);
576 char *scratchptr = scratch.
data;
596 itemidptr = &itemidbase[
i];
597 memcpy(scratchptr + itemidptr->
itemoff, page + itemidptr->
itemoff,
604 itemidptr = &itemidbase[0];
621 itemidptr = &itemidbase[
i];
647 itemidptr = &itemidbase[
i];
653 memcpy((
char *) page +
upper,
654 scratchptr + copy_head,
655 copy_tail - copy_head);
667 copy_head = itemidptr->
itemoff;
674 memcpy((
char *) page +
upper,
675 scratchptr + copy_head,
676 copy_tail - copy_head);
714 bool presorted =
true;
724 pd_lower > pd_upper ||
725 pd_upper > pd_special ||
726 pd_special > BLCKSZ ||
730 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
731 pd_lower, pd_upper, pd_special)));
737 itemidptr = itemidbase;
738 nunused = totallen = 0;
739 last_offset = pd_special;
750 if (last_offset > itemidptr->
itemoff)
751 last_offset = itemidptr->
itemoff;
756 itemidptr->
itemoff >= (
int) pd_special))
759 errmsg(
"corrupted line pointer: %u",
777 nstorage = itemidptr - itemidbase;
786 if (totallen > (
Size) (pd_special - pd_lower))
789 errmsg(
"corrupted item lengths: total %u, available space %u",
790 (
unsigned int) totallen, pd_special - pd_lower)));
795 if (finalusedlp != nline)
798 int nunusedend = nline - finalusedlp;
800 Assert(nunused >= nunusedend && nunusedend > 0);
803 nunused -= nunusedend;
838 bool countdone =
false,
883 #ifdef CLOBBER_FREED_MEMORY
884 memset((
char *) page + phdr->
pd_lower, 0x7F,
945 if (space < (
int) (ntups *
sizeof(
ItemIdData)))
1073 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
1077 if ((
int) offnum <= 0 || (
int) offnum > nline)
1078 elog(
ERROR,
"invalid index offnum: %u", offnum);
1081 offidx = offnum - 1;
1088 if (offset < phdr->pd_upper || (offset +
size) > phdr->
pd_special ||
1092 errmsg(
"corrupted line pointer: offset = %u, size = %u",
1093 offset, (
unsigned int)
size)));
1105 ((
char *) &phdr->
pd_linp[offidx + 1] - (
char *) phdr);
1108 memmove((
char *) &(phdr->
pd_linp[offidx]),
1109 (
char *) &(phdr->
pd_linp[offidx + 1]),
1120 addr = (
char *) page + phdr->
pd_upper;
1140 for (
i = 1;
i <= nline;
i++)
1179 bool presorted =
true;
1202 pd_lower > pd_upper ||
1203 pd_upper > pd_special ||
1204 pd_special > BLCKSZ ||
1205 pd_special !=
MAXALIGN(pd_special))
1208 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
1209 pd_lower, pd_upper, pd_special)));
1217 itemidptr = itemidbase;
1221 last_offset = pd_special;
1228 if (offset < pd_upper ||
1229 (offset +
size) > pd_special ||
1233 errmsg(
"corrupted line pointer: offset = %u, size = %u",
1234 offset, (
unsigned int)
size)));
1236 if (nextitm <
nitems && offnum == itemnos[nextitm])
1246 if (last_offset > itemidptr->
itemoff)
1247 last_offset = itemidptr->
itemoff;
1253 newitemids[nused] = *lp;
1261 elog(
ERROR,
"incorrect index offsets supplied");
1263 if (totallen > (
Size) (pd_special - pd_lower))
1266 errmsg(
"corrupted item lengths: total %u, available space %u",
1267 (
unsigned int) totallen, pd_special - pd_lower)));
1314 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
1318 if ((
int) offnum <= 0 || (
int) offnum > nline)
1319 elog(
ERROR,
"invalid index offnum: %u", offnum);
1326 if (offset < phdr->pd_upper || (offset +
size) > phdr->
pd_special ||
1330 errmsg(
"corrupted line pointer: offset = %u, size = %u",
1331 offset, (
unsigned int)
size)));
1341 if ((
int) offnum < nline)
1357 addr = (
char *) page + phdr->
pd_upper;
1375 for (
i = 1;
i <= nline;
i++)
1412 Size alignednewsize;
1426 errmsg(
"corrupted page pointers: lower = %u, upper = %u, special = %u",
1430 if ((
int) offnum <= 0 || (
int) offnum > itemcount)
1431 elog(
ERROR,
"invalid index offnum: %u", offnum);
1438 if (offset < phdr->pd_upper || (offset + oldsize) > phdr->
pd_special ||
1442 errmsg(
"corrupted line pointer: offset = %u, size = %u",
1443 offset, (
unsigned int) oldsize)));
1449 alignednewsize =
MAXALIGN(newsize);
1461 size_diff = oldsize - (int) alignednewsize;
1464 char *addr = (
char *) page + phdr->
pd_upper;
1468 memmove(addr + size_diff, addr, offset - phdr->
pd_upper);
1485 tupid->
lp_off = offset + size_diff;
1489 memcpy(
PageGetItem(page, tupid), newtup, newsize);
1512 static char *pageCopy = NULL;
1516 return (
char *) page;
1524 if (pageCopy == NULL)
1530 memcpy(pageCopy, (
char *) page, BLCKSZ);
struct itemIdCompactData itemIdCompactData
static void compactify_tuples(itemIdCompact itemidbase, int nitems, Page page, bool presorted)
bool ignore_checksum_failure
void PageRestoreTempPage(Page tempPage, Page oldPage)
Size PageGetFreeSpaceForMultipleTuples(Page page, int ntups)
itemIdCompactData * itemIdCompact
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
OffsetNumber PageAddItemExtended(Page page, Item item, Size size, OffsetNumber offsetNumber, int flags)
Size PageGetHeapFreeSpace(Page page)
Page PageGetTempPageCopySpecial(Page page)
bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
char * PageSetChecksumCopy(Page page, BlockNumber blkno)
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
void PageRepairFragmentation(Page page)
void PageTruncateLinePointerArray(Page page)
void PageInit(Page page, Size pageSize, Size specialSize)
Page PageGetTempPageCopy(Page page)
Page PageGetTempPage(Page page)
void PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum)
Size PageGetExactFreeSpace(Page page)
Size PageGetFreeSpace(Page page)
#define PD_VALID_FLAG_BITS
PageHeaderData * PageHeader
static bool PageIsEmpty(Page page)
static void PageSetHasFreeLinePointers(Page page)
static Item PageGetItem(Page page, ItemId itemId)
static Size PageGetPageSize(Page page)
#define SizeOfPageHeaderData
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static bool PageIsNew(Page page)
#define PG_PAGE_LAYOUT_VERSION
static char * PageGetSpecialPointer(Page page)
static void PageClearHasFreeLinePointers(Page page)
static bool PageHasFreeLinePointers(Page page)
static void PageSetPageSizeAndVersion(Page page, Size size, uint8 version)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
static uint16 PageGetSpecialSize(Page page)
#define Assert(condition)
#define MemSet(start, val, len)
uint16 pg_checksum_page(char *page, BlockNumber blkno)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define MaxHeapTuplesPerPage
if(TABLE==NULL||TABLE_index==NULL)
#define ItemIdGetLength(itemId)
#define ItemIdGetOffset(itemId)
struct ItemIdData ItemIdData
#define ItemIdSetNormal(itemId, off, len)
#define ItemIdIsUsed(itemId)
#define ItemIdSetUnused(itemId)
#define ItemIdHasStorage(itemId)
#define MaxIndexTuplesPerPage
void * MemoryContextAllocAligned(MemoryContext context, Size size, Size alignto, int flags)
void pfree(void *pointer)
MemoryContext TopMemoryContext
#define VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
#define InvalidOffsetNumber
#define OffsetNumberIsValid(offsetNumber)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static bool checksum_failure
#define ERRCODE_DATA_CORRUPTED
void pgstat_report_checksum_failure(void)
static pg_noinline void Size size
bool DataChecksumsEnabled(void)