88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.148 2002/09/04 20:31:09 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.149 2002/09/26 22:46:29 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -1185,10 +1185,14 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11851185rdata [0 ].len = SizeOfHeapInsert ;
11861186rdata [0 ].next = & (rdata [1 ]);
11871187
1188- xlhdr .t_oid = HeapTupleGetOid (tup );
11891188xlhdr .t_natts = tup -> t_data -> t_natts ;
1189+ xlhdr .t_infomask = tup -> t_data -> t_infomask ;
11901190xlhdr .t_hoff = tup -> t_data -> t_hoff ;
1191- xlhdr .mask = tup -> t_data -> t_infomask ;
1191+ /*
1192+ * note we mark rdata[1] as belonging to buffer; if XLogInsert
1193+ * decides to write the whole page to the xlog, we don't need to
1194+ * store xl_heap_header in the xlog.
1195+ */
11921196rdata [1 ].buffer = buffer ;
11931197rdata [1 ].data = (char * )& xlhdr ;
11941198rdata [1 ].len = SizeOfHeapHeader ;
@@ -1200,7 +1204,11 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
12001204rdata [2 ].len = tup -> t_len - offsetof(HeapTupleHeaderData ,t_bits );
12011205rdata [2 ].next = NULL ;
12021206
1203- /* If this is the single and first tuple on page... */
1207+ /*
1208+ * If this is the single and first tuple on page, we can reinit the
1209+ * page instead of restoring the whole thing. Set flag, and hide
1210+ * buffer references from XLogInsert.
1211+ */
12041212if (ItemPointerGetOffsetNumber (& (tup -> t_self ))== FirstOffsetNumber &&
12051213PageGetMaxOffsetNumber (page )== FirstOffsetNumber )
12061214{
@@ -2041,11 +2049,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
20412049rdata [1 ].len = 0 ;
20422050rdata [1 ].next = & (rdata [2 ]);
20432051
2044- xlhdr .hdr .t_oid = HeapTupleGetOid (newtup );
20452052xlhdr .hdr .t_natts = newtup -> t_data -> t_natts ;
2053+ xlhdr .hdr .t_infomask = newtup -> t_data -> t_infomask ;
20462054xlhdr .hdr .t_hoff = newtup -> t_data -> t_hoff ;
2047- xlhdr .hdr .mask = newtup -> t_data -> t_infomask ;
2048- if (move )/* remember xmin & xmax */
2055+ if (move )/* remember xmax & xmin */
20492056{
20502057TransactionId xid [2 ];/* xmax, xmin */
20512058
@@ -2060,6 +2067,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
206020672 * sizeof (TransactionId ));
20612068hsize += 2 * sizeof (TransactionId );
20622069}
2070+ /*
2071+ * As with insert records, we need not store the rdata[2] segment
2072+ * if we decide to store the whole buffer instead.
2073+ */
20632074rdata [2 ].buffer = newbuf ;
20642075rdata [2 ].data = (char * )& xlhdr ;
20652076rdata [2 ].len = hsize ;
@@ -2276,18 +2287,16 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22762287htup = & tbuf .hdr ;
22772288MemSet ((char * )htup ,0 ,sizeof (HeapTupleHeaderData ));
22782289/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
2279- memcpy ((char * )& tbuf + offsetof(HeapTupleHeaderData ,t_bits ),
2290+ memcpy ((char * )htup + offsetof(HeapTupleHeaderData ,t_bits ),
22802291 (char * )xlrec + SizeOfHeapInsert + SizeOfHeapHeader ,
22812292newlen );
22822293newlen += offsetof(HeapTupleHeaderData ,t_bits );
22832294htup -> t_natts = xlhdr .t_natts ;
2295+ htup -> t_infomask = xlhdr .t_infomask ;
22842296htup -> t_hoff = xlhdr .t_hoff ;
2285- htup -> t_infomask = HEAP_XMAX_INVALID |xlhdr .mask ;
22862297HeapTupleHeaderSetXmin (htup ,record -> xl_xid );
22872298HeapTupleHeaderSetCmin (htup ,FirstCommandId );
22882299htup -> t_ctid = xlrec -> target .tid ;
2289- if (reln -> rd_rel -> relhasoids )
2290- HeapTupleHeaderSetOid (htup ,xlhdr .t_oid );
22912300
22922301offnum = PageAddItem (page , (Item )htup ,newlen ,offnum ,
22932302LP_USED |OverwritePageMode );
@@ -2454,34 +2463,27 @@ newsame:;
24542463htup = & tbuf .hdr ;
24552464MemSet ((char * )htup ,0 ,sizeof (HeapTupleHeaderData ));
24562465/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
2457- memcpy ((char * )& tbuf + offsetof(HeapTupleHeaderData ,t_bits ),
2466+ memcpy ((char * )htup + offsetof(HeapTupleHeaderData ,t_bits ),
24582467 (char * )xlrec + hsize ,
24592468newlen );
24602469newlen += offsetof(HeapTupleHeaderData ,t_bits );
24612470htup -> t_natts = xlhdr .t_natts ;
2471+ htup -> t_infomask = xlhdr .t_infomask ;
24622472htup -> t_hoff = xlhdr .t_hoff ;
2463- if (reln -> rd_rel -> relhasoids )
2464- HeapTupleHeaderSetOid (htup ,xlhdr .t_oid );
24652473
24662474if (move )
24672475{
24682476TransactionId xid [2 ];/* xmax, xmin */
24692477
2470- hsize = SizeOfHeapUpdate + SizeOfHeapHeader ;
24712478memcpy ((char * )xid ,
2472- (char * )xlrec + hsize ,2 * sizeof (TransactionId ));
2473- htup -> t_infomask = xlhdr .mask ;
2474- htup -> t_infomask &= ~(HEAP_XMIN_COMMITTED |
2475- HEAP_XMIN_INVALID |
2476- HEAP_MOVED_OFF );
2477- htup -> t_infomask |=HEAP_MOVED_IN ;
2479+ (char * )xlrec + SizeOfHeapUpdate + SizeOfHeapHeader ,
2480+ 2 * sizeof (TransactionId ));
24782481HeapTupleHeaderSetXmin (htup ,xid [1 ]);
24792482HeapTupleHeaderSetXmax (htup ,xid [0 ]);
24802483HeapTupleHeaderSetXvac (htup ,record -> xl_xid );
24812484}
24822485else
24832486{
2484- htup -> t_infomask = HEAP_XMAX_INVALID |xlhdr .mask ;
24852487HeapTupleHeaderSetXmin (htup ,record -> xl_xid );
24862488HeapTupleHeaderSetCmin (htup ,FirstCommandId );
24872489}