LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_int2.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 84.8 % 92 78 14 78
Current Date: 2025-09-06 07:49:51 +0900 Functions: 92.9 % 28 26 2 26
Baseline: lcov-20250906-005545-baseline Branches: 41.7 % 24 10 14 10
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 16 16 16
(360..) days: 81.6 % 76 62 14 62
Function coverage date bins:
(30,360] days: 100.0 % 3 3 3
(360..) days: 92.0 % 25 23 2 23
Branch coverage date bins:
(30,360] days: 100.0 % 4 4 4
(360..) days: 30.0 % 20 6 14 6

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * contrib/btree_gist/btree_int2.c
                                  3                 :                :  */
                                  4                 :                : #include "postgres.h"
                                  5                 :                : 
                                  6                 :                : #include "btree_gist.h"
                                  7                 :                : #include "btree_utils_num.h"
                                  8                 :                : #include "common/int.h"
                                  9                 :                : #include "utils/rel.h"
                                 10                 :                : #include "utils/sortsupport.h"
                                 11                 :                : 
                                 12                 :                : typedef struct int16key
                                 13                 :                : {
                                 14                 :                :     int16       lower;
                                 15                 :                :     int16       upper;
                                 16                 :                : } int16KEY;
                                 17                 :                : 
                                 18                 :                : /* GiST support functions */
 7771 teodor@sigaev.ru           19                 :CBC           4 : PG_FUNCTION_INFO_V1(gbt_int2_compress);
 3816 heikki.linnakangas@i       20                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_fetch);
 7771 teodor@sigaev.ru           21                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_union);
                                 22                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_picksplit);
                                 23                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_consistent);
 5302 tgl@sss.pgh.pa.us          24                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_distance);
 7771 teodor@sigaev.ru           25                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_penalty);
                                 26                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_same);
  156 heikki.linnakangas@i       27                 :              4 : PG_FUNCTION_INFO_V1(gbt_int2_sortsupport);
                                 28                 :                : 
                                 29                 :                : 
                                 30                 :                : static bool
 3091 andrew@dunslane.net        31                 :           1635 : gbt_int2gt(const void *a, const void *b, FmgrInfo *flinfo)
                                 32                 :                : {
 5109 peter_e@gmx.net            33                 :           1635 :     return (*((const int16 *) a) > *((const int16 *) b));
                                 34                 :                : }
                                 35                 :                : static bool
 3091 andrew@dunslane.net        36                 :            576 : gbt_int2ge(const void *a, const void *b, FmgrInfo *flinfo)
                                 37                 :                : {
 5109 peter_e@gmx.net            38                 :            576 :     return (*((const int16 *) a) >= *((const int16 *) b));
                                 39                 :                : }
                                 40                 :                : static bool
 3091 andrew@dunslane.net        41                 :            273 : gbt_int2eq(const void *a, const void *b, FmgrInfo *flinfo)
                                 42                 :                : {
 5109 peter_e@gmx.net            43                 :            273 :     return (*((const int16 *) a) == *((const int16 *) b));
                                 44                 :                : }
                                 45                 :                : static bool
 3091 andrew@dunslane.net        46                 :            556 : gbt_int2le(const void *a, const void *b, FmgrInfo *flinfo)
                                 47                 :                : {
 5109 peter_e@gmx.net            48                 :            556 :     return (*((const int16 *) a) <= *((const int16 *) b));
                                 49                 :                : }
                                 50                 :                : static bool
 3091 andrew@dunslane.net        51                 :           1362 : gbt_int2lt(const void *a, const void *b, FmgrInfo *flinfo)
                                 52                 :                : {
 5109 peter_e@gmx.net            53                 :           1362 :     return (*((const int16 *) a) < *((const int16 *) b));
                                 54                 :                : }
                                 55                 :                : 
                                 56                 :                : static int
 3091 andrew@dunslane.net        57                 :            545 : gbt_int2key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 58                 :                : {
 5109 peter_e@gmx.net            59                 :            545 :     int16KEY   *ia = (int16KEY *) (((const Nsrt *) a)->t);
                                 60                 :            545 :     int16KEY   *ib = (int16KEY *) (((const Nsrt *) b)->t);
                                 61                 :                : 
 5757 teodor@sigaev.ru           62         [ +  + ]:            545 :     if (ia->lower == ib->lower)
                                 63                 :                :     {
                                 64         [ +  - ]:             14 :         if (ia->upper == ib->upper)
                                 65                 :             14 :             return 0;
                                 66                 :                : 
 5757 teodor@sigaev.ru           67         [ #  # ]:UBC           0 :         return (ia->upper > ib->upper) ? 1 : -1;
                                 68                 :                :     }
                                 69                 :                : 
 5757 teodor@sigaev.ru           70         [ -  + ]:CBC         531 :     return (ia->lower > ib->lower) ? 1 : -1;
                                 71                 :                : }
                                 72                 :                : 
                                 73                 :                : static float8
 3091 andrew@dunslane.net        74                 :            274 : gbt_int2_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 75                 :                : {
 4821 peter_e@gmx.net            76                 :            274 :     return GET_FLOAT_DISTANCE(int16, a, b);
                                 77                 :                : }
                                 78                 :                : 
                                 79                 :                : 
                                 80                 :                : static const gbtree_ninfo tinfo =
                                 81                 :                : {
                                 82                 :                :     gbt_t_int2,
                                 83                 :                :     sizeof(int16),
                                 84                 :                :     4,                          /* sizeof(gbtreekey4) */
                                 85                 :                :     gbt_int2gt,
                                 86                 :                :     gbt_int2ge,
                                 87                 :                :     gbt_int2eq,
                                 88                 :                :     gbt_int2le,
                                 89                 :                :     gbt_int2lt,
                                 90                 :                :     gbt_int2key_cmp,
                                 91                 :                :     gbt_int2_dist
                                 92                 :                : };
                                 93                 :                : 
                                 94                 :                : 
 5302 tgl@sss.pgh.pa.us          95                 :              4 : PG_FUNCTION_INFO_V1(int2_dist);
                                 96                 :                : Datum
                                 97                 :            549 : int2_dist(PG_FUNCTION_ARGS)
                                 98                 :                : {
 4821 peter_e@gmx.net            99                 :            549 :     int16       a = PG_GETARG_INT16(0);
                                100                 :            549 :     int16       b = PG_GETARG_INT16(1);
                                101                 :                :     int16       r;
                                102                 :                :     int16       ra;
                                103                 :                : 
 2825 andres@anarazel.de        104         [ +  - ]:            549 :     if (pg_sub_s16_overflow(a, b, &r) ||
                                105         [ -  + ]:            549 :         r == PG_INT16_MIN)
 5302 tgl@sss.pgh.pa.us         106         [ #  # ]:UBC           0 :         ereport(ERROR,
                                107                 :                :                 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                108                 :                :                  errmsg("smallint out of range")));
                                109                 :                : 
 1065 peter@eisentraut.org      110                 :CBC         549 :     ra = abs(r);
                                111                 :                : 
 5302 tgl@sss.pgh.pa.us         112                 :            549 :     PG_RETURN_INT16(ra);
                                113                 :                : }
                                114                 :                : 
                                115                 :                : 
                                116                 :                : /**************************************************
                                117                 :                :  * GiST support functions
                                118                 :                :  **************************************************/
                                119                 :                : 
                                120                 :                : Datum
 7771 teodor@sigaev.ru          121                 :            548 : gbt_int2_compress(PG_FUNCTION_ARGS)
                                122                 :                : {
 7678 bruce@momjian.us          123                 :            548 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                124                 :                : 
 3817 heikki.linnakangas@i      125                 :            548 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                126                 :                : }
                                127                 :                : 
                                128                 :                : Datum
 3816                           129                 :            273 : gbt_int2_fetch(PG_FUNCTION_ARGS)
                                130                 :                : {
                                131                 :            273 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                132                 :                : 
                                133                 :            273 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                134                 :                : }
                                135                 :                : 
                                136                 :                : Datum
 7771 teodor@sigaev.ru          137                 :           1921 : gbt_int2_consistent(PG_FUNCTION_ARGS)
                                138                 :                : {
 7678 bruce@momjian.us          139                 :           1921 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                140                 :           1921 :     int16       query = PG_GETARG_INT16(1);
 6354 tgl@sss.pgh.pa.us         141                 :           1921 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                142                 :                : 
                                143                 :                :     /* Oid      subtype = PG_GETARG_OID(3); */
                                144                 :           1921 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 7678 bruce@momjian.us          145                 :           1921 :     int16KEY   *kkk = (int16KEY *) DatumGetPointer(entry->key);
                                146                 :                :     GBT_NUMKEY_R key;
                                147                 :                : 
                                148                 :                :     /* All cases served by this function are exact */
 6354 tgl@sss.pgh.pa.us         149                 :           1921 :     *recheck = false;
                                150                 :                : 
 5931 bruce@momjian.us          151                 :           1921 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                152                 :           1921 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                153                 :                : 
  282 peter@eisentraut.org      154                 :           1921 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
                                155                 :                :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                156                 :                : }
                                157                 :                : 
                                158                 :                : Datum
 5302 tgl@sss.pgh.pa.us         159                 :            275 : gbt_int2_distance(PG_FUNCTION_ARGS)
                                160                 :                : {
                                161                 :            275 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                162                 :            275 :     int16       query = PG_GETARG_INT16(1);
                                163                 :                : 
                                164                 :                :     /* Oid      subtype = PG_GETARG_OID(3); */
                                165                 :            275 :     int16KEY   *kkk = (int16KEY *) DatumGetPointer(entry->key);
                                166                 :                :     GBT_NUMKEY_R key;
                                167                 :                : 
                                168                 :            275 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                169                 :            275 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                170                 :                : 
  282 peter@eisentraut.org      171                 :            275 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
                                172                 :                :                                       &tinfo, fcinfo->flinfo));
                                173                 :                : }
                                174                 :                : 
                                175                 :                : Datum
 7771 teodor@sigaev.ru          176                 :              1 : gbt_int2_union(PG_FUNCTION_ARGS)
                                177                 :                : {
 7678 bruce@momjian.us          178                 :              1 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                179                 :              1 :     void       *out = palloc(sizeof(int16KEY));
                                180                 :                : 
                                181                 :              1 :     *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
  282 peter@eisentraut.org      182                 :              1 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                183                 :                : }
                                184                 :                : 
                                185                 :                : Datum
 7771 teodor@sigaev.ru          186                 :UBC           0 : gbt_int2_penalty(PG_FUNCTION_ARGS)
                                187                 :                : {
 7678 bruce@momjian.us          188                 :              0 :     int16KEY   *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
 7266                           189                 :              0 :     int16KEY   *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                190                 :              0 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                191                 :                : 
                                192   [ #  #  #  #  :              0 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                              #  # ]
                                193                 :                : 
 7678                           194                 :              0 :     PG_RETURN_POINTER(result);
                                195                 :                : }
                                196                 :                : 
                                197                 :                : Datum
 7771 teodor@sigaev.ru          198                 :CBC           1 : gbt_int2_picksplit(PG_FUNCTION_ARGS)
                                199                 :                : {
 2046 alvherre@alvh.no-ip.      200                 :              1 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                201                 :                :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                202                 :                :                                         &tinfo, fcinfo->flinfo));
                                203                 :                : }
                                204                 :                : 
                                205                 :                : Datum
 7771 teodor@sigaev.ru          206                 :UBC           0 : gbt_int2_same(PG_FUNCTION_ARGS)
                                207                 :                : {
 7678 bruce@momjian.us          208                 :              0 :     int16KEY   *b1 = (int16KEY *) PG_GETARG_POINTER(0);
                                209                 :              0 :     int16KEY   *b2 = (int16KEY *) PG_GETARG_POINTER(1);
                                210                 :              0 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                211                 :                : 
 3091 andrew@dunslane.net       212                 :              0 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 7678 bruce@momjian.us          213                 :              0 :     PG_RETURN_POINTER(result);
                                214                 :                : }
                                215                 :                : 
                                216                 :                : static int
  156 heikki.linnakangas@i      217                 :CBC        5074 : gbt_int2_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                218                 :                : {
                                219                 :           5074 :     int16KEY   *arg1 = (int16KEY *) DatumGetPointer(x);
                                220                 :           5074 :     int16KEY   *arg2 = (int16KEY *) DatumGetPointer(y);
                                221                 :                : 
                                222                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                223         [ +  + ]:           5074 :     if (arg1->lower < arg2->lower)
                                224                 :           2356 :         return -1;
                                225         [ +  + ]:           2718 :     else if (arg1->lower > arg2->lower)
                                226                 :           2703 :         return 1;
                                227                 :                :     else
                                228                 :             15 :         return 0;
                                229                 :                : }
                                230                 :                : 
                                231                 :                : Datum
                                232                 :              1 : gbt_int2_sortsupport(PG_FUNCTION_ARGS)
                                233                 :                : {
                                234                 :              1 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                235                 :                : 
                                236                 :              1 :     ssup->comparator = gbt_int2_ssup_cmp;
                                237                 :              1 :     PG_RETURN_VOID();
                                238                 :                : }
        

Generated by: LCOV version 2.4-beta