diff options
Diffstat (limited to 'src/backend/access')
| -rw-r--r-- | src/backend/access/heap/heapam.c | 45 | ||||
| -rw-r--r-- | src/backend/access/heap/tuptoaster.c | 14 |
2 files changed, 47 insertions, 12 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 3913391f6f1..c0f5f2074b1 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.224 2007/01/09 22:00:59 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.225 2007/01/25 02:17:25 momjian Exp $ * * * INTERFACE ROUTINES @@ -28,6 +28,7 @@ * heap_update - replace a tuple in a relation with another tuple * heap_markpos - mark scan position * heap_restrpos - restore position to marked location + * heap_sync - sync heap, for when no WAL has been written * * NOTES * This file contains the heap_ routines which implement @@ -50,6 +51,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "storage/procarray.h" +#include "storage/smgr.h" #include "utils/inval.h" #include "utils/lsyscache.h" #include "utils/relcache.h" @@ -1358,7 +1360,7 @@ heap_get_latest_tid(Relation relation, * that all new tuples go into new pages not containing any tuples from other * transactions, that the relation gets fsync'd before commit, and that the * transaction emits at least one WAL record to ensure RecordTransactionCommit - * will decide to WAL-log the commit. + * will decide to WAL-log the commit. (see heap_sync() comments also) * * use_fsm is passed directly to RelationGetBufferForTuple, which see for * more info. @@ -1418,7 +1420,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid, */ if (HeapTupleHasExternal(tup) || (MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD)) - heaptup = toast_insert_or_update(relation, tup, NULL); + heaptup = toast_insert_or_update(relation, tup, NULL, use_wal); else heaptup = tup; @@ -1536,6 +1538,18 @@ simple_heap_insert(Relation relation, HeapTuple tup) } /* + * fast_heap_insert - insert a tuple with options to improve speed + * + * Currently, this routine allows specifying additional options for speed + * in certain cases, such as WAL-avoiding COPY command + */ +Oid +fast_heap_insert(Relation relation, HeapTuple tup, bool use_wal) +{ + return heap_insert(relation, tup, GetCurrentCommandId(), use_wal, use_wal); +} + +/* * heap_delete - delete a tuple * * NB: do not call this directly unless you are prepared to deal with @@ -2086,11 +2100,11 @@ l2: * * Note: below this point, heaptup is the data we actually intend to * store into the relation; newtup is the caller's original untoasted - * data. + * data. (We always use WAL for toast table updates.) */ if (need_toast) { - heaptup = toast_insert_or_update(relation, newtup, &oldtup); + heaptup = toast_insert_or_update(relation, newtup, &oldtup, true); newtupsize = MAXALIGN(heaptup->t_len); } else @@ -3966,3 +3980,24 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec) else appendStringInfo(buf, "UNKNOWN"); } + +/* ---------------- + * heap_sync - sync a heap, for use when no WAL has been written + * + * ---------------- + */ +void +heap_sync(Relation rel) +{ + if (!rel->rd_istemp) + { + /* + * If we skipped using WAL, and it's not a temp relation, + * we must force the relation down to disk before it's + * safe to commit the transaction. This requires forcing + * out any dirty buffers and then doing a forced fsync. + */ + FlushRelationBuffers(rel); + smgrimmedsync(rel->rd_smgr); + } +} diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index c7d3a439d51..449c57268e1 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.68 2007/01/05 22:19:22 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.69 2007/01/25 02:17:26 momjian Exp $ * * * INTERFACE ROUTINES @@ -42,7 +42,7 @@ #undef TOAST_DEBUG static void toast_delete_datum(Relation rel, Datum value); -static Datum toast_save_datum(Relation rel, Datum value); +static Datum toast_save_datum(Relation rel, Datum value, bool use_wal); static varattrib *toast_fetch_datum(varattrib *attr); static varattrib *toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length); @@ -342,7 +342,7 @@ toast_delete(Relation rel, HeapTuple oldtup) * ---------- */ HeapTuple -toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup) +toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool use_wal) { HeapTuple result_tuple; TupleDesc tupleDesc; @@ -612,7 +612,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup) i = biggest_attno; old_value = toast_values[i]; toast_action[i] = 'p'; - toast_values[i] = toast_save_datum(rel, toast_values[i]); + toast_values[i] = toast_save_datum(rel, toast_values[i], use_wal); if (toast_free[i]) pfree(DatumGetPointer(old_value)); @@ -724,7 +724,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup) i = biggest_attno; old_value = toast_values[i]; toast_action[i] = 'p'; - toast_values[i] = toast_save_datum(rel, toast_values[i]); + toast_values[i] = toast_save_datum(rel, toast_values[i], use_wal); if (toast_free[i]) pfree(DatumGetPointer(old_value)); @@ -972,7 +972,7 @@ toast_compress_datum(Datum value) * ---------- */ static Datum -toast_save_datum(Relation rel, Datum value) +toast_save_datum(Relation rel, Datum value, bool use_wal) { Relation toastrel; Relation toastidx; @@ -1057,7 +1057,7 @@ toast_save_datum(Relation rel, Datum value) if (!HeapTupleIsValid(toasttup)) elog(ERROR, "failed to build TOAST tuple"); - simple_heap_insert(toastrel, toasttup); + fast_heap_insert(toastrel, toasttup, use_wal); /* * Create the index entry. We cheat a little here by not using |
