summaryrefslogtreecommitdiff
path: root/src/backend/storage/page/bufpage.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-04-04 13:12:38 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-04-04 13:32:40 +0300
commit895243d69ba1972157d8d2644efbf87d557abec3 (patch)
treeb348f19bede0cbe2fd12c3f0a9ed08848f0e9586 /src/backend/storage/page/bufpage.c
parent447e23737cc82489258f9b2564fac68cf834188f (diff)
Avoid allocations in critical sections.
If a palloc in a critical section fails, it becomes a PANIC.
Diffstat (limited to 'src/backend/storage/page/bufpage.c')
-rw-r--r--src/backend/storage/page/bufpage.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index 6bd38127105..4f580fa9b5f 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -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);
}