*** pgsql/src/backend/access/heap/heapam.c 2008/10/31 19:40:26 1.268 --- pgsql/src/backend/access/heap/heapam.c 2008/11/06 20:51:14 1.269 *************** *** 8,14 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.267 2008/10/31 15:04:59 heikki Exp $ * * * INTERFACE ROUTINES --- 8,14 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.268 2008/10/31 19:40:26 heikki Exp $ * * * INTERFACE ROUTINES *************** UpdateXmaxHintBits(HeapTupleHeader tuple *** 1800,1821 **** /* * heap_insert - insert tuple into a heap * * The new tuple is stamped with current transaction ID and the specified * command ID. * ! * If use_wal is false, the new tuple is not logged in WAL, even for a ! * non-temp relation. Safe usage of this behavior requires that we arrange ! * that all new tuples go into new pages not containing any tuples from other ! * transactions, and that the relation gets fsync'd before commit. ! * (See also heap_sync() comments) * ! * use_fsm is passed directly to RelationGetBufferForTuple, which see for ! * more info. * ! * Note that use_wal and use_fsm will be applied when inserting into the ! * heap's TOAST table, too, if the tuple requires any out-of-line data. * * The return value is the OID assigned to the tuple (either here or by the * caller), or InvalidOid if no OID. The header fields of *tup are updated --- 1800,1851 ---- /* + * GetBulkInsertState - prepare status object for a bulk insert + */ + BulkInsertState + GetBulkInsertState(void) + { + BulkInsertState bistate; + + bistate = (BulkInsertState) palloc(sizeof(BulkInsertStateData)); + bistate->strategy = GetAccessStrategy(BAS_BULKWRITE); + bistate->current_buf = InvalidBuffer; + return bistate; + } + + /* + * FreeBulkInsertState - clean up after finishing a bulk insert + */ + void + FreeBulkInsertState(BulkInsertState bistate) + { + if (bistate->current_buf != InvalidBuffer) + ReleaseBuffer(bistate->current_buf); + FreeAccessStrategy(bistate->strategy); + pfree(bistate); + } + + + /* * heap_insert - insert tuple into a heap * * The new tuple is stamped with current transaction ID and the specified * command ID. * ! * If the HEAP_INSERT_SKIP_WAL option is specified, the new tuple is not ! * logged in WAL, even for a non-temp relation. Safe usage of this behavior ! * requires that we arrange that all new tuples go into new pages not ! * containing any tuples from other transactions, and that the relation gets ! * fsync'd before commit. (See also heap_sync() comments) ! * ! * The HEAP_INSERT_SKIP_FSM option is passed directly to ! * RelationGetBufferForTuple, which see for more info. * ! * Note that these options will be applied when inserting into the heap's ! * TOAST table, too, if the tuple requires any out-of-line data. * ! * The BulkInsertState object (if any; bistate can be NULL for default ! * behavior) is also just passed through to RelationGetBufferForTuple. * * The return value is the OID assigned to the tuple (either here or by the * caller), or InvalidOid if no OID. The header fields of *tup are updated *************** UpdateXmaxHintBits(HeapTupleHeader tuple *** 1825,1831 **** */ Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid, ! bool use_wal, bool use_fsm) { TransactionId xid = GetCurrentTransactionId(); HeapTuple heaptup; --- 1855,1861 ---- */ Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid, ! int options, BulkInsertState bistate) { TransactionId xid = GetCurrentTransactionId(); HeapTuple heaptup; *************** heap_insert(Relation relation, HeapTuple *** 1877,1890 **** heaptup = tup; } else if (HeapTupleHasExternal(tup) || tup->t_len > TOAST_TUPLE_THRESHOLD) ! heaptup = toast_insert_or_update(relation, tup, NULL, ! use_wal, use_fsm); else heaptup = tup; /* Find buffer to insert this tuple into */ buffer = RelationGetBufferForTuple(relation, heaptup->t_len, ! InvalidBuffer, use_fsm); /* NO EREPORT(ERROR) from here till changes are logged */ START_CRIT_SECTION(); --- 1907,1919 ---- heaptup = tup; } else if (HeapTupleHasExternal(tup) || tup->t_len > TOAST_TUPLE_THRESHOLD) ! heaptup = toast_insert_or_update(relation, tup, NULL, options); else heaptup = tup; /* Find buffer to insert this tuple into */ buffer = RelationGetBufferForTuple(relation, heaptup->t_len, ! InvalidBuffer, options, bistate); /* NO EREPORT(ERROR) from here till changes are logged */ START_CRIT_SECTION(); *************** heap_insert(Relation relation, HeapTuple *** 1905,1911 **** MarkBufferDirty(buffer); /* XLOG stuff */ ! if (use_wal && !relation->rd_istemp) { xl_heap_insert xlrec; xl_heap_header xlhdr; --- 1934,1940 ---- MarkBufferDirty(buffer); /* XLOG stuff */ ! if (!(options & HEAP_INSERT_SKIP_WAL) && !relation->rd_istemp) { xl_heap_insert xlrec; xl_heap_header xlhdr; *************** heap_insert(Relation relation, HeapTuple *** 2000,2006 **** Oid simple_heap_insert(Relation relation, HeapTuple tup) { ! return heap_insert(relation, tup, GetCurrentCommandId(true), true, true); } /* --- 2029,2035 ---- Oid simple_heap_insert(Relation relation, HeapTuple tup) { ! return heap_insert(relation, tup, GetCurrentCommandId(true), 0, NULL); } /* *************** l2: *** 2595,2602 **** if (need_toast) { /* Note we always use WAL and FSM during updates */ ! heaptup = toast_insert_or_update(relation, newtup, &oldtup, ! true, true); newtupsize = MAXALIGN(heaptup->t_len); } else --- 2624,2630 ---- if (need_toast) { /* Note we always use WAL and FSM during updates */ ! heaptup = toast_insert_or_update(relation, newtup, &oldtup, 0); newtupsize = MAXALIGN(heaptup->t_len); } else *************** l2: *** 2623,2629 **** { /* Assume there's no chance to put heaptup on same page. */ newbuf = RelationGetBufferForTuple(relation, heaptup->t_len, ! buffer, true); } else { --- 2651,2657 ---- { /* Assume there's no chance to put heaptup on same page. */ newbuf = RelationGetBufferForTuple(relation, heaptup->t_len, ! buffer, 0, NULL); } else { *************** l2: *** 2640,2646 **** */ LockBuffer(buffer, BUFFER_LOCK_UNLOCK); newbuf = RelationGetBufferForTuple(relation, heaptup->t_len, ! buffer, true); } else { --- 2668,2674 ---- */ LockBuffer(buffer, BUFFER_LOCK_UNLOCK); newbuf = RelationGetBufferForTuple(relation, heaptup->t_len, ! buffer, 0, NULL); } else {