OSDN Git Service

Update copyright to 2004.
[pg-rex/syncrep.git] / src / include / access / heapam.h
index db40344..103a9c6 100644 (file)
@@ -4,95 +4,39 @@
  *       POSTGRES heap access method definitions.
  *
  *
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: heapam.h,v 1.59 2000/11/30 18:38:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.91 2004/08/29 04:13:03 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef HEAPAM_H
 #define HEAPAM_H
 
-#include <time.h>
 #include "access/htup.h"
 #include "access/relscan.h"
+#include "access/sdir.h"
 #include "access/tupmacs.h"
 #include "access/xlogutils.h"
+#include "nodes/primnodes.h"
 #include "storage/block.h"
 #include "storage/lmgr.h"
 #include "utils/rel.h"
 #include "utils/tqual.h"
 
-/* ----------------------------------------------------------------
- *                             heap access method statistics
- * ----------------------------------------------------------------
- */
-
-typedef struct HeapAccessStatisticsData
-{
-       time_t          init_global_timestamp;  /* time global statistics started */
-       time_t          local_reset_timestamp;  /* last time local reset was done */
-       time_t          last_request_timestamp; /* last time stats were requested */
-
-       int                     global_open;
-       int                     global_openr;
-       int                     global_close;
-       int                     global_beginscan;
-       int                     global_rescan;
-       int                     global_endscan;
-       int                     global_getnext;
-       int                     global_fetch;
-       int                     global_insert;
-       int                     global_delete;
-       int                     global_replace;
-       int                     global_mark4update;
-       int                     global_markpos;
-       int                     global_restrpos;
-       int                     global_BufferGetRelation;
-       int                     global_RelationIdGetRelation;
-       int                     global_RelationIdGetRelation_Buf;
-       int                     global_RelationNameGetRelation;
-       int                     global_getreldesc;
-       int                     global_heapgettup;
-       int                     global_RelationPutHeapTuple;
-       int                     global_RelationPutLongHeapTuple;
-
-       int                     local_open;
-       int                     local_openr;
-       int                     local_close;
-       int                     local_beginscan;
-       int                     local_rescan;
-       int                     local_endscan;
-       int                     local_getnext;
-       int                     local_fetch;
-       int                     local_insert;
-       int                     local_delete;
-       int                     local_replace;
-       int                     local_mark4update;
-       int                     local_markpos;
-       int                     local_restrpos;
-       int                     local_BufferGetRelation;
-       int                     local_RelationIdGetRelation;
-       int                     local_RelationIdGetRelation_Buf;
-       int                     local_RelationNameGetRelation;
-       int                     local_getreldesc;
-       int                     local_heapgettup;
-       int                     local_RelationPutHeapTuple;
-       int                     local_RelationPutLongHeapTuple;
-} HeapAccessStatisticsData;
-
-typedef HeapAccessStatisticsData *HeapAccessStatistics;
-
-#define IncrHeapAccessStat(x) \
-       (heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
-
 /* ----------------
  *             fastgetattr
  *
- *             This gets called many times, so we macro the cacheable and NULL
- *             lookups, and call noncachegetattr() for the rest.
+ *             Fetch a user attribute's value as a Datum (might be either a
+ *             value, or a pointer into the data area of the tuple).
  *
+ *             This must not be used when a system attribute might be requested.
+ *             Furthermore, the passed attnum MUST be valid.  Use heap_getattr()
+ *             instead, if in doubt.
+ *
+ *             This gets called many times, so we macro the cacheable and NULL
+ *             lookups, and call nocachegetattr() for the rest.
  * ----------------
  */
 
@@ -109,7 +53,7 @@ extern Datum nocachegetattr(HeapTuple tup, int attnum,
        (                                                                                                                               \
                (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?                      \
                (                                                                                                                       \
-                       (Datum) fetchatt(&((tupleDesc)->attrs[(attnum)-1]),             \
+                       fetchatt((tupleDesc)->attrs[(attnum)-1],                                \
                                (char *) (tup)->t_data + (tup)->t_data->t_hoff +        \
                                        (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
                )                                                                                                                       \
@@ -130,73 +74,50 @@ extern Datum nocachegetattr(HeapTuple tup, int attnum,
        )                                                                                                                               \
 )
 
-#else /* defined(DISABLE_COMPLEX_MACRO) */
+#else                                                  /* defined(DISABLE_COMPLEX_MACRO) */
 
-extern Datum
-fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
+extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
                        bool *isnull);
-
-#endif /* defined(DISABLE_COMPLEX_MACRO) */
+#endif   /* defined(DISABLE_COMPLEX_MACRO) */
 
 
 /* ----------------
  *             heap_getattr
  *
- *             Find a particular field in a row represented as a heap tuple.
- *             We return a pointer into that heap tuple, which points to the
- *             first byte of the value of the field in question.
+ *             Extract an attribute of a heap tuple and return it as a Datum.
+ *             This works for either system or user attributes.  The given attnum
+ *             is properly range-checked.
  *
- *             If the field in question has a NULL value, we return a null
- *             pointer and return <*isnull> == true.  Otherwise, we return
- *             <*isnull> == false.
+ *             If the field in question has a NULL value, we return a zero Datum
+ *             and set *isnull == true.  Otherwise, we set *isnull == false.
  *
  *             <tup> is the pointer to the heap tuple.  <attnum> is the attribute
  *             number of the column (field) caller wants.      <tupleDesc> is a
  *             pointer to the structure describing the row and all its fields.
- *
- *             Because this macro is often called with constants, it generates
- *             compiler warnings about 'left-hand comma expression has no effect.
- *
  * ----------------
  */
 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
 ( \
-       AssertMacro((tup) != NULL && \
-               (attnum) > FirstLowInvalidHeapAttributeNumber && \
-               (attnum) != 0), \
-       ((attnum) > (int) (tup)->t_data->t_natts) ? \
-       ( \
-               ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
-               (Datum)NULL \
-       ) \
-       : \
+       AssertMacro((tup) != NULL), \
        ( \
                ((attnum) > 0) ? \
                ( \
-                       fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
-               ) \
-               : \
-               ( \
-                       ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
-                       ((attnum) == SelfItemPointerAttributeNumber) ? \
+                       ((attnum) > (int) (tup)->t_data->t_natts) ? \
                        ( \
-                               (Datum)((char *)&((tup)->t_self)) \
+                               ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
+                               (Datum)NULL \
                        ) \
                        : \
-                       (((attnum) == TableOidAttributeNumber) ? \
-                       ( \
-                               (Datum)((tup)->t_tableOid) \
-                       ) \
-            : \
-                       ( \
-                               (Datum)*(unsigned int *) \
-                                       ((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1]) \
-                       )) \
+                               fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
                ) \
+               : \
+                       heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
        ) \
 )
 
-extern HeapAccessStatistics heap_access_stats; /* in stats.c */
+extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
+                                                        bool *isnull);
+
 
 /* ----------------
  *             function prototypes for heap access method
@@ -208,51 +129,80 @@ extern HeapAccessStatistics heap_access_stats;    /* in stats.c */
 
 /* heapam.c */
 
+extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
+extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait);
+extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
+extern Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
+extern void relation_close(Relation relation, LOCKMODE lockmode);
+
 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
-extern Relation heap_openr(const char *relationName, LOCKMODE lockmode);
-extern Relation heap_open_nofail(Oid relationId);
-extern Relation heap_openr_nofail(const char *relationName);
-extern void heap_close(Relation relation, LOCKMODE lockmode);
-extern HeapScanDesc heap_beginscan(Relation relation, int atend,
-                          Snapshot snapshot, unsigned nkeys, ScanKey key);
-extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key);
+extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
+extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
+
+#define heap_close(r,l)  relation_close(r,l)
+
+extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
+                          int nkeys, ScanKey key);
+extern void heap_rescan(HeapScanDesc scan, ScanKey key);
 extern void heap_endscan(HeapScanDesc scan);
-extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw);
-extern void heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tup, Buffer *userbuf);
-extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid);
-extern Oid     heap_insert(Relation relation, HeapTuple tup);
-extern int     heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid);
+extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
+
+extern bool heap_fetch(Relation relation, Snapshot snapshot,
+                  HeapTuple tuple, Buffer *userbuf, bool keep_buf,
+                  PgStat_Info *pgstat_info);
+extern bool heap_release_fetch(Relation relation, Snapshot snapshot,
+                  HeapTuple tuple, Buffer *userbuf, bool keep_buf,
+                  PgStat_Info *pgstat_info);
+
+extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
+                                       ItemPointer tid);
+extern void setLastTid(const ItemPointer tid);
+
+extern Oid     heap_insert(Relation relation, HeapTuple tup, CommandId cid);
+extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
+                       CommandId cid, Snapshot crosscheck, bool wait);
 extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
-                       ItemPointer ctid);
-extern int     heap_mark4update(Relation relation, HeapTuple tup, Buffer *userbuf);
+                       ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
+extern int heap_mark4update(Relation relation, HeapTuple tup,
+                                Buffer *userbuf, CommandId cid);
+
+extern Oid     simple_heap_insert(Relation relation, HeapTuple tup);
+extern void simple_heap_delete(Relation relation, ItemPointer tid);
+extern void simple_heap_update(Relation relation, ItemPointer otid,
+                                  HeapTuple tup);
+
 extern void heap_markpos(HeapScanDesc scan);
 extern void heap_restrpos(HeapScanDesc scan);
 
 extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
 extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
-extern void heap_desc(char *buf, uint8 xl_info, char* rec);
+extern void heap_desc(char *buf, uint8 xl_info, char *rec);
+extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
+                          OffsetNumber *unused, int uncnt);
+extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
+                         ItemPointerData from,
+                         Buffer newbuf, HeapTuple newtup);
 
 /* in common/heaptuple.c */
-extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
+extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *values, char *nulls);
 extern void DataFill(char *data, TupleDesc tupleDesc,
-                Datum *value, char *nulls, uint16 *infomask,
+                Datum *values, char *nulls, uint16 *infomask,
                 bits8 *bit);
 extern int     heap_attisnull(HeapTuple tup, int attnum);
-extern int     heap_sysattrlen(AttrNumber attno);
-extern bool heap_sysattrbyval(AttrNumber attno);
 extern Datum nocachegetattr(HeapTuple tup, int attnum,
                           TupleDesc att, bool *isnull);
 extern HeapTuple heap_copytuple(HeapTuple tuple);
 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
-                          Datum *value, char *nulls);
+                          Datum *values, char *nulls);
 extern HeapTuple heap_modifytuple(HeapTuple tuple,
-               Relation relation, Datum *replValue, char *replNull, char *repl);
+                                                                 Relation relation,
+                                                                 Datum *replValues,
+                                                                 char *replNulls,
+                                                                 char *replActions);
+extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
+                                                        Datum *values, char *nulls);
 extern void heap_freetuple(HeapTuple tuple);
-HeapTuple      heap_addheader(uint32 natts, int structlen, char *structure);
-
-/* in common/heap/stats.c */
-extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
-extern void initam(void);
+extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure);
 
-#endif  /* HEAPAM_H */
+#endif   /* HEAPAM_H */