1998-01-25 06:04:21 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
* heapam.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES heap access method definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1998-06-14 03:34:07 +02:00
|
|
|
* $Id: heapam.h,v 1.32 1998/06/14 01:34:07 momjian Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef HEAPAM_H
|
1996-08-27 23:50:29 +02:00
|
|
|
#define HEAPAM_H
|
|
|
|
|
1998-01-31 05:39:26 +01:00
|
|
|
#include <access/tupmacs.h>
|
1996-11-10 04:06:38 +01:00
|
|
|
#include <access/htup.h>
|
1996-11-05 08:22:50 +01:00
|
|
|
#include <access/relscan.h>
|
1996-11-10 04:06:38 +01:00
|
|
|
#include <storage/block.h>
|
|
|
|
#include <utils/rel.h>
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* heap access method statistics
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct HeapAccessStatisticsData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
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_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_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;
|
1997-09-08 23:56:23 +02:00
|
|
|
} HeapAccessStatisticsData;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
typedef HeapAccessStatisticsData *HeapAccessStatistics;
|
|
|
|
|
|
|
|
#define IncrHeapAccessStat(x) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(heap_access_stats == NULL ? 0 : (heap_access_stats->x)++)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-01-31 05:39:26 +01:00
|
|
|
/* ----------------
|
|
|
|
* fastgetattr
|
|
|
|
*
|
|
|
|
* This gets called many times, so we macro the cacheable and NULL
|
|
|
|
* lookups, and call noncachegetattr() for the rest.
|
|
|
|
*
|
|
|
|
* ----------------
|
|
|
|
*/
|
1998-06-14 03:34:07 +02:00
|
|
|
#if !defined(DISABLE_COMPLEX_MACRO)
|
1998-03-01 05:47:38 +01:00
|
|
|
|
1998-01-31 05:39:26 +01:00
|
|
|
#define fastgetattr(tup, attnum, tupleDesc, isnull) \
|
|
|
|
( \
|
|
|
|
AssertMacro((attnum) > 0) ? \
|
|
|
|
( \
|
|
|
|
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
|
|
|
|
HeapTupleNoNulls(tup) ? \
|
|
|
|
( \
|
1998-02-06 21:18:01 +01:00
|
|
|
((tupleDesc)->attrs[(attnum)-1]->attcacheoff != -1 || \
|
1998-02-01 06:38:40 +01:00
|
|
|
(attnum) == 1) ? \
|
1998-01-31 05:39:26 +01:00
|
|
|
( \
|
|
|
|
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
|
1998-02-26 05:46:47 +01:00
|
|
|
(char *) (tup) + (tup)->t_hoff + \
|
1998-02-01 06:38:40 +01:00
|
|
|
( \
|
|
|
|
((attnum) != 1) ? \
|
|
|
|
(tupleDesc)->attrs[(attnum)-1]->attcacheoff \
|
|
|
|
: \
|
|
|
|
0 \
|
|
|
|
) \
|
1998-01-31 05:39:26 +01:00
|
|
|
) \
|
|
|
|
) \
|
1998-02-01 06:38:40 +01:00
|
|
|
: \
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
1998-01-31 05:39:26 +01:00
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
att_isnull((attnum)-1, (tup)->t_bits) ? \
|
|
|
|
( \
|
|
|
|
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
|
|
|
|
(Datum)NULL \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
(Datum)NULL \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
1998-06-14 03:34:07 +02:00
|
|
|
#else /* !defined(DISABLE_COMPLEX_MACRO) */
|
1998-03-01 05:47:38 +01:00
|
|
|
|
|
|
|
extern Datum nocachegetattr(HeapTuple tup, int attnum,
|
|
|
|
TupleDesc att, bool *isnull);
|
|
|
|
|
|
|
|
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
|
|
|
|
bool *isnull)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(attnum) > 0 ?
|
|
|
|
(
|
|
|
|
((isnull) ? (*(isnull) = false) : (dummyret)NULL),
|
|
|
|
HeapTupleNoNulls(tup) ?
|
|
|
|
(
|
|
|
|
((tupleDesc)->attrs[(attnum)-1]->attcacheoff != -1 ||
|
|
|
|
(attnum) == 1) ?
|
|
|
|
(
|
|
|
|
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]),
|
|
|
|
(char *) (tup) + (tup)->t_hoff +
|
|
|
|
(
|
|
|
|
((attnum) != 1) ?
|
|
|
|
(tupleDesc)->attrs[(attnum)-1]->attcacheoff
|
|
|
|
:
|
|
|
|
0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
:
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull))
|
|
|
|
)
|
|
|
|
:
|
|
|
|
(
|
|
|
|
att_isnull((attnum)-1, (tup)->t_bits) ?
|
|
|
|
(
|
|
|
|
((isnull) ? (*(isnull) = true) : (dummyret)NULL),
|
|
|
|
(Datum)NULL
|
|
|
|
)
|
|
|
|
:
|
|
|
|
(
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
:
|
|
|
|
(
|
|
|
|
(Datum)NULL
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
1998-01-31 05:39:26 +01:00
|
|
|
|
1998-03-01 05:47:38 +01:00
|
|
|
#endif
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1997-08-27 01:31:58 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* heap_getattr
|
1997-08-27 01:31:58 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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.
|
1997-08-27 01:31:58 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* If the field in question has a NULL value, we return a null
|
|
|
|
* pointer and return <*isnull> == true. Otherwise, we return
|
|
|
|
* <*isnull> == false.
|
1997-08-27 01:31:58 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* <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.
|
1997-09-14 05:59:44 +02:00
|
|
|
*
|
|
|
|
* Because this macro is often called with constants, it generates
|
|
|
|
* compiler warnings about 'left-hand comma expression has no effect.
|
|
|
|
*
|
1998-01-31 05:39:26 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#define heap_getattr(tup, attnum, tupleDesc, isnull) \
|
|
|
|
( \
|
|
|
|
AssertMacro((tup) != NULL && \
|
|
|
|
(attnum) > FirstLowInvalidHeapAttributeNumber && \
|
|
|
|
(attnum) != 0) ? \
|
|
|
|
( \
|
1997-09-12 16:29:04 +02:00
|
|
|
((attnum) > (int) (tup)->t_natts) ? \
|
1998-01-31 05:39:26 +01:00
|
|
|
( \
|
|
|
|
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
|
|
|
|
(Datum)NULL \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
((attnum) > 0) ? \
|
|
|
|
( \
|
|
|
|
fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
|
|
|
|
((attnum) == SelfItemPointerAttributeNumber) ? \
|
|
|
|
( \
|
|
|
|
(Datum)((char *)(tup) + \
|
|
|
|
heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
(Datum)*(unsigned int *) \
|
|
|
|
((char *)(tup) + heap_sysoffset[-(attnum)-1]) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
(Datum)NULL \
|
|
|
|
) \
|
|
|
|
)
|
1997-08-27 01:31:58 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
extern HeapAccessStatistics heap_access_stats; /* in stats.c */
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* function prototypes for heap access method
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
/* heap_create, heap_creatr, and heap_destroy are declared in catalog/heap.h */
|
|
|
|
|
|
|
|
/* heapam.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void doinsert(Relation relation, HeapTuple tup);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
extern Relation heap_open(Oid relationId);
|
|
|
|
extern Relation heap_openr(char *relationName);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void heap_close(Relation relation);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern HeapScanDesc
|
|
|
|
heap_beginscan(Relation relation, int atend,
|
1997-11-21 00:24:03 +01:00
|
|
|
bool seeself, unsigned nkeys, ScanKey key);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void heap_rescan(HeapScanDesc sdesc, bool scanFromEnd, ScanKey key);
|
|
|
|
extern void heap_endscan(HeapScanDesc sdesc);
|
1997-09-08 22:59:27 +02:00
|
|
|
extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw, Buffer *b);
|
1998-01-24 23:50:57 +01:00
|
|
|
extern HeapTuple heap_fetch(Relation relation, bool seeself, ItemPointer tid, Buffer *b);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern Oid heap_insert(Relation relation, HeapTuple tup);
|
|
|
|
extern int heap_delete(Relation relation, ItemPointer tid);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern int
|
|
|
|
heap_replace(Relation relation, ItemPointer otid,
|
1997-09-07 07:04:48 +02:00
|
|
|
HeapTuple tup);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void heap_markpos(HeapScanDesc sdesc);
|
|
|
|
extern void heap_restrpos(HeapScanDesc sdesc);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* in common/heaptuple.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern Size ComputeDataSize(TupleDesc tupleDesc, Datum value[], char nulls[]);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern void
|
|
|
|
DataFill(char *data, TupleDesc tupleDesc,
|
1997-11-02 16:27:14 +01:00
|
|
|
Datum value[], char nulls[], uint16 *infomask,
|
1997-09-08 23:56:23 +02:00
|
|
|
bits8 *bit);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int heap_attisnull(HeapTuple tup, int attnum);
|
|
|
|
extern int heap_sysattrlen(AttrNumber attno);
|
|
|
|
extern bool heap_sysattrbyval(AttrNumber attno);
|
1997-09-12 06:09:08 +02:00
|
|
|
extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern Datum
|
|
|
|
nocachegetattr(HeapTuple tup, int attnum,
|
|
|
|
TupleDesc att, bool *isnull);
|
1996-08-27 23:50:29 +02:00
|
|
|
extern HeapTuple heap_copytuple(HeapTuple tuple);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern HeapTuple
|
|
|
|
heap_formtuple(TupleDesc tupleDescriptor,
|
1997-09-07 07:04:48 +02:00
|
|
|
Datum value[], char nulls[]);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern HeapTuple
|
|
|
|
heap_modifytuple(HeapTuple tuple, Buffer buffer,
|
1997-09-07 07:04:48 +02:00
|
|
|
Relation relation, Datum replValue[], char replNull[], char repl[]);
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple heap_addheader(uint32 natts, int structlen, char *structure);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* in common/heap/stats.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void PrintHeapAccessStatistics(HeapAccessStatistics stats);
|
|
|
|
extern void initam(void);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1996-11-10 04:06:38 +01:00
|
|
|
/* hio.c */
|
1998-02-26 05:46:47 +01:00
|
|
|
extern void
|
|
|
|
RelationPutHeapTuple(Relation relation, BlockNumber blockIndex,
|
1997-09-07 07:04:48 +02:00
|
|
|
HeapTuple tuple);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void RelationPutHeapTupleAtEnd(Relation relation, HeapTuple tuple);
|
1996-11-10 04:06:38 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* HEAPAM_H */
|