1
- /*-------------------------------------------------------------------------
1
+ /*-------------------------------------------------------------------------
2
2
*
3
3
* heaptuple.c--
4
4
* This file contains heap tuple accessor and mutator routines, as well
8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
* NOTES
14
14
* The old interface functions have been converted to macros
32
32
#include <string.h>
33
33
#endif
34
34
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
+ };
35
45
36
46
/* this is so the sparcstation debugger works */
37
47
@@ -345,7 +355,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
345
355
{
346
356
switch (attnum )
347
357
{
348
- case SelfItemPointerAttributeNumber :
358
+ case SelfItemPointerAttributeNumber :
349
359
return ((Datum ) & tup -> t_ctid );
350
360
case ObjectIdAttributeNumber :
351
361
return ((Datum ) (long ) tup -> t_oid );
@@ -364,10 +374,12 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
364
374
}
365
375
366
376
/* ----------------
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.
368
381
*
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.
371
383
*
372
384
* an alternate way to speed things up would be to cache offsets
373
385
* with the tuple, but that seems more difficult unless you take
@@ -381,7 +393,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
381
393
* ----------------
382
394
*/
383
395
Datum
384
- fastgetattr (HeapTuple tup ,
396
+ nocachegetattr (HeapTuple tup ,
385
397
int attnum ,
386
398
TupleDesc tupleDesc ,
387
399
bool * isnull )
@@ -391,13 +403,15 @@ fastgetattr(HeapTuple tup,
391
403
int slow ; /* do we have to walk nulls? */
392
404
AttributeTupleForm * att = tupleDesc -> attrs ;
393
405
394
- /* ----------------
395
- * sanity checks
396
- * ----------------
397
- */
398
-
406
+
407
+ #if IN_MACRO
408
+ /* This is handled in the macro */
399
409
Assert (attnum > 0 );
400
410
411
+ if (isnull )
412
+ * isnull = false;
413
+ #endif
414
+
401
415
/* ----------------
402
416
* Three cases:
403
417
*
@@ -407,12 +421,12 @@ fastgetattr(HeapTuple tup,
407
421
* ----------------
408
422
*/
409
423
410
- if (isnull )
411
- * isnull = false;
412
-
413
424
if (HeapTupleNoNulls (tup ))
414
425
{
415
426
attnum -- ;
427
+
428
+ #if IN_MACRO
429
+ /* This is handled in the macro */
416
430
if (att [attnum ]-> attcacheoff > 0 )
417
431
{
418
432
return (Datum )
@@ -427,6 +441,7 @@ fastgetattr(HeapTuple tup,
427
441
*/
428
442
return ((Datum ) fetchatt (& (att [0 ]), (char * ) tup + tup -> t_hoff ));
429
443
}
444
+ #endif
430
445
431
446
tp = (char * ) tup + tup -> t_hoff ;
432
447
@@ -449,12 +464,15 @@ fastgetattr(HeapTuple tup,
449
464
* ----------------
450
465
*/
451
466
467
+ #if IN_MACRO
468
+ /* This is handled in the macro */
452
469
if (att_isnull (attnum , bp ))
453
470
{
454
471
if (isnull )
455
472
* isnull = true;
456
473
return (Datum ) NULL ;
457
474
}
475
+ #endif
458
476
459
477
/* ----------------
460
478
* Now check to see if any preceeding bits are null...
@@ -539,7 +557,7 @@ fastgetattr(HeapTuple tup,
539
557
if (att [j ]-> attlen < sizeof (int32 ))
540
558
{
541
559
elog (ERROR ,
542
- "fastgetattr : attribute %d has len %d" ,
560
+ "nocachegetattr : attribute %d has len %d" ,
543
561
j , att [j ]-> attlen );
544
562
}
545
563
if (att [j ]-> attalign == 'd' )
@@ -599,7 +617,7 @@ fastgetattr(HeapTuple tup,
599
617
default :
600
618
if (att [i ]-> attlen < sizeof (int32 ))
601
619
elog (ERROR ,
602
- "fastgetattr2 : attribute %d has len %d" ,
620
+ "nocachegetattr2 : attribute %d has len %d" ,
603
621
i , att [i ]-> attlen );
604
622
if (att [i ]-> attalign == 'd' )
605
623
off = DOUBLEALIGN (off );
@@ -657,7 +675,7 @@ fastgetattr(HeapTuple tup,
657
675
break ;
658
676
default :
659
677
if (att [attnum ]-> attlen < sizeof (int32 ))
660
- elog (ERROR , "fastgetattr3 : attribute %d has len %d" ,
678
+ elog (ERROR , "nocachegetattr3 : attribute %d has len %d" ,
661
679
attnum , att [attnum ]-> attlen );
662
680
if (att [attnum ]-> attalign == 'd' )
663
681
off = DOUBLEALIGN (off );
@@ -719,7 +737,6 @@ heap_deformtuple(HeapTuple tuple,
719
737
bool isnull ;
720
738
721
739
values [i ] = heap_getattr (tuple ,
722
- InvalidBuffer ,
723
740
i + 1 ,
724
741
tdesc ,
725
742
& isnull );
@@ -874,7 +891,6 @@ heap_modifytuple(HeapTuple tuple,
874
891
{
875
892
value [attoff ] =
876
893
heap_getattr (tuple ,
877
- InvalidBuffer ,
878
894
AttrOffsetGetAttrNumber (attoff ),
879
895
RelationGetTupleDescriptor (relation ),
880
896
& isNull );
@@ -959,3 +975,4 @@ heap_addheader(uint32 natts, /* max domain index */
959
975
960
976
return (tup );
961
977
}
978
+
0 commit comments