mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Avoid allocations in critical sections.
If a palloc in a critical section fails, it becomes a PANIC.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/htup.h"
|
||||
#include "access/itup.h"
|
||||
#include "storage/bufpage.h"
|
||||
|
||||
|
||||
@@ -363,8 +364,6 @@ PageRepairFragmentation(Page page)
|
||||
Offset pd_lower = ((PageHeader) page)->pd_lower;
|
||||
Offset pd_upper = ((PageHeader) page)->pd_upper;
|
||||
Offset pd_special = ((PageHeader) page)->pd_special;
|
||||
itemIdSort itemidbase,
|
||||
itemidptr;
|
||||
ItemId lp;
|
||||
int nline,
|
||||
nstorage,
|
||||
@@ -414,10 +413,11 @@ PageRepairFragmentation(Page page)
|
||||
((PageHeader) page)->pd_upper = pd_special;
|
||||
}
|
||||
else
|
||||
{ /* nstorage != 0 */
|
||||
{
|
||||
/* Need to compact the page the hard way */
|
||||
itemidbase = (itemIdSort) palloc(sizeof(itemIdSortData) * nstorage);
|
||||
itemidptr = itemidbase;
|
||||
itemIdSortData itemidbase[MaxHeapTuplesPerPage];
|
||||
itemIdSort itemidptr = itemidbase;
|
||||
|
||||
totallen = 0;
|
||||
for (i = 0; i < nline; i++)
|
||||
{
|
||||
@@ -462,8 +462,6 @@ PageRepairFragmentation(Page page)
|
||||
}
|
||||
|
||||
((PageHeader) page)->pd_upper = upper;
|
||||
|
||||
pfree(itemidbase);
|
||||
}
|
||||
|
||||
/* Set hint bit for PageAddItem */
|
||||
@@ -712,8 +710,8 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
|
||||
Offset pd_lower = phdr->pd_lower;
|
||||
Offset pd_upper = phdr->pd_upper;
|
||||
Offset pd_special = phdr->pd_special;
|
||||
itemIdSort itemidbase,
|
||||
itemidptr;
|
||||
itemIdSortData itemidbase[MaxIndexTuplesPerPage];
|
||||
itemIdSort itemidptr;
|
||||
ItemId lp;
|
||||
int nline,
|
||||
nused;
|
||||
@@ -725,6 +723,8 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
|
||||
int nextitm;
|
||||
OffsetNumber offnum;
|
||||
|
||||
Assert(nitems < MaxIndexTuplesPerPage);
|
||||
|
||||
/*
|
||||
* If there aren't very many items to delete, then retail
|
||||
* PageIndexTupleDelete is the best way. Delete the items in reverse
|
||||
@@ -759,7 +759,6 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
|
||||
* still validity-checking.
|
||||
*/
|
||||
nline = PageGetMaxOffsetNumber(page);
|
||||
itemidbase = (itemIdSort) palloc(sizeof(itemIdSortData) * nline);
|
||||
itemidptr = itemidbase;
|
||||
totallen = 0;
|
||||
nused = 0;
|
||||
@@ -825,6 +824,4 @@ PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
|
||||
|
||||
phdr->pd_lower = SizeOfPageHeaderData + nused * sizeof(ItemIdData);
|
||||
phdr->pd_upper = upper;
|
||||
|
||||
pfree(itemidbase);
|
||||
}
|
||||
|
Reference in New Issue
Block a user