1998-01-25 06:04:21 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* heapam.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES heap access method definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2005-03-21 02:24:04 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.98 2005/03/21 01:24:04 tgl 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
|
|
|
|
|
1999-07-11 00:06:26 +02:00
|
|
|
#include "access/htup.h"
|
|
|
|
#include "access/relscan.h"
|
2002-05-21 01:51:44 +02:00
|
|
|
#include "access/sdir.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "access/tupmacs.h"
|
2000-11-21 22:16:06 +01:00
|
|
|
#include "access/xlogutils.h"
|
2002-03-26 20:17:02 +01:00
|
|
|
#include "nodes/primnodes.h"
|
1999-07-11 00:06:26 +02:00
|
|
|
#include "storage/block.h"
|
1999-09-18 21:08:25 +02:00
|
|
|
#include "storage/lmgr.h"
|
1999-07-11 00:06:26 +02:00
|
|
|
#include "utils/rel.h"
|
|
|
|
#include "utils/tqual.h"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-01-31 05:39:26 +01:00
|
|
|
/* ----------------
|
|
|
|
* fastgetattr
|
|
|
|
*
|
2000-12-28 00:59:14 +01:00
|
|
|
* 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.
|
1998-01-31 05:39:26 +01:00
|
|
|
*
|
2000-12-28 00:59:14 +01:00
|
|
|
* This gets called many times, so we macro the cacheable and NULL
|
|
|
|
* lookups, and call nocachegetattr() for the rest.
|
1998-01-31 05:39:26 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
1998-11-27 20:33:35 +01:00
|
|
|
|
1998-06-14 03:34:07 +02:00
|
|
|
#if !defined(DISABLE_COMPLEX_MACRO)
|
1998-03-01 05:47:38 +01:00
|
|
|
|
2000-06-30 18:11:02 +02:00
|
|
|
#define fastgetattr(tup, attnum, tupleDesc, isnull) \
|
|
|
|
( \
|
|
|
|
AssertMacro((attnum) > 0), \
|
|
|
|
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
|
|
|
|
HeapTupleNoNulls(tup) ? \
|
|
|
|
( \
|
2000-11-30 19:38:47 +01:00
|
|
|
(tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
|
2000-06-30 18:11:02 +02:00
|
|
|
( \
|
2000-12-28 00:59:14 +01:00
|
|
|
fetchatt((tupleDesc)->attrs[(attnum)-1], \
|
2000-06-30 18:11:02 +02:00
|
|
|
(char *) (tup)->t_data + (tup)->t_data->t_hoff + \
|
2000-11-30 19:38:47 +01:00
|
|
|
(tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
|
2000-06-30 18:11:02 +02:00
|
|
|
) \
|
|
|
|
: \
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
|
|
|
|
( \
|
|
|
|
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
|
|
|
|
(Datum)NULL \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
|
|
|
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
|
|
|
) \
|
|
|
|
) \
|
1998-01-31 05:39:26 +01:00
|
|
|
)
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#else /* defined(DISABLE_COMPLEX_MACRO) */
|
1998-03-01 05:47:38 +01:00
|
|
|
|
2000-12-28 00:59:14 +01:00
|
|
|
extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
|
2001-03-22 05:01:46 +01:00
|
|
|
bool *isnull);
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* defined(DISABLE_COMPLEX_MACRO) */
|
2000-06-30 18:11:02 +02:00
|
|
|
|
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
|
|
|
*
|
2000-12-28 00:59:14 +01:00
|
|
|
* 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.
|
1997-08-27 01:31:58 +02:00
|
|
|
*
|
2000-12-28 00:59:14 +01:00
|
|
|
* If the field in question has a NULL value, we return a zero Datum
|
|
|
|
* and set *isnull == true. Otherwise, we set *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.
|
1998-01-31 05:39:26 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
2000-07-03 00:01:27 +02:00
|
|
|
#define heap_getattr(tup, attnum, tupleDesc, isnull) \
|
|
|
|
( \
|
2000-12-28 00:59:14 +01:00
|
|
|
AssertMacro((tup) != NULL), \
|
2000-07-03 00:01:27 +02:00
|
|
|
( \
|
|
|
|
((attnum) > 0) ? \
|
|
|
|
( \
|
2000-12-28 00:59:14 +01:00
|
|
|
((attnum) > (int) (tup)->t_data->t_natts) ? \
|
2000-07-03 00:01:27 +02:00
|
|
|
( \
|
2000-12-28 00:59:14 +01:00
|
|
|
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
|
|
|
|
(Datum)NULL \
|
2000-07-03 00:01:27 +02:00
|
|
|
) \
|
|
|
|
: \
|
2000-12-28 00:59:14 +01:00
|
|
|
fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
|
2000-07-03 00:01:27 +02:00
|
|
|
) \
|
2000-12-28 00:59:14 +01:00
|
|
|
: \
|
2004-04-01 23:28:47 +02:00
|
|
|
heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
|
2000-07-03 00:01:27 +02:00
|
|
|
) \
|
1998-01-31 05:39:26 +01:00
|
|
|
)
|
1997-08-27 01:31:58 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* function prototypes for heap access method
|
2000-06-19 00:44:35 +02:00
|
|
|
*
|
|
|
|
* heap_create, heap_create_with_catalog, and heap_drop_with_catalog
|
|
|
|
* are declared in catalog/heap.h
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* heapam.c */
|
|
|
|
|
2001-11-02 17:30:29 +01:00
|
|
|
extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
|
2004-03-11 02:47:41 +01:00
|
|
|
extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait);
|
2002-03-26 20:17:02 +01:00
|
|
|
extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
|
|
|
extern Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
|
2001-11-02 17:30:29 +01:00
|
|
|
extern void relation_close(Relation relation, LOCKMODE lockmode);
|
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
|
2002-03-26 20:17:02 +01:00
|
|
|
extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
|
|
|
|
extern Relation heap_openr(const char *sysRelationName, LOCKMODE lockmode);
|
2001-11-05 18:46:40 +01:00
|
|
|
|
2001-11-02 17:30:29 +01:00
|
|
|
#define heap_close(r,l) relation_close(r,l)
|
|
|
|
|
2002-05-21 01:51:44 +02:00
|
|
|
extern HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot,
|
2002-09-04 22:31:48 +02:00
|
|
|
int nkeys, ScanKey key);
|
2002-05-21 01:51:44 +02:00
|
|
|
extern void heap_rescan(HeapScanDesc scan, ScanKey key);
|
1998-08-19 04:04:17 +02:00
|
|
|
extern void heap_endscan(HeapScanDesc scan);
|
2002-05-21 01:51:44 +02:00
|
|
|
extern HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction);
|
|
|
|
|
2002-05-24 20:57:57 +02:00
|
|
|
extern bool heap_fetch(Relation relation, Snapshot snapshot,
|
2002-09-04 22:31:48 +02:00
|
|
|
HeapTuple tuple, Buffer *userbuf, bool keep_buf,
|
|
|
|
PgStat_Info *pgstat_info);
|
2004-04-21 20:24:26 +02:00
|
|
|
extern bool heap_release_fetch(Relation relation, Snapshot snapshot,
|
2004-08-29 07:07:03 +02:00
|
|
|
HeapTuple tuple, Buffer *userbuf, bool keep_buf,
|
|
|
|
PgStat_Info *pgstat_info);
|
2002-05-21 01:51:44 +02:00
|
|
|
|
2002-05-22 00:05:55 +02:00
|
|
|
extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
|
2002-09-04 22:31:48 +02:00
|
|
|
ItemPointer tid);
|
2001-09-17 02:29:10 +02:00
|
|
|
extern void setLastTid(const ItemPointer tid);
|
2002-05-22 00:05:55 +02:00
|
|
|
|
|
|
|
extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
|
2005-03-21 00:40:34 +01:00
|
|
|
extern HTSU_Result heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
|
2003-10-01 23:30:53 +02:00
|
|
|
CommandId cid, Snapshot crosscheck, bool wait);
|
2005-03-21 00:40:34 +01:00
|
|
|
extern HTSU_Result heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
|
2004-08-29 07:07:03 +02:00
|
|
|
ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait);
|
2005-03-21 00:40:34 +01:00
|
|
|
extern HTSU_Result heap_mark4update(Relation relation, HeapTuple tup,
|
2002-09-04 22:31:48 +02:00
|
|
|
Buffer *userbuf, CommandId cid);
|
2002-05-22 00:05:55 +02:00
|
|
|
|
|
|
|
extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
|
2001-01-23 05:32:23 +01:00
|
|
|
extern void simple_heap_delete(Relation relation, ItemPointer tid);
|
|
|
|
extern void simple_heap_update(Relation relation, ItemPointer otid,
|
2001-03-22 05:01:46 +01:00
|
|
|
HeapTuple tup);
|
2002-05-22 00:05:55 +02:00
|
|
|
|
1998-08-19 04:04:17 +02:00
|
|
|
extern void heap_markpos(HeapScanDesc scan);
|
|
|
|
extern void heap_restrpos(HeapScanDesc scan);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2000-11-21 22:16:06 +01:00
|
|
|
extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
|
|
|
|
extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
|
2001-03-22 05:01:46 +01:00
|
|
|
extern void heap_desc(char *buf, uint8 xl_info, char *rec);
|
2001-07-12 06:11:13 +02:00
|
|
|
extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
|
2003-08-04 02:43:34 +02:00
|
|
|
OffsetNumber *unused, int uncnt);
|
2001-07-12 06:11:13 +02:00
|
|
|
extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
|
2001-10-25 07:50:21 +02:00
|
|
|
ItemPointerData from,
|
|
|
|
Buffer newbuf, HeapTuple newtup);
|
2000-11-21 22:16:06 +01:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/* in common/heaptuple.c */
|
2005-03-16 22:38:10 +01:00
|
|
|
extern Size heap_compute_data_size(TupleDesc tupleDesc,
|
|
|
|
Datum *values, bool *isnull);
|
|
|
|
extern void heap_fill_tuple(TupleDesc tupleDesc,
|
|
|
|
Datum *values, bool *isnull,
|
|
|
|
char *data, uint16 *infomask, bits8 *bit);
|
|
|
|
extern bool heap_attisnull(HeapTuple tup, int attnum);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern Datum nocachegetattr(HeapTuple tup, int attnum,
|
1998-02-26 05:46:47 +01:00
|
|
|
TupleDesc att, bool *isnull);
|
2005-03-14 05:41:13 +01:00
|
|
|
extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
|
|
|
|
bool *isnull);
|
1996-08-27 23:50:29 +02:00
|
|
|
extern HeapTuple heap_copytuple(HeapTuple tuple);
|
1998-11-27 20:33:35 +01:00
|
|
|
extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
|
2005-03-16 22:38:10 +01:00
|
|
|
extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor,
|
|
|
|
Datum *values, bool *isnull);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
|
2004-06-04 22:35:21 +02:00
|
|
|
Datum *values, char *nulls);
|
2005-03-16 22:38:10 +01:00
|
|
|
extern HeapTuple heap_modify_tuple(HeapTuple tuple,
|
|
|
|
TupleDesc tupleDesc,
|
|
|
|
Datum *replValues,
|
|
|
|
bool *replIsnull,
|
|
|
|
bool *doReplace);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern HeapTuple heap_modifytuple(HeapTuple tuple,
|
2005-01-28 00:24:11 +01:00
|
|
|
TupleDesc tupleDesc,
|
2004-08-29 07:07:03 +02:00
|
|
|
Datum *replValues,
|
|
|
|
char *replNulls,
|
|
|
|
char *replActions);
|
2005-03-16 22:38:10 +01:00
|
|
|
extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
|
|
|
|
Datum *values, bool *isnull);
|
2004-06-04 22:35:21 +02:00
|
|
|
extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
|
2004-08-29 07:07:03 +02:00
|
|
|
Datum *values, char *nulls);
|
1999-12-16 23:20:03 +01:00
|
|
|
extern void heap_freetuple(HeapTuple tuple);
|
2005-03-16 22:38:10 +01:00
|
|
|
extern HeapTuple heap_addheader(int natts, bool withoid,
|
|
|
|
Size structlen, void *structure);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* HEAPAM_H */
|