LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_float4.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: 77aeca80249c9e640c811e80633a2e334a9320de vs 38afc3dcb25c45b744d4025029ce0a6c90b7059f Lines: 91.2 % 102 93 9 1 92 1
Current Date: 2026-07-25 19:08:27 +0900 Functions: 100.0 % 28 28 1 27
Baseline: lcov-20260725-baseline Branches: 35.7 % 28 10 18 10
Baseline Date: 2026-07-25 19:09:19 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 70.4 % 27 19 8 1 18
(360..) days: 98.7 % 75 74 1 74
Function coverage date bins:
(360..) days: 100.0 % 28 28 1 27
Branch coverage date bins:
(7,30] days: 31.8 % 22 7 15 7
(360..) days: 50.0 % 6 3 3 3

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * contrib/btree_gist/btree_float4.c
                                  3                 :                :  */
                                  4                 :                : #include "postgres.h"
                                  5                 :                : 
                                  6                 :                : #include "btree_gist.h"
                                  7                 :                : #include "btree_utils_num.h"
                                  8                 :                : #include "utils/float.h"
                                  9                 :                : #include "utils/rel.h"
                                 10                 :                : #include "utils/sortsupport.h"
                                 11                 :                : 
                                 12                 :                : typedef struct float4key
                                 13                 :                : {
                                 14                 :                :     float4      lower;
                                 15                 :                :     float4      upper;
                                 16                 :                : } float4KEY;
                                 17                 :                : 
                                 18                 :                : /* GiST support functions */
 8093 teodor@sigaev.ru           19                 :CBC           4 : PG_FUNCTION_INFO_V1(gbt_float4_compress);
 4138 heikki.linnakangas@i       20                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_fetch);
 8093 teodor@sigaev.ru           21                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_union);
                                 22                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_picksplit);
                                 23                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_consistent);
 5624 tgl@sss.pgh.pa.us          24                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_distance);
 8093 teodor@sigaev.ru           25                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_penalty);
                                 26                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_same);
  478 heikki.linnakangas@i       27                 :              4 : PG_FUNCTION_INFO_V1(gbt_float4_sortsupport);
                                 28                 :                : 
                                 29                 :                : /*
                                 30                 :                :  * Use the NaN-aware comparators from utils/float.h, so that our results
                                 31                 :                :  * will agree with standard btree indexes.  Note that penalty and distance
                                 32                 :                :  * functions below must also cope with NaNs, in particular with the policy
                                 33                 :                :  * that all NaNs are equal.
                                 34                 :                :  */
                                 35                 :                : static bool
 3413 andrew@dunslane.net        36                 :           4389 : gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
                                 37                 :                : {
   24 tgl@sss.pgh.pa.us          38                 :           4389 :     return float4_gt(*((const float4 *) a), *((const float4 *) b));
                                 39                 :                : }
                                 40                 :                : static bool
 3413 andrew@dunslane.net        41                 :            802 : gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
                                 42                 :                : {
   24 tgl@sss.pgh.pa.us          43                 :            802 :     return float4_ge(*((const float4 *) a), *((const float4 *) b));
                                 44                 :                : }
                                 45                 :                : static bool
 3413 andrew@dunslane.net        46                 :            554 : gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
                                 47                 :                : {
   24 tgl@sss.pgh.pa.us          48                 :            554 :     return float4_eq(*((const float4 *) a), *((const float4 *) b));
                                 49                 :                : }
                                 50                 :                : static bool
 3413 andrew@dunslane.net        51                 :            560 : gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
                                 52                 :                : {
   24 tgl@sss.pgh.pa.us          53                 :            560 :     return float4_le(*((const float4 *) a), *((const float4 *) b));
                                 54                 :                : }
                                 55                 :                : static bool
 3413 andrew@dunslane.net        56                 :           4114 : gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
                                 57                 :                : {
   24 tgl@sss.pgh.pa.us          58                 :           4114 :     return float4_lt(*((const float4 *) a), *((const float4 *) b));
                                 59                 :                : }
                                 60                 :                : 
                                 61                 :                : static int
 3413 andrew@dunslane.net        62                 :           1098 : gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 63                 :                : {
 5431 peter_e@gmx.net            64                 :           1098 :     float4KEY  *ia = (float4KEY *) (((const Nsrt *) a)->t);
                                 65                 :           1098 :     float4KEY  *ib = (float4KEY *) (((const Nsrt *) b)->t);
                                 66                 :                :     int         res;
                                 67                 :                : 
   24 tgl@sss.pgh.pa.us          68                 :           1098 :     res = float4_cmp_internal(ia->lower, ib->lower);
                                 69         [ +  - ]:           1098 :     if (res != 0)
                                 70                 :           1098 :         return res;
   24 tgl@sss.pgh.pa.us          71                 :UBC           0 :     return float4_cmp_internal(ia->upper, ib->upper);
                                 72                 :                : }
                                 73                 :                : 
                                 74                 :                : static float8
 3413 andrew@dunslane.net        75                 :CBC         276 : gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 76                 :                : {
   24 tgl@sss.pgh.pa.us          77                 :            276 :     float8      arg1 = *(const float4 *) a;
                                 78                 :            276 :     float8      arg2 = *(const float4 *) b;
                                 79                 :                :     float8      r;
                                 80                 :                : 
                                 81                 :            276 :     r = arg1 - arg2;
                                 82                 :                :     /* needn't consider isinf case here, must be due to input infinity */
                                 83         [ -  + ]:            276 :     if (unlikely(isnan(r)))
                                 84                 :                :     {
   24 tgl@sss.pgh.pa.us          85   [ #  #  #  # ]:UBC           0 :         if (isnan(arg1) && isnan(arg2))
                                 86                 :              0 :             r = 0.0;            /* treat NaNs as equal */
                                 87   [ #  #  #  # ]:              0 :         else if (isnan(arg1) || isnan(arg2))
                                 88                 :              0 :             r = get_float8_infinity();  /* max dist for NaN vs non-NaN */
                                 89                 :                :         else
                                 90                 :              0 :             r = 0.0;            /* must be Inf - Inf case */
                                 91                 :                :     }
   24 tgl@sss.pgh.pa.us          92                 :CBC         276 :     return fabs(r);
                                 93                 :                : }
                                 94                 :                : 
                                 95                 :                : 
                                 96                 :                : static const gbtree_ninfo tinfo =
                                 97                 :                : {
                                 98                 :                :     gbt_t_float4,
                                 99                 :                :     sizeof(float4),
                                100                 :                :     8,                          /* sizeof(gbtreekey8) */
                                101                 :                :     gbt_float4gt,
                                102                 :                :     gbt_float4ge,
                                103                 :                :     gbt_float4eq,
                                104                 :                :     gbt_float4le,
                                105                 :                :     gbt_float4lt,
                                106                 :                :     gbt_float4key_cmp,
                                107                 :                :     gbt_float4_dist
                                108                 :                : };
                                109                 :                : 
                                110                 :                : 
 5624                           111                 :              4 : PG_FUNCTION_INFO_V1(float4_dist);
                                112                 :                : Datum
                                113                 :            553 : float4_dist(PG_FUNCTION_ARGS)
                                114                 :                : {
 5585 bruce@momjian.us          115                 :            553 :     float4      a = PG_GETARG_FLOAT4(0);
 5624 tgl@sss.pgh.pa.us         116                 :            553 :     float4      b = PG_GETARG_FLOAT4(1);
                                117                 :                :     float4      r;
                                118                 :                : 
                                119                 :            553 :     r = a - b;
 1801 michael@paquier.xyz       120   [ +  +  -  +  :            553 :     if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
                                              -  - ]
 1801 michael@paquier.xyz       121                 :UBC           0 :         float_overflow_error();
   24 tgl@sss.pgh.pa.us         122         [ +  + ]:CBC         553 :     if (unlikely(isnan(r)))
                                123                 :                :     {
                                124   [ +  -  -  + ]:              1 :         if (isnan(a) && isnan(b))
   24 tgl@sss.pgh.pa.us         125                 :UBC           0 :             r = 0.0;            /* treat NaNs as equal */
   24 tgl@sss.pgh.pa.us         126   [ -  +  -  - ]:CBC           1 :         else if (isnan(a) || isnan(b))
                                127                 :              1 :             r = get_float4_infinity();  /* max dist for NaN vs non-NaN */
                                128                 :                :         else
   24 tgl@sss.pgh.pa.us         129                 :UBC           0 :             r = 0.0;            /* must be Inf - Inf case */
                                130                 :                :     }
 1386 peter@eisentraut.org      131                 :CBC         553 :     PG_RETURN_FLOAT4(fabsf(r));
                                132                 :                : }
                                133                 :                : 
                                134                 :                : 
                                135                 :                : /**************************************************
                                136                 :                :  * GiST support functions
                                137                 :                :  **************************************************/
                                138                 :                : 
                                139                 :                : Datum
 8093 teodor@sigaev.ru          140                 :           1658 : gbt_float4_compress(PG_FUNCTION_ARGS)
                                141                 :                : {
 8000 bruce@momjian.us          142                 :           1658 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                143                 :                : 
 4139 heikki.linnakangas@i      144                 :           1658 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                145                 :                : }
                                146                 :                : 
                                147                 :                : Datum
 4138                           148                 :            275 : gbt_float4_fetch(PG_FUNCTION_ARGS)
                                149                 :                : {
                                150                 :            275 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                151                 :                : 
                                152                 :            275 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                153                 :                : }
                                154                 :                : 
                                155                 :                : Datum
 8093 teodor@sigaev.ru          156                 :           2215 : gbt_float4_consistent(PG_FUNCTION_ARGS)
                                157                 :                : {
 8000 bruce@momjian.us          158                 :           2215 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                159                 :           2215 :     float4      query = PG_GETARG_FLOAT4(1);
 6676 tgl@sss.pgh.pa.us         160                 :           2215 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                161                 :                : #ifdef NOT_USED
                                162                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                163                 :                : #endif
                                164                 :           2215 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 8000 bruce@momjian.us          165                 :           2215 :     float4KEY  *kkk = (float4KEY *) DatumGetPointer(entry->key);
                                166                 :                :     GBT_NUMKEY_R key;
                                167                 :                : 
                                168                 :                :     /* All cases served by this function are exact */
 6676 tgl@sss.pgh.pa.us         169                 :           2215 :     *recheck = false;
                                170                 :                : 
 6253 bruce@momjian.us          171                 :           2215 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                172                 :           2215 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                173                 :                : 
   22 tgl@sss.pgh.pa.us         174                 :GNC        2215 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
                                175                 :                :                                       GIST_LEAF(entry), &tinfo,
                                176                 :                :                                       fcinfo->flinfo));
                                177                 :                : }
                                178                 :                : 
                                179                 :                : Datum
 5624 tgl@sss.pgh.pa.us         180                 :CBC         277 : gbt_float4_distance(PG_FUNCTION_ARGS)
                                181                 :                : {
                                182                 :            277 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                183                 :            277 :     float4      query = PG_GETARG_FLOAT4(1);
                                184                 :                : #ifdef NOT_USED
                                185                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                186                 :                : #endif
                                187                 :            277 :     float4KEY  *kkk = (float4KEY *) DatumGetPointer(entry->key);
                                188                 :                :     GBT_NUMKEY_R key;
                                189                 :                : 
                                190                 :            277 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                191                 :            277 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                192                 :                : 
  604 peter@eisentraut.org      193                 :            277 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
                                194                 :                :                                       &tinfo, fcinfo->flinfo));
                                195                 :                : }
                                196                 :                : 
                                197                 :                : Datum
 8093 teodor@sigaev.ru          198                 :              7 : gbt_float4_union(PG_FUNCTION_ARGS)
                                199                 :                : {
 8000 bruce@momjian.us          200                 :              7 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                201                 :              7 :     void       *out = palloc(sizeof(float4KEY));
                                202                 :                : 
                                203                 :              7 :     *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
  604 peter@eisentraut.org      204                 :              7 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                205                 :                : }
                                206                 :                : 
                                207                 :                : Datum
 8093 teodor@sigaev.ru          208                 :            550 : gbt_float4_penalty(PG_FUNCTION_ARGS)
                                209                 :                : {
 8000 bruce@momjian.us          210                 :            550 :     float4KEY  *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                211                 :            550 :     float4KEY  *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                212                 :            550 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                213                 :                : 
   24 tgl@sss.pgh.pa.us         214                 :            550 :     float_penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                215                 :                : 
 8000 bruce@momjian.us          216                 :            550 :     PG_RETURN_POINTER(result);
                                217                 :                : }
                                218                 :                : 
                                219                 :                : Datum
 8093 teodor@sigaev.ru          220                 :              2 : gbt_float4_picksplit(PG_FUNCTION_ARGS)
                                221                 :                : {
 2368 alvherre@alvh.no-ip.      222                 :              2 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                223                 :                :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                224                 :                :                                         &tinfo, fcinfo->flinfo));
                                225                 :                : }
                                226                 :                : 
                                227                 :                : Datum
 8093 teodor@sigaev.ru          228                 :              1 : gbt_float4_same(PG_FUNCTION_ARGS)
                                229                 :                : {
 8000 bruce@momjian.us          230                 :              1 :     float4KEY  *b1 = (float4KEY *) PG_GETARG_POINTER(0);
                                231                 :              1 :     float4KEY  *b2 = (float4KEY *) PG_GETARG_POINTER(1);
                                232                 :              1 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                233                 :                : 
 3413 andrew@dunslane.net       234                 :              1 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 8000 bruce@momjian.us          235                 :              1 :     PG_RETURN_POINTER(result);
                                236                 :                : }
                                237                 :                : 
                                238                 :                : static int
  478 heikki.linnakangas@i      239                 :          10276 : gbt_float4_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                240                 :                : {
                                241                 :          10276 :     float4KEY  *arg1 = (float4KEY *) DatumGetPointer(x);
                                242                 :          10276 :     float4KEY  *arg2 = (float4KEY *) DatumGetPointer(y);
                                243                 :                : 
                                244                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                245                 :          10276 :     return float4_cmp_internal(arg1->lower, arg2->lower);
                                246                 :                : }
                                247                 :                : 
                                248                 :                : Datum
                                249                 :              4 : gbt_float4_sortsupport(PG_FUNCTION_ARGS)
                                250                 :                : {
                                251                 :              4 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                252                 :                : 
                                253                 :              4 :     ssup->comparator = gbt_float4_ssup_cmp;
                                254                 :              4 :     ssup->ssup_extra = NULL;
                                255                 :                : 
                                256                 :              4 :     PG_RETURN_VOID();
                                257                 :                : }
        

Generated by: LCOV version 2.0-1