Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite27f4ee

Browse files
committed
Change fastgetattr and heap_getattr to inline functions
They were macros previously, but recent callsite additions made Coveritycomplain about one of the assertions being always true. This changecould have been made a long time ago, but the Coverity complain brokethe 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 parent0bd7af0 commite27f4ee

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(HeapTupletup,intattnum,TupleDesctupleDesc,
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
#defineHeapTupleClearHeapOnly(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-
#definefastgetattr(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-
externDatumfastgetattr(HeapTupletup,intattnum,TupleDesctupleDesc,
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-
#defineheap_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
externSizeheap_compute_data_size(TupleDesctupleDesc,
777695
Datum*values,bool*isnull);
@@ -815,4 +733,73 @@ extern size_t varsize_any(void *p);
815733
externHeapTupleheap_expand_tuple(HeapTuplesourceTuple,TupleDesctupleDesc);
816734
externMinimalTupleminimal_expand_tuple(HeapTuplesourceTuple,TupleDesctupleDesc);
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+
staticinlineDatum
749+
fastgetattr(HeapTupletup,intattnum,TupleDesctupleDesc,bool*isnull)
750+
{
751+
AssertMacro(attnum>0);
752+
753+
*isnull= false;
754+
if (HeapTupleNoNulls(tup))
755+
{
756+
Form_pg_attributeatt;
757+
758+
att=TupleDescAttr(tupleDesc,attnum-1);
759+
if (att->attcacheoff >=0)
760+
returnfetchatt(att, (char*)tup->t_data+tup->t_data->t_hoff+
761+
att->attcacheoff);
762+
else
763+
returnnocachegetattr(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+
returnnocachegetattr(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+
staticinlineDatum
792+
heap_getattr(HeapTupletup,intattnum,TupleDesctupleDesc,bool*isnull)
793+
{
794+
if (attnum>0)
795+
{
796+
if (attnum> (int)HeapTupleHeaderGetNatts(tup->t_data))
797+
returngetmissingattr(tupleDesc,attnum,isnull);
798+
else
799+
returnfastgetattr(tup,attnum,tupleDesc,isnull);
800+
}
801+
else
802+
returnheap_getsysattr(tup,attnum,tupleDesc,isnull);
803+
}
804+
818805
#endif/* HTUP_DETAILS_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp