Skip to content

Commit e27f4ee

Browse files
committed
Change fastgetattr and heap_getattr to inline functions
They were macros previously, but recent callsite additions made Coverity complain about one of the assertions being always true. This change could have been made a long time ago, but the Coverity complain broke the inertia. Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Japin Li <japinli@hotmail.com> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Discussion: https://postgr.es/m/202203241021.uts52sczx3al@alvherre.pgsql
1 parent 0bd7af0 commit e27f4ee

File tree

2 files changed

+69
-128
lines changed

2 files changed

+69
-128
lines changed

src/backend/access/heap/heapam.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,52 +1131,6 @@ heapgettup_pagemode(HeapScanDesc scan,
11311131
}
11321132

11331133

1134-
#if defined(DISABLE_COMPLEX_MACRO)
1135-
/*
1136-
* This is formatted so oddly so that the correspondence to the macro
1137-
* definition in access/htup_details.h is maintained.
1138-
*/
1139-
Datum
1140-
fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
1141-
bool *isnull)
1142-
{
1143-
return (
1144-
(attnum) > 0 ?
1145-
(
1146-
(*(isnull) = false),
1147-
HeapTupleNoNulls(tup) ?
1148-
(
1149-
TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff >= 0 ?
1150-
(
1151-
fetchatt(TupleDescAttr((tupleDesc), (attnum) - 1),
1152-
(char *) (tup)->t_data + (tup)->t_data->t_hoff +
1153-
TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff)
1154-
)
1155-
:
1156-
nocachegetattr((tup), (attnum), (tupleDesc))
1157-
)
1158-
:
1159-
(
1160-
att_isnull((attnum) - 1, (tup)->t_data->t_bits) ?
1161-
(
1162-
(*(isnull) = true),
1163-
(Datum) NULL
1164-
)
1165-
:
1166-
(
1167-
nocachegetattr((tup), (attnum), (tupleDesc))
1168-
)
1169-
)
1170-
)
1171-
:
1172-
(
1173-
(Datum) NULL
1174-
)
1175-
);
1176-
}
1177-
#endif /* defined(DISABLE_COMPLEX_MACRO) */
1178-
1179-
11801134
/* ----------------------------------------------------------------
11811135
* heap access method interface
11821136
* ----------------------------------------------------------------

src/include/access/htup_details.h

Lines changed: 69 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -690,88 +690,6 @@ struct MinimalTupleData
690690
#define HeapTupleClearHeapOnly(tuple) \
691691
HeapTupleHeaderClearHeapOnly((tuple)->t_data)
692692

693-
694-
/* ----------------
695-
* fastgetattr
696-
*
697-
* Fetch a user attribute's value as a Datum (might be either a
698-
* value, or a pointer into the data area of the tuple).
699-
*
700-
* This must not be used when a system attribute might be requested.
701-
* Furthermore, the passed attnum MUST be valid. Use heap_getattr()
702-
* instead, if in doubt.
703-
*
704-
* This gets called many times, so we macro the cacheable and NULL
705-
* lookups, and call nocachegetattr() for the rest.
706-
* ----------------
707-
*/
708-
709-
#if !defined(DISABLE_COMPLEX_MACRO)
710-
711-
#define fastgetattr(tup, attnum, tupleDesc, isnull) \
712-
( \
713-
AssertMacro((attnum) > 0), \
714-
(*(isnull) = false), \
715-
HeapTupleNoNulls(tup) ? \
716-
( \
717-
TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \
718-
( \
719-
fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \
720-
(char *) (tup)->t_data + (tup)->t_data->t_hoff + \
721-
TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff)\
722-
) \
723-
: \
724-
nocachegetattr((tup), (attnum), (tupleDesc)) \
725-
) \
726-
: \
727-
( \
728-
att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
729-
( \
730-
(*(isnull) = true), \
731-
(Datum)NULL \
732-
) \
733-
: \
734-
( \
735-
nocachegetattr((tup), (attnum), (tupleDesc)) \
736-
) \
737-
) \
738-
)
739-
#else /* defined(DISABLE_COMPLEX_MACRO) */
740-
741-
extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
742-
bool *isnull);
743-
#endif /* defined(DISABLE_COMPLEX_MACRO) */
744-
745-
746-
/* ----------------
747-
* heap_getattr
748-
*
749-
* Extract an attribute of a heap tuple and return it as a Datum.
750-
* This works for either system or user attributes. The given attnum
751-
* is properly range-checked.
752-
*
753-
* If the field in question has a NULL value, we return a zero Datum
754-
* and set *isnull == true. Otherwise, we set *isnull == false.
755-
*
756-
* <tup> is the pointer to the heap tuple. <attnum> is the attribute
757-
* number of the column (field) caller wants. <tupleDesc> is a
758-
* pointer to the structure describing the row and all its fields.
759-
* ----------------
760-
*/
761-
#define heap_getattr(tup, attnum, tupleDesc, isnull) \
762-
( \
763-
((attnum) > 0) ? \
764-
( \
765-
((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
766-
getmissingattr((tupleDesc), (attnum), (isnull)) \
767-
: \
768-
fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
769-
) \
770-
: \
771-
heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
772-
)
773-
774-
775693
/* prototypes for functions in common/heaptuple.c */
776694
extern Size heap_compute_data_size(TupleDesc tupleDesc,
777695
Datum *values, bool *isnull);
@@ -815,4 +733,73 @@ extern size_t varsize_any(void *p);
815733
extern HeapTuple heap_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc);
816734
extern MinimalTuple minimal_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc);
817735

736+
/*
737+
* fastgetattr
738+
* Fetch a user attribute's value as a Datum (might be either a
739+
* value, or a pointer into the data area of the tuple).
740+
*
741+
* This must not be used when a system attribute might be requested.
742+
* Furthermore, the passed attnum MUST be valid. Use heap_getattr()
743+
* instead, if in doubt.
744+
*
745+
* This gets called many times, so we macro the cacheable and NULL
746+
* lookups, and call nocachegetattr() for the rest.
747+
*/
748+
static inline Datum
749+
fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
750+
{
751+
AssertMacro(attnum > 0);
752+
753+
*isnull = false;
754+
if (HeapTupleNoNulls(tup))
755+
{
756+
Form_pg_attribute att;
757+
758+
att = TupleDescAttr(tupleDesc, attnum - 1);
759+
if (att->attcacheoff >= 0)
760+
return fetchatt(att, (char *) tup->t_data + tup->t_data->t_hoff +
761+
att->attcacheoff);
762+
else
763+
return nocachegetattr(tup, attnum, tupleDesc);
764+
}
765+
else
766+
{
767+
if (att_isnull(attnum - 1, tup->t_data->t_bits))
768+
{
769+
*isnull = true;
770+
return (Datum) NULL;
771+
}
772+
else
773+
return nocachegetattr(tup, attnum, tupleDesc);
774+
}
775+
}
776+
777+
/*
778+
* heap_getattr
779+
* Extract an attribute of a heap tuple and return it as a Datum.
780+
* This works for either system or user attributes. The given attnum
781+
* is properly range-checked.
782+
*
783+
* If the field in question has a NULL value, we return a zero Datum
784+
* and set *isnull == true. Otherwise, we set *isnull == false.
785+
*
786+
* <tup> is the pointer to the heap tuple. <attnum> is the attribute
787+
* number of the column (field) caller wants. <tupleDesc> is a
788+
* pointer to the structure describing the row and all its fields.
789+
*
790+
*/
791+
static inline Datum
792+
heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
793+
{
794+
if (attnum > 0)
795+
{
796+
if (attnum > (int) HeapTupleHeaderGetNatts(tup->t_data))
797+
return getmissingattr(tupleDesc, attnum, isnull);
798+
else
799+
return fastgetattr(tup, attnum, tupleDesc, isnull);
800+
}
801+
else
802+
return heap_getsysattr(tup, attnum, tupleDesc, isnull);
803+
}
804+
818805
#endif /* HTUP_DETAILS_H */

0 commit comments

Comments
 (0)