LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_oid.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 53.1 % 96 51 45 51
Current Date: 2025-09-06 07:49:51 +0900 Functions: 75.0 % 28 21 7 21
Baseline: lcov-20250906-005545-baseline Branches: 18.2 % 22 4 18 4
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: 76.5 % 17 13 4 13
(360..) days: 48.1 % 79 38 41 38
Function coverage date bins:
(30,360] days: 100.0 % 3 3 3
(360..) days: 72.0 % 25 18 7 18
Branch coverage date bins:
(30,360] days: 50.0 % 4 2 2 2
(360..) days: 11.1 % 18 2 16 2

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * contrib/btree_gist/btree_oid.c
                                  3                 :                :  */
                                  4                 :                : #include "postgres.h"
                                  5                 :                : 
                                  6                 :                : #include "btree_gist.h"
                                  7                 :                : #include "btree_utils_num.h"
                                  8                 :                : #include "utils/rel.h"
                                  9                 :                : #include "utils/sortsupport.h"
                                 10                 :                : 
                                 11                 :                : typedef struct
                                 12                 :                : {
                                 13                 :                :     Oid         lower;
                                 14                 :                :     Oid         upper;
                                 15                 :                : } oidKEY;
                                 16                 :                : 
                                 17                 :                : /* GiST support functions */
 7771 teodor@sigaev.ru           18                 :CBC           4 : PG_FUNCTION_INFO_V1(gbt_oid_compress);
 3816 heikki.linnakangas@i       19                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_fetch);
 7771 teodor@sigaev.ru           20                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_union);
                                 21                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
                                 22                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_consistent);
 5302 tgl@sss.pgh.pa.us          23                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_distance);
 7771 teodor@sigaev.ru           24                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_penalty);
                                 25                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_same);
  156 heikki.linnakangas@i       26                 :              4 : PG_FUNCTION_INFO_V1(gbt_oid_sortsupport);
                                 27                 :                : 
                                 28                 :                : 
                                 29                 :                : static bool
 3091 andrew@dunslane.net        30                 :           2244 : gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
                                 31                 :                : {
 5109 peter_e@gmx.net            32                 :           2244 :     return (*((const Oid *) a) > *((const Oid *) b));
                                 33                 :                : }
                                 34                 :                : static bool
 3091 andrew@dunslane.net        35                 :            258 : gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
                                 36                 :                : {
 5109 peter_e@gmx.net            37                 :            258 :     return (*((const Oid *) a) >= *((const Oid *) b));
                                 38                 :                : }
                                 39                 :                : static bool
 3091 andrew@dunslane.net        40                 :            250 : gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
                                 41                 :                : {
 5109 peter_e@gmx.net            42                 :            250 :     return (*((const Oid *) a) == *((const Oid *) b));
                                 43                 :                : }
                                 44                 :                : static bool
 3091 andrew@dunslane.net        45                 :           1013 : gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
                                 46                 :                : {
 5109 peter_e@gmx.net            47                 :           1013 :     return (*((const Oid *) a) <= *((const Oid *) b));
                                 48                 :                : }
                                 49                 :                : static bool
 3091 andrew@dunslane.net        50                 :           2994 : gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
                                 51                 :                : {
 5109 peter_e@gmx.net            52                 :           2994 :     return (*((const Oid *) a) < *((const Oid *) b));
                                 53                 :                : }
                                 54                 :                : 
                                 55                 :                : static int
 3091 andrew@dunslane.net        56                 :           1997 : gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 57                 :                : {
 5109 peter_e@gmx.net            58                 :           1997 :     oidKEY     *ia = (oidKEY *) (((const Nsrt *) a)->t);
                                 59                 :           1997 :     oidKEY     *ib = (oidKEY *) (((const Nsrt *) b)->t);
                                 60                 :                : 
 5757 teodor@sigaev.ru           61         [ -  + ]:           1997 :     if (ia->lower == ib->lower)
                                 62                 :                :     {
 5757 teodor@sigaev.ru           63         [ #  # ]:UBC           0 :         if (ia->upper == ib->upper)
                                 64                 :              0 :             return 0;
                                 65                 :                : 
                                 66         [ #  # ]:              0 :         return (ia->upper > ib->upper) ? 1 : -1;
                                 67                 :                :     }
                                 68                 :                : 
 5757 teodor@sigaev.ru           69         [ -  + ]:CBC        1997 :     return (ia->lower > ib->lower) ? 1 : -1;
                                 70                 :                : }
                                 71                 :                : 
                                 72                 :                : static float8
 3091 andrew@dunslane.net        73                 :UBC           0 : gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 74                 :                : {
 5302 tgl@sss.pgh.pa.us          75                 :              0 :     Oid         aa = *(const Oid *) a;
                                 76                 :              0 :     Oid         bb = *(const Oid *) b;
                                 77                 :                : 
                                 78         [ #  # ]:              0 :     if (aa < bb)
                                 79                 :              0 :         return (float8) (bb - aa);
                                 80                 :                :     else
                                 81                 :              0 :         return (float8) (aa - bb);
                                 82                 :                : }
                                 83                 :                : 
                                 84                 :                : 
                                 85                 :                : static const gbtree_ninfo tinfo =
                                 86                 :                : {
                                 87                 :                :     gbt_t_oid,
                                 88                 :                :     sizeof(Oid),
                                 89                 :                :     8,                          /* sizeof(gbtreekey8) */
                                 90                 :                :     gbt_oidgt,
                                 91                 :                :     gbt_oidge,
                                 92                 :                :     gbt_oideq,
                                 93                 :                :     gbt_oidle,
                                 94                 :                :     gbt_oidlt,
                                 95                 :                :     gbt_oidkey_cmp,
                                 96                 :                :     gbt_oid_dist
                                 97                 :                : };
                                 98                 :                : 
                                 99                 :                : 
 5302 tgl@sss.pgh.pa.us         100                 :CBC           3 : PG_FUNCTION_INFO_V1(oid_dist);
                                101                 :                : Datum
 5302 tgl@sss.pgh.pa.us         102                 :UBC           0 : oid_dist(PG_FUNCTION_ARGS)
                                103                 :                : {
 5263 bruce@momjian.us          104                 :              0 :     Oid         a = PG_GETARG_OID(0);
                                105                 :              0 :     Oid         b = PG_GETARG_OID(1);
                                106                 :                :     Oid         res;
                                107                 :                : 
 5302 tgl@sss.pgh.pa.us         108         [ #  # ]:              0 :     if (a < b)
                                109                 :              0 :         res = b - a;
                                110                 :                :     else
                                111                 :              0 :         res = a - b;
                                112                 :              0 :     PG_RETURN_OID(res);
                                113                 :                : }
                                114                 :                : 
                                115                 :                : 
                                116                 :                : /**************************************************
                                117                 :                :  * GiST support functions
                                118                 :                :  **************************************************/
                                119                 :                : 
                                120                 :                : Datum
 7771 teodor@sigaev.ru          121                 :CBC        1004 : gbt_oid_compress(PG_FUNCTION_ARGS)
                                122                 :                : {
 7678 bruce@momjian.us          123                 :           1004 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                124                 :                : 
 3817 heikki.linnakangas@i      125                 :           1004 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                126                 :                : }
                                127                 :                : 
                                128                 :                : Datum
 3816 heikki.linnakangas@i      129                 :UBC           0 : gbt_oid_fetch(PG_FUNCTION_ARGS)
                                130                 :                : {
                                131                 :              0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                132                 :                : 
                                133                 :              0 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                134                 :                : }
                                135                 :                : 
                                136                 :                : Datum
 7771 teodor@sigaev.ru          137                 :CBC        2770 : gbt_oid_consistent(PG_FUNCTION_ARGS)
                                138                 :                : {
 7678 bruce@momjian.us          139                 :           2770 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                140                 :           2770 :     Oid         query = PG_GETARG_OID(1);
 6354 tgl@sss.pgh.pa.us         141                 :           2770 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                142                 :                : 
                                143                 :                :     /* Oid      subtype = PG_GETARG_OID(3); */
                                144                 :           2770 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 7678 bruce@momjian.us          145                 :           2770 :     oidKEY     *kkk = (oidKEY *) 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                 :           2770 :     *recheck = false;
                                150                 :                : 
 5931 bruce@momjian.us          151                 :           2770 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                152                 :           2770 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                153                 :                : 
  282 peter@eisentraut.org      154                 :           2770 :     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                 :UBC           0 : gbt_oid_distance(PG_FUNCTION_ARGS)
                                160                 :                : {
                                161                 :              0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                162                 :              0 :     Oid         query = PG_GETARG_OID(1);
                                163                 :                : 
                                164                 :                :     /* Oid      subtype = PG_GETARG_OID(3); */
                                165                 :              0 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
                                166                 :                :     GBT_NUMKEY_R key;
                                167                 :                : 
                                168                 :              0 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                169                 :              0 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                170                 :                : 
  282 peter@eisentraut.org      171                 :              0 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
                                172                 :                :                                       &tinfo, fcinfo->flinfo));
                                173                 :                : }
                                174                 :                : 
                                175                 :                : Datum
 7771 teodor@sigaev.ru          176                 :              0 : gbt_oid_union(PG_FUNCTION_ARGS)
                                177                 :                : {
 7678 bruce@momjian.us          178                 :              0 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                179                 :              0 :     void       *out = palloc(sizeof(oidKEY));
                                180                 :                : 
                                181                 :              0 :     *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
  282 peter@eisentraut.org      182                 :              0 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                183                 :                : }
                                184                 :                : 
                                185                 :                : Datum
 7771 teodor@sigaev.ru          186                 :              0 : gbt_oid_penalty(PG_FUNCTION_ARGS)
                                187                 :                : {
 7678 bruce@momjian.us          188                 :              0 :     oidKEY     *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                189                 :              0 :     oidKEY     *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                190                 :              0 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                191                 :                : 
 7266                           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           3 : gbt_oid_picksplit(PG_FUNCTION_ARGS)
                                199                 :                : {
 2046 alvherre@alvh.no-ip.      200                 :              3 :     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_oid_same(PG_FUNCTION_ARGS)
                                207                 :                : {
 7678 bruce@momjian.us          208                 :              0 :     oidKEY     *b1 = (oidKEY *) PG_GETARG_POINTER(0);
                                209                 :              0 :     oidKEY     *b2 = (oidKEY *) 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         999 : gbt_oid_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                218                 :                : {
                                219                 :            999 :     oidKEY     *arg1 = (oidKEY *) DatumGetPointer(x);
                                220                 :            999 :     oidKEY     *arg2 = (oidKEY *) DatumGetPointer(y);
                                221                 :                : 
                                222                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                223         [ -  + ]:            999 :     if (arg1->lower > arg2->lower)
  156 heikki.linnakangas@i      224                 :UBC           0 :         return 1;
  156 heikki.linnakangas@i      225         [ +  - ]:CBC         999 :     else if (arg1->lower < arg2->lower)
                                226                 :            999 :         return -1;
                                227                 :                :     else
  156 heikki.linnakangas@i      228                 :UBC           0 :         return 0;
                                229                 :                : }
                                230                 :                : 
                                231                 :                : Datum
  156 heikki.linnakangas@i      232                 :CBC           1 : gbt_oid_sortsupport(PG_FUNCTION_ARGS)
                                233                 :                : {
                                234                 :              1 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                235                 :                : 
                                236                 :              1 :     ssup->comparator = gbt_oid_ssup_cmp;
                                237                 :              1 :     ssup->ssup_extra = NULL;
                                238                 :                : 
                                239                 :              1 :     PG_RETURN_VOID();
                                240                 :                : }
        

Generated by: LCOV version 2.4-beta