Header And Logo

PostgreSQL
| The world's most advanced open source database.

heapam.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * heapam.h
00004  *    POSTGRES heap access method definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/access/heapam.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef HEAPAM_H
00015 #define HEAPAM_H
00016 
00017 #include "access/sdir.h"
00018 #include "access/skey.h"
00019 #include "nodes/primnodes.h"
00020 #include "storage/bufpage.h"
00021 #include "storage/lock.h"
00022 #include "utils/relcache.h"
00023 #include "utils/snapshot.h"
00024 
00025 
00026 /* "options" flag bits for heap_insert */
00027 #define HEAP_INSERT_SKIP_WAL    0x0001
00028 #define HEAP_INSERT_SKIP_FSM    0x0002
00029 #define HEAP_INSERT_FROZEN      0x0004
00030 
00031 typedef struct BulkInsertStateData *BulkInsertState;
00032 
00033 /*
00034  * Possible lock modes for a tuple.
00035  */
00036 typedef enum LockTupleMode
00037 {
00038     /* SELECT FOR KEY SHARE */
00039     LockTupleKeyShare,
00040     /* SELECT FOR SHARE */
00041     LockTupleShare,
00042     /* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */
00043     LockTupleNoKeyExclusive,
00044     /* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */
00045     LockTupleExclusive
00046 } LockTupleMode;
00047 
00048 #define MaxLockTupleMode    LockTupleExclusive
00049 
00050 /*
00051  * When heap_update, heap_delete, or heap_lock_tuple fail because the target
00052  * tuple is already outdated, they fill in this struct to provide information
00053  * to the caller about what happened.
00054  * ctid is the target's ctid link: it is the same as the target's TID if the
00055  * target was deleted, or the location of the replacement tuple if the target
00056  * was updated.
00057  * xmax is the outdating transaction's XID.  If the caller wants to visit the
00058  * replacement tuple, it must check that this matches before believing the
00059  * replacement is really a match.
00060  * cmax is the outdating command's CID, but only when the failure code is
00061  * HeapTupleSelfUpdated (i.e., something in the current transaction outdated
00062  * the tuple); otherwise cmax is zero.  (We make this restriction because
00063  * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other
00064  * transactions.)
00065  */
00066 typedef struct HeapUpdateFailureData
00067 {
00068     ItemPointerData     ctid;
00069     TransactionId       xmax;
00070     CommandId           cmax;
00071 } HeapUpdateFailureData;
00072 
00073 
00074 /* ----------------
00075  *      function prototypes for heap access method
00076  *
00077  * heap_create, heap_create_with_catalog, and heap_drop_with_catalog
00078  * are declared in catalog/heap.h
00079  * ----------------
00080  */
00081 
00082 /* in heap/heapam.c */
00083 extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
00084 extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
00085 extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
00086 extern Relation relation_openrv_extended(const RangeVar *relation,
00087                          LOCKMODE lockmode, bool missing_ok);
00088 extern void relation_close(Relation relation, LOCKMODE lockmode);
00089 
00090 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
00091 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
00092 extern Relation heap_openrv_extended(const RangeVar *relation,
00093                      LOCKMODE lockmode, bool missing_ok);
00094 
00095 #define heap_close(r,l)  relation_close(r,l)
00096 
00097 /* struct definition appears in relscan.h */
00098 typedef struct HeapScanDescData *HeapScanDesc;
00099 
00100 /*
00101  * HeapScanIsValid
00102  *      True iff the heap scan is valid.
00103  */
00104 #define HeapScanIsValid(scan) PointerIsValid(scan)
00105 
00106 extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
00107                int nkeys, ScanKey key);
00108 extern HeapScanDesc heap_beginscan_strat(Relation relation, Snapshot snapshot,
00109                      int nkeys, ScanKey key,
00110                      bool allow_strat, bool allow_sync);
00111 extern HeapScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot,
00112                   int nkeys, ScanKey key);
00113 extern void heap_rescan(HeapScanDesc scan, ScanKey key);
00114 extern void heap_endscan(HeapScanDesc scan);
00115 extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
00116 
00117 extern bool heap_fetch(Relation relation, Snapshot snapshot,
00118            HeapTuple tuple, Buffer *userbuf, bool keep_buf,
00119            Relation stats_relation);
00120 extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation,
00121                        Buffer buffer, Snapshot snapshot, HeapTuple heapTuple,
00122                        bool *all_dead, bool first_call);
00123 extern bool heap_hot_search(ItemPointer tid, Relation relation,
00124                 Snapshot snapshot, bool *all_dead);
00125 
00126 extern void heap_get_latest_tid(Relation relation, Snapshot snapshot,
00127                     ItemPointer tid);
00128 extern void setLastTid(const ItemPointer tid);
00129 
00130 extern BulkInsertState GetBulkInsertState(void);
00131 extern void FreeBulkInsertState(BulkInsertState);
00132 
00133 extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid,
00134             int options, BulkInsertState bistate);
00135 extern void heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
00136                   CommandId cid, int options, BulkInsertState bistate);
00137 extern HTSU_Result heap_delete(Relation relation, ItemPointer tid,
00138             CommandId cid, Snapshot crosscheck, bool wait,
00139             HeapUpdateFailureData *hufd);
00140 extern HTSU_Result heap_update(Relation relation, ItemPointer otid,
00141             HeapTuple newtup,
00142             CommandId cid, Snapshot crosscheck, bool wait,
00143             HeapUpdateFailureData *hufd, LockTupleMode *lockmode);
00144 extern HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
00145                 CommandId cid, LockTupleMode mode, bool nowait,
00146                 bool follow_update,
00147                 Buffer *buffer, HeapUpdateFailureData *hufd);
00148 extern void heap_inplace_update(Relation relation, HeapTuple tuple);
00149 extern bool heap_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid,
00150                   TransactionId cutoff_multi);
00151 extern bool heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
00152                         MultiXactId cutoff_multi, Buffer buf);
00153 
00154 extern Oid  simple_heap_insert(Relation relation, HeapTuple tup);
00155 extern void simple_heap_delete(Relation relation, ItemPointer tid);
00156 extern void simple_heap_update(Relation relation, ItemPointer otid,
00157                    HeapTuple tup);
00158 
00159 extern void heap_markpos(HeapScanDesc scan);
00160 extern void heap_restrpos(HeapScanDesc scan);
00161 
00162 extern void heap_sync(Relation relation);
00163 
00164 /* in heap/pruneheap.c */
00165 extern void heap_page_prune_opt(Relation relation, Buffer buffer,
00166                     TransactionId OldestXmin);
00167 extern int heap_page_prune(Relation relation, Buffer buffer,
00168                 TransactionId OldestXmin,
00169                 bool report_stats, TransactionId *latestRemovedXid);
00170 extern void heap_page_prune_execute(Buffer buffer,
00171                         OffsetNumber *redirected, int nredirected,
00172                         OffsetNumber *nowdead, int ndead,
00173                         OffsetNumber *nowunused, int nunused);
00174 extern void heap_get_root_tuples(Page page, OffsetNumber *root_offsets);
00175 
00176 /* in heap/syncscan.c */
00177 extern void ss_report_location(Relation rel, BlockNumber location);
00178 extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks);
00179 extern void SyncScanShmemInit(void);
00180 extern Size SyncScanShmemSize(void);
00181 
00182 #endif   /* HEAPAM_H */