mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Inline fastgetattr and others so data access does not use function
calls.
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: heapam.h,v 1.26 1998/01/27 15:57:41 momjian Exp $
|
||||
* $Id: heapam.h,v 1.27 1998/01/31 04:39:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef HEAPAM_H
|
||||
#define HEAPAM_H
|
||||
|
||||
#include <access/tupmacs.h>
|
||||
#include <access/htup.h>
|
||||
#include <access/relscan.h>
|
||||
#include <storage/block.h>
|
||||
@@ -79,6 +80,59 @@ 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.
|
||||
*
|
||||
* ----------------
|
||||
*/
|
||||
#define fastgetattr(tup, attnum, tupleDesc, isnull) \
|
||||
( \
|
||||
AssertMacro((attnum) > 0) ? \
|
||||
( \
|
||||
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
|
||||
HeapTupleNoNulls(tup) ? \
|
||||
( \
|
||||
((tupleDesc)->attrs[(attnum)-1]->attcacheoff > 0) ? \
|
||||
( \
|
||||
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
|
||||
(char *) (tup) + (tup)->t_hoff + (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
((attnum)-1 == 0) ? \
|
||||
( \
|
||||
(Datum)fetchatt(&((tupleDesc)->attrs[0]), (char *) (tup) + (tup)->t_hoff) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
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 \
|
||||
) \
|
||||
)
|
||||
|
||||
|
||||
|
||||
/* ----------------
|
||||
* heap_getattr
|
||||
*
|
||||
@@ -97,15 +151,46 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
|
||||
* Because this macro is often called with constants, it generates
|
||||
* compiler warnings about 'left-hand comma expression has no effect.
|
||||
*
|
||||
* ---------------- */
|
||||
#define heap_getattr(tup, b, attnum, tupleDesc, isnull) \
|
||||
(AssertMacro((tup) != NULL) ? \
|
||||
* ----------------
|
||||
*/
|
||||
#define heap_getattr(tup, attnum, tupleDesc, isnull) \
|
||||
( \
|
||||
AssertMacro((tup) != NULL && \
|
||||
(attnum) > FirstLowInvalidHeapAttributeNumber && \
|
||||
(attnum) != 0) ? \
|
||||
( \
|
||||
((attnum) > (int) (tup)->t_natts) ? \
|
||||
(((isnull) ? (*(isnull) = true) : (dummyret)NULL), (Datum)NULL) : \
|
||||
((attnum) > 0) ? \
|
||||
fastgetattr((tup), (attnum), (tupleDesc), (isnull)) : \
|
||||
(((isnull) ? (*(isnull) = false) : (dummyret)NULL), heap_getsysattr((tup), (b), (attnum))) : \
|
||||
(Datum)NULL)
|
||||
( \
|
||||
((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 \
|
||||
) \
|
||||
)
|
||||
|
||||
extern HeapAccessStatistics heap_access_stats; /* in stats.c */
|
||||
|
||||
@@ -143,7 +228,7 @@ extern int heap_attisnull(HeapTuple tup, int attnum);
|
||||
extern int heap_sysattrlen(AttrNumber attno);
|
||||
extern bool heap_sysattrbyval(AttrNumber attno);
|
||||
extern Datum heap_getsysattr(HeapTuple tup, Buffer b, int attnum);
|
||||
extern Datum fastgetattr(HeapTuple tup, int attnum,
|
||||
extern Datum nocachegetattr(HeapTuple tup, int attnum,
|
||||
TupleDesc att, bool *isnull);
|
||||
extern HeapTuple heap_copytuple(HeapTuple tuple);
|
||||
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: htup.h,v 1.7 1997/11/02 15:26:42 vadim Exp $
|
||||
* $Id: htup.h,v 1.8 1998/01/31 04:39:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -63,6 +63,8 @@ typedef HeapTupleData *HeapTuple;
|
||||
#define MaxCommandIdAttributeNumber (-6)
|
||||
#define FirstLowInvalidHeapAttributeNumber (-7)
|
||||
|
||||
/* If you make any changes above, the order off offsets in this must change */
|
||||
extern long heap_sysoffset[];
|
||||
|
||||
/* ----------------
|
||||
* support macros
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: itup.h,v 1.9 1998/01/24 22:48:06 momjian Exp $
|
||||
* $Id: itup.h,v 1.10 1998/01/31 04:39:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef ITUP_H
|
||||
#define ITUP_H
|
||||
|
||||
#include <access/ibit.h>
|
||||
#include <access/tupmacs.h>
|
||||
#include <access/tupdesc.h>
|
||||
#include <storage/itemptr.h>
|
||||
#include <utils/memutils.h>
|
||||
|
||||
#define MaxIndexAttributeNumber 7
|
||||
|
||||
@@ -87,12 +90,87 @@ typedef struct PredInfo
|
||||
|
||||
#define IndexTupleHasMinHeader(itup) (IndexTupleNoNulls(itup))
|
||||
|
||||
/*
|
||||
* Takes an infomask as argument (primarily because this needs to be usable
|
||||
* at index_formtuple time so enough space is allocated).
|
||||
*
|
||||
* Change me if adding an attribute to IndexTuples!!!!!!!!!!!
|
||||
*/
|
||||
#define IndexInfoFindDataOffset(t_info) \
|
||||
( \
|
||||
(!((unsigned short)(t_info) & INDEX_NULL_MASK)) ? \
|
||||
( \
|
||||
(Size)sizeof(IndexTupleData) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
(Size)DOUBLEALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)) \
|
||||
) \
|
||||
)
|
||||
|
||||
/* ----------------
|
||||
* index_getattr
|
||||
*
|
||||
* This gets called many times, so we macro the cacheable and NULL
|
||||
* lookups, and call noncachegetattr() for the rest.
|
||||
*
|
||||
* ----------------
|
||||
*/
|
||||
#define index_getattr(tup, attnum, tupleDesc, isnull) \
|
||||
( \
|
||||
AssertMacro(PointerIsValid(isnull) && (attnum) > 0) ? \
|
||||
( \
|
||||
*(isnull) = false, \
|
||||
IndexTupleNoNulls(tup) ? \
|
||||
( \
|
||||
((tupleDesc)->attrs[(attnum)-1]->attcacheoff > 0) ? \
|
||||
( \
|
||||
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
|
||||
(char *) (tup) + \
|
||||
(IndexTupleHasMinHeader(tup) ? sizeof (*(tup)) : \
|
||||
IndexInfoFindDataOffset((tup)->t_info)) + \
|
||||
(tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
((attnum)-1 == 0) ? \
|
||||
( \
|
||||
(Datum)fetchatt(&((tupleDesc)->attrs[0]), \
|
||||
(char *) (tup) + \
|
||||
(IndexTupleHasMinHeader(tup) ? sizeof (*(tup)) : \
|
||||
IndexInfoFindDataOffset((tup)->t_info))) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
(att_isnull((attnum)-1, (char *)(tup) + sizeof(*(tup)))) ? \
|
||||
( \
|
||||
*(isnull) = true, \
|
||||
(Datum)NULL \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
: \
|
||||
( \
|
||||
(Datum)NULL \
|
||||
) \
|
||||
)
|
||||
|
||||
|
||||
/* indextuple.h */
|
||||
extern IndexTuple index_formtuple(TupleDesc tupleDescriptor,
|
||||
Datum value[], char null[]);
|
||||
extern Datum index_getattr(IndexTuple tuple, AttrNumber attNum,
|
||||
TupleDesc tupDesc, bool *isNullOutP);
|
||||
extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
|
||||
TupleDesc tupleDesc, bool *isnull);
|
||||
extern RetrieveIndexResult FormRetrieveIndexResult(ItemPointer indexItemPointer,
|
||||
ItemPointer heapItemPointer);
|
||||
extern void CopyIndexTuple(IndexTuple source, IndexTuple *target);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: valid.h,v 1.12 1998/01/15 19:46:18 pgsql Exp $
|
||||
* $Id: valid.h,v 1.13 1998/01/31 04:39:24 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ do \
|
||||
(result) = true; /* may change */ \
|
||||
for (; __cur_nkeys--; __cur_keys++) \
|
||||
{ \
|
||||
__atp = heap_getattr((tuple), InvalidBuffer, \
|
||||
__atp = heap_getattr((tuple), \
|
||||
__cur_keys->sk_attno, \
|
||||
(tupdesc), \
|
||||
&__isnull); \
|
||||
|
||||
Reference in New Issue
Block a user