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

Commit ee7ac7b

Browse files
committed
Modify XLogInsert API to make callers specify whether pages to be backed
up have the standard layout with unused space between pd_lower and pd_upper. When this is set, XLogInsert will omit the unused space without bothering to scan it to see if it's zero. That saves time in XLogInsert, and also allows reversion of my earlier patch to make PageRepairFragmentation et al explicitly re-zero freed space. Per suggestion by Heikki Linnakangas.
1 parent 4c8495a commit ee7ac7b

File tree

14 files changed

+185
-156
lines changed

14 files changed

+185
-156
lines changed

src/backend/access/heap/heapam.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.192 2005/06/06 17:01:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.193 2005/06/06 20:22:56 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1107,9 +1107,9 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11071107

11081108
xlrec.target.node = relation->rd_node;
11091109
xlrec.target.tid = tup->t_self;
1110-
rdata[0].buffer = InvalidBuffer;
11111110
rdata[0].data = (char *) &xlrec;
11121111
rdata[0].len = SizeOfHeapInsert;
1112+
rdata[0].buffer = InvalidBuffer;
11131113
rdata[0].next = &(rdata[1]);
11141114

11151115
xlhdr.t_natts = tup->t_data->t_natts;
@@ -1121,15 +1121,17 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11211121
* decides to write the whole page to the xlog, we don't need to
11221122
* store xl_heap_header in the xlog.
11231123
*/
1124-
rdata[1].buffer = buffer;
11251124
rdata[1].data = (char *) &xlhdr;
11261125
rdata[1].len = SizeOfHeapHeader;
1126+
rdata[1].buffer = buffer;
1127+
rdata[1].buffer_std = true;
11271128
rdata[1].next = &(rdata[2]);
11281129

1129-
rdata[2].buffer = buffer;
11301130
/* PG73FORMAT: write bitmap [+ padding] [+ oid] + data */
11311131
rdata[2].data = (char *) tup->t_data + offsetof(HeapTupleHeaderData, t_bits);
11321132
rdata[2].len = tup->t_len - offsetof(HeapTupleHeaderData, t_bits);
1133+
rdata[2].buffer = buffer;
1134+
rdata[2].buffer_std = true;
11331135
rdata[2].next = NULL;
11341136

11351137
/*
@@ -1378,14 +1380,15 @@ heap_delete(Relation relation, ItemPointer tid,
13781380

13791381
xlrec.target.node = relation->rd_node;
13801382
xlrec.target.tid = tp.t_self;
1381-
rdata[0].buffer = InvalidBuffer;
13821383
rdata[0].data = (char *) &xlrec;
13831384
rdata[0].len = SizeOfHeapDelete;
1385+
rdata[0].buffer = InvalidBuffer;
13841386
rdata[0].next = &(rdata[1]);
13851387

1386-
rdata[1].buffer = buffer;
13871388
rdata[1].data = NULL;
13881389
rdata[1].len = 0;
1390+
rdata[1].buffer = buffer;
1391+
rdata[1].buffer_std = true;
13891392
rdata[1].next = NULL;
13901393

13911394
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_DELETE, rdata);
@@ -2226,14 +2229,15 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
22262229
xlrec.target.node = relation->rd_node;
22272230
xlrec.target.tid = tuple->t_self;
22282231
xlrec.shared_lock = (mode == LockTupleShared);
2229-
rdata[0].buffer = InvalidBuffer;
22302232
rdata[0].data = (char *) &xlrec;
22312233
rdata[0].len = SizeOfHeapLock;
2234+
rdata[0].buffer = InvalidBuffer;
22322235
rdata[0].next = &(rdata[1]);
22332236

2234-
rdata[1].buffer = *buffer;
22352237
rdata[1].data = NULL;
22362238
rdata[1].len = 0;
2239+
rdata[1].buffer = *buffer;
2240+
rdata[1].buffer_std = true;
22372241
rdata[1].next = NULL;
22382242

22392243
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_LOCK, rdata);
@@ -2330,17 +2334,16 @@ log_heap_clean(Relation reln, Buffer buffer, OffsetNumber *unused, int uncnt)
23302334
xlrec.node = reln->rd_node;
23312335
xlrec.block = BufferGetBlockNumber(buffer);
23322336

2333-
rdata[0].buffer = InvalidBuffer;
23342337
rdata[0].data = (char *) &xlrec;
23352338
rdata[0].len = SizeOfHeapClean;
2339+
rdata[0].buffer = InvalidBuffer;
23362340
rdata[0].next = &(rdata[1]);
23372341

23382342
/*
23392343
* The unused-offsets array is not actually in the buffer, but pretend
23402344
* that it is. When XLogInsert stores the whole buffer, the offsets
23412345
* array need not be stored too.
23422346
*/
2343-
rdata[1].buffer = buffer;
23442347
if (uncnt > 0)
23452348
{
23462349
rdata[1].data = (char *) unused;
@@ -2351,6 +2354,8 @@ log_heap_clean(Relation reln, Buffer buffer, OffsetNumber *unused, int uncnt)
23512354
rdata[1].data = NULL;
23522355
rdata[1].len = 0;
23532356
}
2357+
rdata[1].buffer = buffer;
2358+
rdata[1].buffer_std = true;
23542359
rdata[1].next = NULL;
23552360

23562361
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_CLEAN, rdata);
@@ -2388,14 +2393,15 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
23882393
xlrec.target.node = reln->rd_node;
23892394
xlrec.target.tid = from;
23902395
xlrec.newtid = newtup->t_self;
2391-
rdata[0].buffer = InvalidBuffer;
23922396
rdata[0].data = (char *) &xlrec;
23932397
rdata[0].len = SizeOfHeapUpdate;
2398+
rdata[0].buffer = InvalidBuffer;
23942399
rdata[0].next = &(rdata[1]);
23952400

2396-
rdata[1].buffer = oldbuf;
23972401
rdata[1].data = NULL;
23982402
rdata[1].len = 0;
2403+
rdata[1].buffer = oldbuf;
2404+
rdata[1].buffer_std = true;
23992405
rdata[1].next = &(rdata[2]);
24002406

24012407
xlhdr.hdr.t_natts = newtup->t_data->t_natts;
@@ -2420,15 +2426,17 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
24202426
* As with insert records, we need not store the rdata[2] segment if
24212427
* we decide to store the whole buffer instead.
24222428
*/
2423-
rdata[2].buffer = newbuf;
24242429
rdata[2].data = (char *) &xlhdr;
24252430
rdata[2].len = hsize;
2431+
rdata[2].buffer = newbuf;
2432+
rdata[2].buffer_std = true;
24262433
rdata[2].next = &(rdata[3]);
24272434

2428-
rdata[3].buffer = newbuf;
24292435
/* PG73FORMAT: write bitmap [+ padding] [+ oid] + data */
24302436
rdata[3].data = (char *) newtup->t_data + offsetof(HeapTupleHeaderData, t_bits);
24312437
rdata[3].len = newtup->t_len - offsetof(HeapTupleHeaderData, t_bits);
2438+
rdata[3].buffer = newbuf;
2439+
rdata[3].buffer_std = true;
24322440
rdata[3].next = NULL;
24332441

24342442
/* If new tuple is the single and first tuple on page... */

src/backend/access/nbtree/nbtinsert.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.120 2005/03/21 01:23:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.121 2005/06/06 20:22:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -564,9 +564,9 @@ _bt_insertonpg(Relation rel,
564564
xlrec.target.node = rel->rd_node;
565565
ItemPointerSet(&(xlrec.target.tid), itup_blkno, itup_off);
566566

567-
rdata[0].buffer = InvalidBuffer;
568567
rdata[0].data = (char *) &xlrec;
569568
rdata[0].len = SizeOfBtreeInsert;
569+
rdata[0].buffer = InvalidBuffer;
570570
rdata[0].next = nextrdata = &(rdata[1]);
571571

572572
if (BufferIsValid(metabuf))
@@ -576,9 +576,9 @@ _bt_insertonpg(Relation rel,
576576
xlmeta.fastroot = metad->btm_fastroot;
577577
xlmeta.fastlevel = metad->btm_fastlevel;
578578

579-
nextrdata->buffer = InvalidBuffer;
580579
nextrdata->data = (char *) &xlmeta;
581580
nextrdata->len = sizeof(xl_btree_metadata);
581+
nextrdata->buffer = InvalidBuffer;
582582
nextrdata->next = nextrdata + 1;
583583
nextrdata++;
584584
xlinfo = XLOG_BTREE_INSERT_META;
@@ -603,6 +603,7 @@ _bt_insertonpg(Relation rel,
603603
(sizeof(BTItemData) - sizeof(IndexTupleData));
604604
}
605605
nextrdata->buffer = buf;
606+
nextrdata->buffer_std = true;
606607
nextrdata->next = NULL;
607608

608609
recptr = XLogInsert(RM_BTREE_ID, xlinfo, rdata);
@@ -853,28 +854,29 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
853854
xlrec.leftlen = ((PageHeader) leftpage)->pd_special -
854855
((PageHeader) leftpage)->pd_upper;
855856

856-
rdata[0].buffer = InvalidBuffer;
857857
rdata[0].data = (char *) &xlrec;
858858
rdata[0].len = SizeOfBtreeSplit;
859+
rdata[0].buffer = InvalidBuffer;
859860
rdata[0].next = &(rdata[1]);
860861

861-
rdata[1].buffer = InvalidBuffer;
862862
rdata[1].data = (char *) leftpage + ((PageHeader) leftpage)->pd_upper;
863863
rdata[1].len = xlrec.leftlen;
864+
rdata[1].buffer = InvalidBuffer;
864865
rdata[1].next = &(rdata[2]);
865866

866-
rdata[2].buffer = InvalidBuffer;
867867
rdata[2].data = (char *) rightpage + ((PageHeader) rightpage)->pd_upper;
868868
rdata[2].len = ((PageHeader) rightpage)->pd_special -
869869
((PageHeader) rightpage)->pd_upper;
870+
rdata[2].buffer = InvalidBuffer;
870871
rdata[2].next = NULL;
871872

872873
if (!P_RIGHTMOST(ropaque))
873874
{
874875
rdata[2].next = &(rdata[3]);
875-
rdata[3].buffer = sbuf;
876876
rdata[3].data = NULL;
877877
rdata[3].len = 0;
878+
rdata[3].buffer = sbuf;
879+
rdata[3].buffer_std = true;
878880
rdata[3].next = NULL;
879881
}
880882

@@ -1464,19 +1466,19 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
14641466
xlrec.rootblk = rootblknum;
14651467
xlrec.level = metad->btm_level;
14661468

1467-
rdata[0].buffer = InvalidBuffer;
14681469
rdata[0].data = (char *) &xlrec;
14691470
rdata[0].len = SizeOfBtreeNewroot;
1471+
rdata[0].buffer = InvalidBuffer;
14701472
rdata[0].next = &(rdata[1]);
14711473

14721474
/*
14731475
* Direct access to page is not good but faster - we should
14741476
* implement some new func in page API.
14751477
*/
1476-
rdata[1].buffer = InvalidBuffer;
14771478
rdata[1].data = (char *) rootpage + ((PageHeader) rootpage)->pd_upper;
14781479
rdata[1].len = ((PageHeader) rootpage)->pd_special -
14791480
((PageHeader) rootpage)->pd_upper;
1481+
rdata[1].buffer = InvalidBuffer;
14801482
rdata[1].next = NULL;
14811483

14821484
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, rdata);

src/backend/access/nbtree/nbtpage.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.85 2005/06/02 05:55:28 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.86 2005/06/06 20:22:57 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -74,9 +74,9 @@ _bt_metapinit(Relation rel)
7474
xlrec.meta.fastroot = metad->btm_fastroot;
7575
xlrec.meta.fastlevel = metad->btm_fastlevel;
7676

77-
rdata[0].buffer = InvalidBuffer;
7877
rdata[0].data = (char *) &xlrec;
7978
rdata[0].len = SizeOfBtreeNewmeta;
79+
rdata[0].buffer = InvalidBuffer;
8080
rdata[0].next = NULL;
8181

8282
recptr = XLogInsert(RM_BTREE_ID,
@@ -248,9 +248,9 @@ _bt_getroot(Relation rel, int access)
248248
xlrec.rootblk = rootblkno;
249249
xlrec.level = 0;
250250

251-
rdata.buffer = InvalidBuffer;
252251
rdata.data = (char *) &xlrec;
253252
rdata.len = SizeOfBtreeNewroot;
253+
rdata.buffer = InvalidBuffer;
254254
rdata.next = NULL;
255255

256256
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, &rdata);
@@ -666,17 +666,16 @@ _bt_delitems(Relation rel, Buffer buf,
666666
xlrec.node = rel->rd_node;
667667
xlrec.block = BufferGetBlockNumber(buf);
668668

669-
rdata[0].buffer = InvalidBuffer;
670669
rdata[0].data = (char *) &xlrec;
671670
rdata[0].len = SizeOfBtreeDelete;
671+
rdata[0].buffer = InvalidBuffer;
672672
rdata[0].next = &(rdata[1]);
673673

674674
/*
675675
* The target-offsets array is not in the buffer, but pretend that
676676
* it is. When XLogInsert stores the whole buffer, the offsets
677677
* array need not be stored too.
678678
*/
679-
rdata[1].buffer = buf;
680679
if (nitems > 0)
681680
{
682681
rdata[1].data = (char *) itemnos;
@@ -687,6 +686,8 @@ _bt_delitems(Relation rel, Buffer buf,
687686
rdata[1].data = NULL;
688687
rdata[1].len = 0;
689688
}
689+
rdata[1].buffer = buf;
690+
rdata[1].buffer_std = true;
690691
rdata[1].next = NULL;
691692

692693
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE, rdata);
@@ -1038,9 +1039,9 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
10381039
xlrec.leftblk = leftsib;
10391040
xlrec.rightblk = rightsib;
10401041

1041-
rdata[0].buffer = InvalidBuffer;
10421042
rdata[0].data = (char *) &xlrec;
10431043
rdata[0].len = SizeOfBtreeDeletePage;
1044+
rdata[0].buffer = InvalidBuffer;
10441045
rdata[0].next = nextrdata = &(rdata[1]);
10451046

10461047
if (BufferIsValid(metabuf))
@@ -1050,34 +1051,37 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
10501051
xlmeta.fastroot = metad->btm_fastroot;
10511052
xlmeta.fastlevel = metad->btm_fastlevel;
10521053

1053-
nextrdata->buffer = InvalidBuffer;
10541054
nextrdata->data = (char *) &xlmeta;
10551055
nextrdata->len = sizeof(xl_btree_metadata);
1056+
nextrdata->buffer = InvalidBuffer;
10561057
nextrdata->next = nextrdata + 1;
10571058
nextrdata++;
10581059
xlinfo = XLOG_BTREE_DELETE_PAGE_META;
10591060
}
10601061
else
10611062
xlinfo = XLOG_BTREE_DELETE_PAGE;
10621063

1063-
nextrdata->buffer = pbuf;
10641064
nextrdata->data = NULL;
10651065
nextrdata->len = 0;
10661066
nextrdata->next = nextrdata + 1;
1067+
nextrdata->buffer = pbuf;
1068+
nextrdata->buffer_std = true;
10671069
nextrdata++;
10681070

1069-
nextrdata->buffer = rbuf;
10701071
nextrdata->data = NULL;
10711072
nextrdata->len = 0;
1073+
nextrdata->buffer = rbuf;
1074+
nextrdata->buffer_std = true;
10721075
nextrdata->next = NULL;
10731076

10741077
if (BufferIsValid(lbuf))
10751078
{
10761079
nextrdata->next = nextrdata + 1;
10771080
nextrdata++;
1078-
nextrdata->buffer = lbuf;
10791081
nextrdata->data = NULL;
10801082
nextrdata->len = 0;
1083+
nextrdata->buffer = lbuf;
1084+
nextrdata->buffer_std = true;
10811085
nextrdata->next = NULL;
10821086
}
10831087

src/backend/access/nbtree/nbtsort.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* Portions Copyright (c) 1994, Regents of the University of California
5757
*
5858
* IDENTIFICATION
59-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.90 2004/12/31 21:59:22 pgsql Exp $
59+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.91 2005/06/06 20:22:57 tgl Exp $
6060
*
6161
*-------------------------------------------------------------------------
6262
*/
@@ -287,14 +287,14 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
287287
xlrec.node = wstate->index->rd_node;
288288
xlrec.blkno = blkno;
289289

290-
rdata[0].buffer = InvalidBuffer;
291290
rdata[0].data = (char *) &xlrec;
292291
rdata[0].len = SizeOfHeapNewpage;
292+
rdata[0].buffer = InvalidBuffer;
293293
rdata[0].next = &(rdata[1]);
294294

295-
rdata[1].buffer = InvalidBuffer;
296295
rdata[1].data = (char *) page;
297296
rdata[1].len = BLCKSZ;
297+
rdata[1].buffer = InvalidBuffer;
298298
rdata[1].next = NULL;
299299

300300
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_NEWPAGE, rdata);

src/backend/access/transam/clog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
2525
* Portions Copyright (c) 1994, Regents of the University of California
2626
*
27-
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.29 2005/06/06 17:01:22 tgl Exp $
27+
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.30 2005/06/06 20:22:57 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -379,9 +379,9 @@ WriteZeroPageXlogRec(int pageno)
379379
{
380380
XLogRecData rdata;
381381

382-
rdata.buffer = InvalidBuffer;
383382
rdata.data = (char *) (&pageno);
384383
rdata.len = sizeof(int);
384+
rdata.buffer = InvalidBuffer;
385385
rdata.next = NULL;
386386
(void) XLogInsert(RM_CLOG_ID, CLOG_ZEROPAGE | XLOG_NO_TRAN, &rdata);
387387
}

0 commit comments

Comments
 (0)