Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6889303

Browse files
committed
Redefine the lp_flags field of item pointers as having four states, rather
than two independent bits (one of which was never used in heap pages anyway, or at least hadn't been in a very long time). This gives us flexibility to add the HOT notions of redirected and dead item pointers without requiring anything so klugy as magic values of lp_off and lp_len. The state values are chosen so that for the states currently in use (pre-HOT) there is no change in the physical representation.
1 parent eb0a773 commit 6889303

31 files changed

+278
-185
lines changed

contrib/pageinspect/btreefuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
140140

141141
item_size += IndexTupleSize(itup);
142142

143-
if (!ItemIdDeleted(id))
143+
if (!ItemIdIsDead(id))
144144
stat->live_items++;
145145
else
146146
stat->dead_items++;

contrib/pageinspect/heapfuncs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Copyright (c) 2007, PostgreSQL Global Development Group
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/contrib/pageinspect/heapfuncs.c,v 1.1 2007/05/17 19:11:24 momjian Exp $
21+
* $PostgreSQL: pgsql/contrib/pageinspect/heapfuncs.c,v 1.2 2007/09/12 22:10:25 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -156,15 +156,15 @@ heap_page_items(PG_FUNCTION_ARGS)
156156
* could be corrupt in many other ways, but at least we won't
157157
* crash.
158158
*/
159-
if ((lp_len >= sizeof(HeapTupleHeader)) &&
160-
(lp_offset == MAXALIGN(lp_offset)) &&
161-
(lp_offset + lp_len <= raw_page_size) &&
162-
ItemIdIsUsed(id))
159+
if (ItemIdHasStorage(id) &&
160+
lp_len >= sizeof(HeapTupleHeader) &&
161+
lp_offset == MAXALIGN(lp_offset) &&
162+
lp_offset + lp_len <= raw_page_size)
163163
{
164164
HeapTupleHeader tuphdr;
165165
int bits_len;
166166

167-
/* Extract infromation from the tuple header */
167+
/* Extract information from the tuple header */
168168

169169
tuphdr = (HeapTupleHeader) PageGetItem(page, id);
170170

contrib/pgstattuple/pgstattuple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.28 2007/08/26 23:59:50 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.29 2007/09/12 22:10:25 tgl Exp $
33
*
44
* Copyright (c) 2001,2002 Tatsuo Ishii
55
*
@@ -477,7 +477,7 @@ pgstat_index_page(pgstattuple_type * stat, Page page,
477477
{
478478
ItemId itemid = PageGetItemId(page, i);
479479

480-
if (ItemIdDeleted(itemid))
480+
if (ItemIdIsDead(itemid))
481481
{
482482
stat->dead_tuple_count++;
483483
stat->dead_tuple_len += ItemIdGetLength(itemid);

src/backend/access/gin/ginentrypage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.7 2007/06/04 15:56:28 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.8 2007/09/12 22:10:25 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -359,7 +359,7 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd
359359
*prdata = rdata;
360360
data.updateBlkno = entryPreparePage(btree, page, off);
361361

362-
placed = PageAddItem(page, (Item) btree->entry, IndexTupleSize(btree->entry), off, LP_USED);
362+
placed = PageAddItem(page, (Item) btree->entry, IndexTupleSize(btree->entry), off, false);
363363
if (placed != off)
364364
elog(ERROR, "failed to add item to index page in \"%s\"",
365365
RelationGetRelationName(btree->index));
@@ -488,7 +488,7 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR
488488
lsize += MAXALIGN(IndexTupleSize(itup)) + sizeof(ItemIdData);
489489
}
490490

491-
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
491+
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
492492
elog(ERROR, "failed to add item to index page in \"%s\"",
493493
RelationGetRelationName(btree->index));
494494
ptr += MAXALIGN(IndexTupleSize(itup));
@@ -563,11 +563,11 @@ entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
563563
page = BufferGetPage(root);
564564

565565
itup = ginPageGetLinkItup(lbuf);
566-
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
566+
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
567567
elog(ERROR, "failed to add item to index root page");
568568

569569
itup = ginPageGetLinkItup(rbuf);
570-
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
570+
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
571571
elog(ERROR, "failed to add item to index root page");
572572
}
573573

src/backend/access/gin/ginvacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.15 2007/06/05 12:47:49 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.16 2007/09/12 22:10:25 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -544,7 +544,7 @@ ginVacuumEntryPage(GinVacuumState *gvs, Buffer buffer, BlockNumber *roots, uint3
544544
itup = GinFormTuple(&gvs->ginstate, value, GinGetPosting(itup), newN);
545545
PageIndexTupleDelete(tmppage, i);
546546

547-
if (PageAddItem(tmppage, (Item) itup, IndexTupleSize(itup), i, LP_USED) != i)
547+
if (PageAddItem(tmppage, (Item) itup, IndexTupleSize(itup), i, false) != i)
548548
elog(ERROR, "failed to add item to index page in \"%s\"",
549549
RelationGetRelationName(gvs->index));
550550

src/backend/access/gin/ginxlog.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginxlog.c,v 1.7 2007/06/04 15:56:28 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginxlog.c,v 1.8 2007/09/12 22:10:25 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include "postgres.h"
@@ -199,7 +199,7 @@ ginRedoInsert(XLogRecPtr lsn, XLogRecord *record)
199199

200200
itup = (IndexTuple) (XLogRecGetData(record) + sizeof(ginxlogInsert));
201201

202-
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), data->offset, LP_USED) == InvalidOffsetNumber)
202+
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), data->offset, false) == InvalidOffsetNumber)
203203
elog(ERROR, "failed to add item to index page in %u/%u/%u",
204204
data->node.spcNode, data->node.dbNode, data->node.relNode);
205205

@@ -281,15 +281,15 @@ ginRedoSplit(XLogRecPtr lsn, XLogRecord *record)
281281

282282
for (i = 0; i < data->separator; i++)
283283
{
284-
if (PageAddItem(lpage, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
284+
if (PageAddItem(lpage, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
285285
elog(ERROR, "failed to add item to index page in %u/%u/%u",
286286
data->node.spcNode, data->node.dbNode, data->node.relNode);
287287
itup = (IndexTuple) (((char *) itup) + MAXALIGN(IndexTupleSize(itup)));
288288
}
289289

290290
for (i = data->separator; i < data->nitem; i++)
291291
{
292-
if (PageAddItem(rpage, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
292+
if (PageAddItem(rpage, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
293293
elog(ERROR, "failed to add item to index page in %u/%u/%u",
294294
data->node.spcNode, data->node.dbNode, data->node.relNode);
295295
itup = (IndexTuple) (((char *) itup) + MAXALIGN(IndexTupleSize(itup)));
@@ -375,7 +375,7 @@ ginRedoVacuumPage(XLogRecPtr lsn, XLogRecord *record)
375375

376376
for (i = 0; i < data->nitem; i++)
377377
{
378-
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, LP_USED) == InvalidOffsetNumber)
378+
if (PageAddItem(page, (Item) itup, IndexTupleSize(itup), InvalidOffsetNumber, false) == InvalidOffsetNumber)
379379
elog(ERROR, "failed to add item to index page in %u/%u/%u",
380380
data->node.spcNode, data->node.dbNode, data->node.relNode);
381381
itup = (IndexTuple) (((char *) itup) + MAXALIGN(IndexTupleSize(itup)));

src/backend/access/gist/gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.145 2007/01/05 22:19:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.146 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -366,7 +366,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
366366
data = (char *) (ptr->list);
367367
for (i = 0; i < ptr->block.num; i++)
368368
{
369-
if (PageAddItem(ptr->page, (Item) data, IndexTupleSize((IndexTuple) data), i + FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
369+
if (PageAddItem(ptr->page, (Item) data, IndexTupleSize((IndexTuple) data), i + FirstOffsetNumber, false) == InvalidOffsetNumber)
370370
elog(ERROR, "failed to add item to index page in \"%s\"", RelationGetRelationName(state->r));
371371
data += IndexTupleSize((IndexTuple) data);
372372
}

src/backend/access/gist/gistget.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.66 2007/05/27 03:50:38 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.67 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -46,7 +46,7 @@ killtuple(Relation r, GISTScanOpaque so, ItemPointer iptr)
4646
{
4747
/* page unchanged, so all is simple */
4848
offset = ItemPointerGetOffsetNumber(iptr);
49-
PageGetItemId(p, offset)->lp_flags |= LP_DELETE;
49+
ItemIdMarkDead(PageGetItemId(p, offset));
5050
SetBufferCommitInfoNeedsSave(buffer);
5151
LockBuffer(buffer, GIST_UNLOCK);
5252
break;
@@ -61,7 +61,7 @@ killtuple(Relation r, GISTScanOpaque so, ItemPointer iptr)
6161
if (ItemPointerEquals(&(ituple->t_tid), iptr))
6262
{
6363
/* found */
64-
PageGetItemId(p, offset)->lp_flags |= LP_DELETE;
64+
ItemIdMarkDead(PageGetItemId(p, offset));
6565
SetBufferCommitInfoNeedsSave(buffer);
6666
LockBuffer(buffer, GIST_UNLOCK);
6767
if (buffer != so->curbuf)
@@ -289,7 +289,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids,
289289
ItemPointerSet(&(so->curpos),
290290
BufferGetBlockNumber(so->curbuf), n);
291291

292-
if (!(ignore_killed_tuples && ItemIdDeleted(PageGetItemId(p, n))))
292+
if (!(ignore_killed_tuples && ItemIdIsDead(PageGetItemId(p, n))))
293293
{
294294
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
295295
tids[ntids] = scan->xs_ctup.t_self = it->t_tid;

src/backend/access/gist/gistutil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.22 2007/04/09 22:03:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.23 2007/09/12 22:10:25 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include "postgres.h"
@@ -42,7 +42,7 @@ gistfillbuffer(Relation r, Page page, IndexTuple *itup,
4242
for (i = 0; i < len; i++)
4343
{
4444
l = PageAddItem(page, (Item) itup[i], IndexTupleSize(itup[i]),
45-
off, LP_USED);
45+
off, false);
4646
if (l == InvalidOffsetNumber)
4747
elog(ERROR, "failed to add item to index page in \"%s\"",
4848
RelationGetRelationName(r));

src/backend/access/gist/gistvacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.30 2007/05/31 14:03:09 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.31 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -201,7 +201,7 @@ vacuumSplitPage(GistVacuum *gv, Page tempPage, Buffer buffer, IndexTuple *addon,
201201
data = (char *) (ptr->list);
202202
for (i = 0; i < ptr->block.num; i++)
203203
{
204-
if (PageAddItem(ptr->page, (Item) data, IndexTupleSize((IndexTuple) data), i + FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
204+
if (PageAddItem(ptr->page, (Item) data, IndexTupleSize((IndexTuple) data), i + FirstOffsetNumber, false) == InvalidOffsetNumber)
205205
elog(ERROR, "failed to add item to index page in \"%s\"", RelationGetRelationName(gv->index));
206206
data += IndexTupleSize((IndexTuple) data);
207207
}

src/backend/access/hash/hash.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.95 2007/05/30 20:11:51 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.96 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -193,11 +193,11 @@ hashgettuple(PG_FUNCTION_ARGS)
193193
if (scan->kill_prior_tuple)
194194
{
195195
/*
196-
* Yes, so mark it by setting the LP_DELETE bit in the item flags.
196+
* Yes, so mark it by setting the LP_DEAD state in the item flags.
197197
*/
198198
offnum = ItemPointerGetOffsetNumber(&(so->hashso_curpos));
199199
page = BufferGetPage(so->hashso_curbuf);
200-
PageGetItemId(page, offnum)->lp_flags |= LP_DELETE;
200+
ItemIdMarkDead(PageGetItemId(page, offnum));
201201

202202
/*
203203
* Since this can be redone later if needed, it's treated the same
@@ -224,7 +224,7 @@ hashgettuple(PG_FUNCTION_ARGS)
224224
{
225225
offnum = ItemPointerGetOffsetNumber(&(so->hashso_curpos));
226226
page = BufferGetPage(so->hashso_curbuf);
227-
if (!ItemIdDeleted(PageGetItemId(page, offnum)))
227+
if (!ItemIdIsDead(PageGetItemId(page, offnum)))
228228
break;
229229
res = _hash_next(scan, dir);
230230
}
@@ -286,7 +286,7 @@ hashgetmulti(PG_FUNCTION_ARGS)
286286

287287
offnum = ItemPointerGetOffsetNumber(&(so->hashso_curpos));
288288
page = BufferGetPage(so->hashso_curbuf);
289-
if (!ItemIdDeleted(PageGetItemId(page, offnum)))
289+
if (!ItemIdIsDead(PageGetItemId(page, offnum)))
290290
break;
291291
res = _hash_next(scan, ForwardScanDirection);
292292
}

src/backend/access/hash/hashinsert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.45 2007/05/03 16:45:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.46 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -200,7 +200,7 @@ _hash_pgaddtup(Relation rel,
200200
page = BufferGetPage(buf);
201201

202202
itup_off = OffsetNumberNext(PageGetMaxOffsetNumber(page));
203-
if (PageAddItem(page, (Item) itup, itemsize, itup_off, LP_USED)
203+
if (PageAddItem(page, (Item) itup, itemsize, itup_off, false)
204204
== InvalidOffsetNumber)
205205
elog(ERROR, "failed to add index item to \"%s\"",
206206
RelationGetRelationName(rel));

src/backend/access/hash/hashovfl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.58 2007/05/30 20:11:51 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.59 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
* NOTES
1414
* Overflow pages look like ordinary relation pages.
@@ -684,7 +684,7 @@ _hash_squeezebucket(Relation rel,
684684
* we have found room so insert on the "write" page.
685685
*/
686686
woffnum = OffsetNumberNext(PageGetMaxOffsetNumber(wpage));
687-
if (PageAddItem(wpage, (Item) itup, itemsz, woffnum, LP_USED)
687+
if (PageAddItem(wpage, (Item) itup, itemsz, woffnum, false)
688688
== InvalidOffsetNumber)
689689
elog(ERROR, "failed to add index item to \"%s\"",
690690
RelationGetRelationName(rel));

src/backend/access/hash/hashpage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.68 2007/05/30 20:11:51 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.69 2007/09/12 22:10:25 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -830,7 +830,7 @@ _hash_splitbucket(Relation rel,
830830
}
831831

832832
noffnum = OffsetNumberNext(PageGetMaxOffsetNumber(npage));
833-
if (PageAddItem(npage, (Item) itup, itemsz, noffnum, LP_USED)
833+
if (PageAddItem(npage, (Item) itup, itemsz, noffnum, false)
834834
== InvalidOffsetNumber)
835835
elog(ERROR, "failed to add index item to \"%s\"",
836836
RelationGetRelationName(rel));

0 commit comments

Comments
 (0)