Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 726c385

Browse files
committed
Inline fastgetattr and others so data access does not use function
calls.
1 parent 2df6bba commit 726c385

File tree

35 files changed

+350
-215
lines changed

35 files changed

+350
-215
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*-------------------------------------------------------------------------
1+
/*-------------------------------------------------------------------------
22
*
33
* heaptuple.c--
44
* This file contains heap tuple accessor and mutator routines, as well
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.30 1998/01/07 21:00:40 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.31 1998/01/31 04:38:02 momjian Exp $
1212
*
1313
* NOTES
1414
* The old interface functions have been converted to macros
@@ -32,6 +32,16 @@
3232
#include <string.h>
3333
#endif
3434

35+
/* Used by heap_getattr() macro, for speed */
36+
long heap_sysoffset[] = {
37+
/* Only the first one is pass-by-ref, and is handled specially in the macro */
38+
offsetof(HeapTupleData, t_ctid),
39+
offsetof(HeapTupleData, t_oid),
40+
offsetof(HeapTupleData, t_xmin),
41+
offsetof(HeapTupleData, t_cmin),
42+
offsetof(HeapTupleData, t_xmax),
43+
offsetof(HeapTupleData, t_cmax)
44+
};
3545

3646
/* this is so the sparcstation debugger works */
3747

@@ -345,7 +355,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
345355
{
346356
switch (attnum)
347357
{
348-
case SelfItemPointerAttributeNumber:
358+
case SelfItemPointerAttributeNumber:
349359
return ((Datum) &tup->t_ctid);
350360
case ObjectIdAttributeNumber:
351361
return ((Datum) (long) tup->t_oid);
@@ -364,10 +374,12 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
364374
}
365375

366376
/* ----------------
367-
* fastgetattr
377+
* nocachegetattr
378+
*
379+
* This only gets called from fastgetattr() macro, in cases where
380+
* we can't use a cacheoffset and the value is not null.
368381
*
369-
* This is a newer version of fastgetattr which attempts to be
370-
* faster by caching attribute offsets in the attribute descriptor.
382+
* This caches attribute offsets in the attribute descriptor.
371383
*
372384
* an alternate way to speed things up would be to cache offsets
373385
* with the tuple, but that seems more difficult unless you take
@@ -381,7 +393,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
381393
* ----------------
382394
*/
383395
Datum
384-
fastgetattr(HeapTuple tup,
396+
nocachegetattr(HeapTuple tup,
385397
int attnum,
386398
TupleDesc tupleDesc,
387399
bool *isnull)
@@ -391,13 +403,15 @@ fastgetattr(HeapTuple tup,
391403
int slow; /* do we have to walk nulls? */
392404
AttributeTupleForm *att = tupleDesc->attrs;
393405

394-
/* ----------------
395-
* sanity checks
396-
* ----------------
397-
*/
398-
406+
407+
#if IN_MACRO
408+
/* This is handled in the macro */
399409
Assert(attnum > 0);
400410

411+
if (isnull)
412+
*isnull = false;
413+
#endif
414+
401415
/* ----------------
402416
* Three cases:
403417
*
@@ -407,12 +421,12 @@ fastgetattr(HeapTuple tup,
407421
* ----------------
408422
*/
409423

410-
if (isnull)
411-
*isnull = false;
412-
413424
if (HeapTupleNoNulls(tup))
414425
{
415426
attnum--;
427+
428+
#if IN_MACRO
429+
/* This is handled in the macro */
416430
if (att[attnum]->attcacheoff > 0)
417431
{
418432
return (Datum)
@@ -427,6 +441,7 @@ fastgetattr(HeapTuple tup,
427441
*/
428442
return ((Datum) fetchatt(&(att[0]), (char *) tup + tup->t_hoff));
429443
}
444+
#endif
430445

431446
tp = (char *) tup + tup->t_hoff;
432447

@@ -449,12 +464,15 @@ fastgetattr(HeapTuple tup,
449464
* ----------------
450465
*/
451466

467+
#if IN_MACRO
468+
/* This is handled in the macro */
452469
if (att_isnull(attnum, bp))
453470
{
454471
if (isnull)
455472
*isnull = true;
456473
return (Datum) NULL;
457474
}
475+
#endif
458476

459477
/* ----------------
460478
* Now check to see if any preceeding bits are null...
@@ -539,7 +557,7 @@ fastgetattr(HeapTuple tup,
539557
if (att[j]->attlen < sizeof(int32))
540558
{
541559
elog(ERROR,
542-
"fastgetattr: attribute %d has len %d",
560+
"nocachegetattr: attribute %d has len %d",
543561
j, att[j]->attlen);
544562
}
545563
if (att[j]->attalign == 'd')
@@ -599,7 +617,7 @@ fastgetattr(HeapTuple tup,
599617
default:
600618
if (att[i]->attlen < sizeof(int32))
601619
elog(ERROR,
602-
"fastgetattr2: attribute %d has len %d",
620+
"nocachegetattr2: attribute %d has len %d",
603621
i, att[i]->attlen);
604622
if (att[i]->attalign == 'd')
605623
off = DOUBLEALIGN(off);
@@ -657,7 +675,7 @@ fastgetattr(HeapTuple tup,
657675
break;
658676
default:
659677
if (att[attnum]->attlen < sizeof(int32))
660-
elog(ERROR, "fastgetattr3: attribute %d has len %d",
678+
elog(ERROR, "nocachegetattr3: attribute %d has len %d",
661679
attnum, att[attnum]->attlen);
662680
if (att[attnum]->attalign == 'd')
663681
off = DOUBLEALIGN(off);
@@ -719,7 +737,6 @@ heap_deformtuple(HeapTuple tuple,
719737
bool isnull;
720738

721739
values[i] = heap_getattr(tuple,
722-
InvalidBuffer,
723740
i + 1,
724741
tdesc,
725742
&isnull);
@@ -874,7 +891,6 @@ heap_modifytuple(HeapTuple tuple,
874891
{
875892
value[attoff] =
876893
heap_getattr(tuple,
877-
InvalidBuffer,
878894
AttrOffsetGetAttrNumber(attoff),
879895
RelationGetTupleDescriptor(relation),
880896
&isNull);
@@ -959,3 +975,4 @@ heap_addheader(uint32 natts, /* max domain index */
959975

960976
return (tup);
961977
}
978+

0 commit comments

Comments
 (0)