LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_float8.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: 77aeca80249c9e640c811e80633a2e334a9320de vs 38afc3dcb25c45b744d4025029ce0a6c90b7059f Lines: 90.4 % 104 94 10 1 93 1
Current Date: 2026-07-25 19:08:27 +0900 Functions: 100.0 % 28 28 1 27
Baseline: lcov-20260725-baseline Branches: 41.2 % 34 14 20 14
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: 65.2 % 23 15 8 1 14
(360..) days: 97.5 % 81 79 2 79
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: 58.3 % 12 7 5 7

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * contrib/btree_gist/btree_float8.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 float8key
                                 13                 :                : {
                                 14                 :                :     float8      lower;
                                 15                 :                :     float8      upper;
                                 16                 :                : } float8KEY;
                                 17                 :                : 
                                 18                 :                : /* GiST support functions */
 8093 teodor@sigaev.ru           19                 :CBC           4 : PG_FUNCTION_INFO_V1(gbt_float8_compress);
 4138 heikki.linnakangas@i       20                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_fetch);
 8093 teodor@sigaev.ru           21                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_union);
                                 22                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_picksplit);
                                 23                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_consistent);
 5624 tgl@sss.pgh.pa.us          24                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_distance);
 8093 teodor@sigaev.ru           25                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_penalty);
                                 26                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_same);
  478 heikki.linnakangas@i       27                 :              4 : PG_FUNCTION_INFO_V1(gbt_float8_sortsupport);
                                 28                 :                : 
                                 29                 :                : 
                                 30                 :                : /*
                                 31                 :                :  * Use the NaN-aware comparators from utils/float.h, so that our results
                                 32                 :                :  * will agree with standard btree indexes.  Note that penalty and distance
                                 33                 :                :  * functions below must also cope with NaNs, in particular with the policy
                                 34                 :                :  * that all NaNs are equal.
                                 35                 :                :  */
                                 36                 :                : static bool
 3413 andrew@dunslane.net        37                 :           5994 : gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
                                 38                 :                : {
   24 tgl@sss.pgh.pa.us          39                 :           5994 :     return float8_gt(*((const float8 *) a), *((const float8 *) b));
                                 40                 :                : }
                                 41                 :                : static bool
 3413 andrew@dunslane.net        42                 :            792 : gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
                                 43                 :                : {
   24 tgl@sss.pgh.pa.us          44                 :            792 :     return float8_ge(*((const float8 *) a), *((const float8 *) b));
                                 45                 :                : }
                                 46                 :                : static bool
 3413 andrew@dunslane.net        47                 :            416 : gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
                                 48                 :                : {
   24 tgl@sss.pgh.pa.us          49                 :            416 :     return float8_eq(*((const float8 *) a), *((const float8 *) b));
                                 50                 :                : }
                                 51                 :                : static bool
 3413 andrew@dunslane.net        52                 :            558 : gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
                                 53                 :                : {
   24 tgl@sss.pgh.pa.us          54                 :            558 :     return float8_le(*((const float8 *) a), *((const float8 *) b));
                                 55                 :                : }
                                 56                 :                : static bool
 3413 andrew@dunslane.net        57                 :           5720 : gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
                                 58                 :                : {
   24 tgl@sss.pgh.pa.us          59                 :           5720 :     return float8_lt(*((const float8 *) a), *((const float8 *) b));
                                 60                 :                : }
                                 61                 :                : 
                                 62                 :                : static int
 3413 andrew@dunslane.net        63                 :           1637 : gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 64                 :                : {
 5431 peter_e@gmx.net            65                 :           1637 :     float8KEY  *ia = (float8KEY *) (((const Nsrt *) a)->t);
                                 66                 :           1637 :     float8KEY  *ib = (float8KEY *) (((const Nsrt *) b)->t);
                                 67                 :                :     int         res;
                                 68                 :                : 
   24 tgl@sss.pgh.pa.us          69                 :           1637 :     res = float8_cmp_internal(ia->lower, ib->lower);
                                 70         [ +  - ]:           1637 :     if (res != 0)
                                 71                 :           1637 :         return res;
   24 tgl@sss.pgh.pa.us          72                 :UBC           0 :     return float8_cmp_internal(ia->upper, ib->upper);
                                 73                 :                : }
                                 74                 :                : 
                                 75                 :                : static float8
 3413 andrew@dunslane.net        76                 :CBC         274 : gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 77                 :                : {
 5585 bruce@momjian.us           78                 :            274 :     float8      arg1 = *(const float8 *) a;
                                 79                 :            274 :     float8      arg2 = *(const float8 *) b;
                                 80                 :                :     float8      r;
                                 81                 :                : 
 5624 tgl@sss.pgh.pa.us          82                 :            274 :     r = arg1 - arg2;
 1801 michael@paquier.xyz        83   [ +  +  +  -  :            274 :     if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
                                              -  + ]
 1801 michael@paquier.xyz        84                 :UBC           0 :         float_overflow_error();
   24 tgl@sss.pgh.pa.us          85         [ -  + ]:CBC         274 :     if (unlikely(isnan(r)))
                                 86                 :                :     {
   24 tgl@sss.pgh.pa.us          87   [ #  #  #  # ]:UBC           0 :         if (isnan(arg1) && isnan(arg2))
                                 88                 :              0 :             r = 0.0;            /* treat NaNs as equal */
                                 89   [ #  #  #  # ]:              0 :         else if (isnan(arg1) || isnan(arg2))
                                 90                 :              0 :             r = get_float8_infinity();  /* max dist for NaN vs non-NaN */
                                 91                 :                :         else
                                 92                 :              0 :             r = 0.0;            /* must be Inf - Inf case */
                                 93                 :                :     }
 1387 peter@eisentraut.org       94                 :CBC         274 :     return fabs(r);
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : 
                                 98                 :                : static const gbtree_ninfo tinfo =
                                 99                 :                : {
                                100                 :                :     gbt_t_float8,
                                101                 :                :     sizeof(float8),
                                102                 :                :     16,                         /* sizeof(gbtreekey16) */
                                103                 :                :     gbt_float8gt,
                                104                 :                :     gbt_float8ge,
                                105                 :                :     gbt_float8eq,
                                106                 :                :     gbt_float8le,
                                107                 :                :     gbt_float8lt,
                                108                 :                :     gbt_float8key_cmp,
                                109                 :                :     gbt_float8_dist
                                110                 :                : };
                                111                 :                : 
                                112                 :                : 
 5624 tgl@sss.pgh.pa.us         113                 :              4 : PG_FUNCTION_INFO_V1(float8_dist);
                                114                 :                : Datum
                                115                 :            550 : float8_dist(PG_FUNCTION_ARGS)
                                116                 :                : {
                                117                 :            550 :     float8      a = PG_GETARG_FLOAT8(0);
                                118                 :            550 :     float8      b = PG_GETARG_FLOAT8(1);
                                119                 :                :     float8      r;
                                120                 :                : 
                                121                 :            550 :     r = a - b;
 1801 michael@paquier.xyz       122   [ +  +  -  +  :            550 :     if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
                                              -  - ]
 1801 michael@paquier.xyz       123                 :UBC           0 :         float_overflow_error();
   24 tgl@sss.pgh.pa.us         124         [ +  + ]:CBC         550 :     if (unlikely(isnan(r)))
                                125                 :                :     {
                                126   [ +  -  -  + ]:              1 :         if (isnan(a) && isnan(b))
   24 tgl@sss.pgh.pa.us         127                 :UBC           0 :             r = 0.0;            /* treat NaNs as equal */
   24 tgl@sss.pgh.pa.us         128   [ -  +  -  - ]:CBC           1 :         else if (isnan(a) || isnan(b))
                                129                 :              1 :             r = get_float8_infinity();  /* max dist for NaN vs non-NaN */
                                130                 :                :         else
   24 tgl@sss.pgh.pa.us         131                 :UBC           0 :             r = 0.0;            /* must be Inf - Inf case */
                                132                 :                :     }
 1387 peter@eisentraut.org      133                 :CBC         550 :     PG_RETURN_FLOAT8(fabs(r));
                                134                 :                : }
                                135                 :                : 
                                136                 :                : 
                                137                 :                : /**************************************************
                                138                 :                :  * GiST support functions
                                139                 :                :  **************************************************/
                                140                 :                : 
                                141                 :                : Datum
 8093 teodor@sigaev.ru          142                 :           1653 : gbt_float8_compress(PG_FUNCTION_ARGS)
                                143                 :                : {
 8000 bruce@momjian.us          144                 :           1653 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                145                 :                : 
 4139 heikki.linnakangas@i      146                 :           1653 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                147                 :                : }
                                148                 :                : 
                                149                 :                : Datum
 4138                           150                 :            273 : gbt_float8_fetch(PG_FUNCTION_ARGS)
                                151                 :                : {
                                152                 :            273 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                153                 :                : 
                                154                 :            273 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                155                 :                : }
                                156                 :                : 
                                157                 :                : Datum
 8093 teodor@sigaev.ru          158                 :           2067 : gbt_float8_consistent(PG_FUNCTION_ARGS)
                                159                 :                : {
 8000 bruce@momjian.us          160                 :           2067 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                161                 :           2067 :     float8      query = PG_GETARG_FLOAT8(1);
 6676 tgl@sss.pgh.pa.us         162                 :           2067 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                163                 :                : #ifdef NOT_USED
                                164                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                165                 :                : #endif
                                166                 :           2067 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 8000 bruce@momjian.us          167                 :           2067 :     float8KEY  *kkk = (float8KEY *) DatumGetPointer(entry->key);
                                168                 :                :     GBT_NUMKEY_R key;
                                169                 :                : 
                                170                 :                :     /* All cases served by this function are exact */
 6676 tgl@sss.pgh.pa.us         171                 :           2067 :     *recheck = false;
                                172                 :                : 
 6253 bruce@momjian.us          173                 :           2067 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                174                 :           2067 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                175                 :                : 
   22 tgl@sss.pgh.pa.us         176                 :GNC        2067 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
                                177                 :                :                                       GIST_LEAF(entry), &tinfo,
                                178                 :                :                                       fcinfo->flinfo));
                                179                 :                : }
                                180                 :                : 
                                181                 :                : Datum
 5624 tgl@sss.pgh.pa.us         182                 :CBC         275 : gbt_float8_distance(PG_FUNCTION_ARGS)
                                183                 :                : {
                                184                 :            275 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                185                 :            275 :     float8      query = PG_GETARG_FLOAT8(1);
                                186                 :                : #ifdef NOT_USED
                                187                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                188                 :                : #endif
                                189                 :            275 :     float8KEY  *kkk = (float8KEY *) DatumGetPointer(entry->key);
                                190                 :                :     GBT_NUMKEY_R key;
                                191                 :                : 
                                192                 :            275 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                193                 :            275 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                194                 :                : 
  604 peter@eisentraut.org      195                 :            275 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
                                196                 :                :                                       &tinfo, fcinfo->flinfo));
                                197                 :                : }
                                198                 :                : 
                                199                 :                : Datum
 8093 teodor@sigaev.ru          200                 :             15 : gbt_float8_union(PG_FUNCTION_ARGS)
                                201                 :                : {
 8000 bruce@momjian.us          202                 :             15 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                203                 :             15 :     void       *out = palloc(sizeof(float8KEY));
                                204                 :                : 
                                205                 :             15 :     *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
  604 peter@eisentraut.org      206                 :             15 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                207                 :                : }
                                208                 :                : 
                                209                 :                : Datum
 8093 teodor@sigaev.ru          210                 :           1094 : gbt_float8_penalty(PG_FUNCTION_ARGS)
                                211                 :                : {
 8000 bruce@momjian.us          212                 :           1094 :     float8KEY  *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                213                 :           1094 :     float8KEY  *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                214                 :           1094 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                215                 :                : 
   24 tgl@sss.pgh.pa.us         216                 :           1094 :     float_penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                217                 :                : 
 8000 bruce@momjian.us          218                 :           1094 :     PG_RETURN_POINTER(result);
                                219                 :                : }
                                220                 :                : 
                                221                 :                : Datum
 8093 teodor@sigaev.ru          222                 :              4 : gbt_float8_picksplit(PG_FUNCTION_ARGS)
                                223                 :                : {
 2368 alvherre@alvh.no-ip.      224                 :              4 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                225                 :                :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                226                 :                :                                         &tinfo, fcinfo->flinfo));
                                227                 :                : }
                                228                 :                : 
                                229                 :                : Datum
 8093 teodor@sigaev.ru          230                 :              3 : gbt_float8_same(PG_FUNCTION_ARGS)
                                231                 :                : {
 8000 bruce@momjian.us          232                 :              3 :     float8KEY  *b1 = (float8KEY *) PG_GETARG_POINTER(0);
                                233                 :              3 :     float8KEY  *b2 = (float8KEY *) PG_GETARG_POINTER(1);
                                234                 :              3 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                235                 :                : 
 3413 andrew@dunslane.net       236                 :              3 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 8000 bruce@momjian.us          237                 :              3 :     PG_RETURN_POINTER(result);
                                238                 :                : }
                                239                 :                : 
                                240                 :                : static int
  478 heikki.linnakangas@i      241                 :          10432 : gbt_float8_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                242                 :                : {
                                243                 :          10432 :     float8KEY  *arg1 = (float8KEY *) DatumGetPointer(x);
                                244                 :          10432 :     float8KEY  *arg2 = (float8KEY *) DatumGetPointer(y);
                                245                 :                : 
                                246                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                247                 :          10432 :     return float8_cmp_internal(arg1->lower, arg2->lower);
                                248                 :                : }
                                249                 :                : 
                                250                 :                : Datum
                                251                 :              4 : gbt_float8_sortsupport(PG_FUNCTION_ARGS)
                                252                 :                : {
                                253                 :              4 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                254                 :                : 
                                255                 :              4 :     ssup->comparator = gbt_float8_ssup_cmp;
                                256                 :              4 :     ssup->ssup_extra = NULL;
                                257                 :                : 
                                258                 :              4 :     PG_RETURN_VOID();
                                259                 :                : }
        

Generated by: LCOV version 2.0-1