83
83
#define VARLENA_ATT_IS_PACKABLE (att ) \
84
84
((att)->attstorage != TYPSTORAGE_PLAIN)
85
85
86
+ /* FormData_pg_attribute.attstorage != TYPSTORAGE_PLAIN and an attlen of -1 */
87
+ #define COMPACT_ATTR_IS_PACKABLE (att ) \
88
+ ((att)->attlen == -1 && (att)->attispackable)
89
+
86
90
/*
87
91
* Setup for caching pass-by-ref missing attributes in a way that survives
88
92
* tupleDesc destruction.
@@ -147,12 +151,12 @@ Datum
147
151
getmissingattr (TupleDesc tupleDesc ,
148
152
int attnum , bool * isnull )
149
153
{
150
- Form_pg_attribute att ;
154
+ CompactAttribute * att ;
151
155
152
156
Assert (attnum <= tupleDesc -> natts );
153
157
Assert (attnum > 0 );
154
158
155
- att = TupleDescAttr (tupleDesc , attnum - 1 );
159
+ att = TupleDescCompactAttr (tupleDesc , attnum - 1 );
156
160
157
161
if (att -> atthasmissing )
158
162
{
@@ -223,15 +227,15 @@ heap_compute_data_size(TupleDesc tupleDesc,
223
227
for (i = 0 ; i < numberOfAttributes ; i ++ )
224
228
{
225
229
Datum val ;
226
- Form_pg_attribute atti ;
230
+ CompactAttribute * atti ;
227
231
228
232
if (isnull [i ])
229
233
continue ;
230
234
231
235
val = values [i ];
232
- atti = TupleDescAttr (tupleDesc , i );
236
+ atti = TupleDescCompactAttr (tupleDesc , i );
233
237
234
- if (ATT_IS_PACKABLE (atti ) &&
238
+ if (COMPACT_ATTR_IS_PACKABLE (atti ) &&
235
239
VARATT_CAN_MAKE_SHORT (DatumGetPointer (val )))
236
240
{
237
241
/*
@@ -268,7 +272,7 @@ heap_compute_data_size(TupleDesc tupleDesc,
268
272
* Fill in either a data value or a bit in the null bitmask
269
273
*/
270
274
static inline void
271
- fill_val (Form_pg_attribute att ,
275
+ fill_val (CompactAttribute * att ,
272
276
bits8 * * bit ,
273
277
int * bitmask ,
274
278
char * * dataP ,
@@ -349,8 +353,7 @@ fill_val(Form_pg_attribute att,
349
353
data_length = VARSIZE_SHORT (val );
350
354
memcpy (data , val , data_length );
351
355
}
352
- else if (VARLENA_ATT_IS_PACKABLE (att ) &&
353
- VARATT_CAN_MAKE_SHORT (val ))
356
+ else if (att -> attispackable && VARATT_CAN_MAKE_SHORT (val ))
354
357
{
355
358
/* convert to short varlena -- no alignment */
356
359
data_length = VARATT_CONVERTED_SHORT_SIZE (val );
@@ -427,7 +430,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
427
430
428
431
for (i = 0 ; i < numberOfAttributes ; i ++ )
429
432
{
430
- Form_pg_attribute attr = TupleDescAttr (tupleDesc , i );
433
+ CompactAttribute * attr = TupleDescCompactAttr (tupleDesc , i );
431
434
432
435
fill_val (attr ,
433
436
bitP ? & bitP : NULL ,
@@ -461,7 +464,8 @@ heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
461
464
Assert (!tupleDesc || attnum <= tupleDesc -> natts );
462
465
if (attnum > (int ) HeapTupleHeaderGetNatts (tup -> t_data ))
463
466
{
464
- if (tupleDesc && TupleDescAttr (tupleDesc , attnum - 1 )-> atthasmissing )
467
+ if (tupleDesc &&
468
+ TupleDescCompactAttr (tupleDesc , attnum - 1 )-> atthasmissing )
465
469
return false;
466
470
else
467
471
return true;
@@ -570,13 +574,13 @@ nocachegetattr(HeapTuple tup,
570
574
571
575
if (!slow )
572
576
{
573
- Form_pg_attribute att ;
577
+ CompactAttribute * att ;
574
578
575
579
/*
576
580
* If we get here, there are no nulls up to and including the target
577
581
* attribute. If we have a cached offset, we can use it.
578
582
*/
579
- att = TupleDescAttr (tupleDesc , attnum );
583
+ att = TupleDescCompactAttr (tupleDesc , attnum );
580
584
if (att -> attcacheoff >= 0 )
581
585
return fetchatt (att , tp + att -> attcacheoff );
582
586
@@ -591,7 +595,7 @@ nocachegetattr(HeapTuple tup,
591
595
592
596
for (j = 0 ; j <= attnum ; j ++ )
593
597
{
594
- if (TupleDescAttr (tupleDesc , j )-> attlen <= 0 )
598
+ if (TupleDescCompactAttr (tupleDesc , j )-> attlen <= 0 )
595
599
{
596
600
slow = true;
597
601
break ;
@@ -614,18 +618,18 @@ nocachegetattr(HeapTuple tup,
614
618
* fixed-width columns, in hope of avoiding future visits to this
615
619
* routine.
616
620
*/
617
- TupleDescAttr (tupleDesc , 0 )-> attcacheoff = 0 ;
621
+ TupleDescCompactAttr (tupleDesc , 0 )-> attcacheoff = 0 ;
618
622
619
623
/* we might have set some offsets in the slow path previously */
620
- while (j < natts && TupleDescAttr (tupleDesc , j )-> attcacheoff > 0 )
624
+ while (j < natts && TupleDescCompactAttr (tupleDesc , j )-> attcacheoff > 0 )
621
625
j ++ ;
622
626
623
- off = TupleDescAttr (tupleDesc , j - 1 )-> attcacheoff +
624
- TupleDescAttr (tupleDesc , j - 1 )-> attlen ;
627
+ off = TupleDescCompactAttr (tupleDesc , j - 1 )-> attcacheoff +
628
+ TupleDescCompactAttr (tupleDesc , j - 1 )-> attlen ;
625
629
626
630
for (; j < natts ; j ++ )
627
631
{
628
- Form_pg_attribute att = TupleDescAttr (tupleDesc , j );
632
+ CompactAttribute * att = TupleDescCompactAttr (tupleDesc , j );
629
633
630
634
if (att -> attlen <= 0 )
631
635
break ;
@@ -639,7 +643,7 @@ nocachegetattr(HeapTuple tup,
639
643
640
644
Assert (j > attnum );
641
645
642
- off = TupleDescAttr (tupleDesc , attnum )-> attcacheoff ;
646
+ off = TupleDescCompactAttr (tupleDesc , attnum )-> attcacheoff ;
643
647
}
644
648
else
645
649
{
@@ -659,7 +663,7 @@ nocachegetattr(HeapTuple tup,
659
663
off = 0 ;
660
664
for (i = 0 ;; i ++ ) /* loop exit is at "break" */
661
665
{
662
- Form_pg_attribute att = TupleDescAttr (tupleDesc , i );
666
+ CompactAttribute * att = TupleDescCompactAttr (tupleDesc , i );
663
667
664
668
if (HeapTupleHasNulls (tup ) && att_isnull (i , bp ))
665
669
{
@@ -707,7 +711,7 @@ nocachegetattr(HeapTuple tup,
707
711
}
708
712
}
709
713
710
- return fetchatt (TupleDescAttr (tupleDesc , attnum ), tp + off );
714
+ return fetchatt (TupleDescCompactAttr (tupleDesc , attnum ), tp + off );
711
715
}
712
716
713
717
/* ----------------
@@ -892,7 +896,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
892
896
{
893
897
if (attrmiss [attnum ].am_present )
894
898
{
895
- Form_pg_attribute att = TupleDescAttr (tupleDesc , attnum );
899
+ CompactAttribute * att = TupleDescCompactAttr (tupleDesc , attnum );
896
900
897
901
targetDataLen = att_align_datum (targetDataLen ,
898
902
att -> attalign ,
@@ -1020,8 +1024,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
1020
1024
/* Now fill in the missing values */
1021
1025
for (attnum = sourceNatts ; attnum < natts ; attnum ++ )
1022
1026
{
1023
-
1024
- Form_pg_attribute attr = TupleDescAttr (tupleDesc , attnum );
1027
+ CompactAttribute * attr = TupleDescCompactAttr (tupleDesc , attnum );
1025
1028
1026
1029
if (attrmiss && attrmiss [attnum ].am_present )
1027
1030
{
@@ -1370,7 +1373,7 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
1370
1373
1371
1374
for (attnum = 0 ; attnum < natts ; attnum ++ )
1372
1375
{
1373
- Form_pg_attribute thisatt = TupleDescAttr (tupleDesc , attnum );
1376
+ CompactAttribute * thisatt = TupleDescCompactAttr (tupleDesc , attnum );
1374
1377
1375
1378
if (hasnulls && att_isnull (attnum , bp ))
1376
1379
{
0 commit comments