LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_bool.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 55.0 % 60 33 27 33
Current Date: 2023-04-08 17:13:01 Functions: 75.0 % 20 15 5 15
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 55.0 % 60 33 27 33
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 75.0 % 20 15 5 15

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * contrib/btree_gist/btree_bool.c
                                  3                 :  */
                                  4                 : #include "postgres.h"
                                  5                 : 
                                  6                 : #include "btree_gist.h"
                                  7                 : #include "btree_utils_num.h"
                                  8                 : #include "common/int.h"
                                  9                 : 
                                 10                 : typedef struct boolkey
                                 11                 : {
                                 12                 :     bool        lower;
                                 13                 :     bool        upper;
                                 14                 : } boolKEY;
                                 15                 : 
                                 16                 : /*
                                 17                 : ** bool ops
                                 18                 : */
  519 tomas.vondra               19 CBC           2 : PG_FUNCTION_INFO_V1(gbt_bool_compress);
                                 20               2 : PG_FUNCTION_INFO_V1(gbt_bool_fetch);
                                 21               2 : PG_FUNCTION_INFO_V1(gbt_bool_union);
                                 22               2 : PG_FUNCTION_INFO_V1(gbt_bool_picksplit);
                                 23               2 : PG_FUNCTION_INFO_V1(gbt_bool_consistent);
                                 24               2 : PG_FUNCTION_INFO_V1(gbt_bool_penalty);
                                 25               2 : PG_FUNCTION_INFO_V1(gbt_bool_same);
                                 26                 : 
                                 27                 : static bool
                                 28               2 : gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
                                 29                 : {
                                 30               2 :     return (*((const bool *) a) > *((const bool *) b));
                                 31                 : }
                                 32                 : static bool
                                 33               2 : gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
                                 34                 : {
                                 35               2 :     return (*((const bool *) a) >= *((const bool *) b));
                                 36                 : }
                                 37                 : static bool
                                 38               6 : gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
                                 39                 : {
                                 40               6 :     return (*((const bool *) a) == *((const bool *) b));
                                 41                 : }
                                 42                 : static bool
                                 43               2 : gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
                                 44                 : {
                                 45               2 :     return (*((const bool *) a) <= *((const bool *) b));
                                 46                 : }
                                 47                 : static bool
                                 48               2 : gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
                                 49                 : {
                                 50               2 :     return (*((const bool *) a) < *((const bool *) b));
                                 51                 : }
                                 52                 : 
                                 53                 : static int
  519 tomas.vondra               54 UBC           0 : gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 55                 : {
  332 tgl                        56               0 :     boolKEY    *ia = (boolKEY *) (((const Nsrt *) a)->t);
                                 57               0 :     boolKEY    *ib = (boolKEY *) (((const Nsrt *) b)->t);
                                 58                 : 
  519 tomas.vondra               59               0 :     if (ia->lower == ib->lower)
                                 60                 :     {
                                 61               0 :         if (ia->upper == ib->upper)
                                 62               0 :             return 0;
                                 63                 : 
                                 64               0 :         return (ia->upper > ib->upper) ? 1 : -1;
                                 65                 :     }
                                 66                 : 
                                 67               0 :     return (ia->lower > ib->lower) ? 1 : -1;
                                 68                 : }
                                 69                 : 
                                 70                 : 
                                 71                 : static const gbtree_ninfo tinfo =
                                 72                 : {
                                 73                 :     gbt_t_bool,
                                 74                 :     sizeof(bool),
                                 75                 :     2,                          /* sizeof(gbtreekey2) */
                                 76                 :     gbt_boolgt,
                                 77                 :     gbt_boolge,
                                 78                 :     gbt_booleq,
                                 79                 :     gbt_boolle,
                                 80                 :     gbt_boollt,
                                 81                 :     gbt_boolkey_cmp,
                                 82                 : };
                                 83                 : 
                                 84                 : 
                                 85                 : /**************************************************
                                 86                 :  * bool ops
                                 87                 :  **************************************************/
                                 88                 : 
                                 89                 : 
                                 90                 : Datum
  519 tomas.vondra               91 CBC           2 : gbt_bool_compress(PG_FUNCTION_ARGS)
                                 92                 : {
                                 93               2 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                 94                 : 
                                 95               2 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                 96                 : }
                                 97                 : 
                                 98                 : Datum
                                 99               7 : gbt_bool_fetch(PG_FUNCTION_ARGS)
                                100                 : {
                                101               7 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                102                 : 
                                103               7 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                104                 : }
                                105                 : 
                                106                 : Datum
                                107              14 : gbt_bool_consistent(PG_FUNCTION_ARGS)
                                108                 : {
                                109              14 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                110              14 :     bool        query = PG_GETARG_INT16(1);
                                111              14 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                112                 : 
                                113                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                114              14 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
                                115              14 :     boolKEY    *kkk = (boolKEY *) DatumGetPointer(entry->key);
                                116                 :     GBT_NUMKEY_R key;
                                117                 : 
                                118                 :     /* All cases served by this function are exact */
                                119              14 :     *recheck = false;
                                120                 : 
                                121              14 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                122              14 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                123                 : 
                                124              14 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
                                125                 :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                126                 : }
                                127                 : 
                                128                 : 
                                129                 : Datum
  519 tomas.vondra              130 UBC           0 : gbt_bool_union(PG_FUNCTION_ARGS)
                                131                 : {
                                132               0 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                133               0 :     void       *out = palloc(sizeof(boolKEY));
                                134                 : 
                                135               0 :     *(int *) PG_GETARG_POINTER(1) = sizeof(boolKEY);
                                136               0 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
                                137                 : }
                                138                 : 
                                139                 : 
                                140                 : Datum
                                141               0 : gbt_bool_penalty(PG_FUNCTION_ARGS)
                                142                 : {
                                143               0 :     boolKEY    *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                144               0 :     boolKEY    *newentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                145               0 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                146                 : 
                                147               0 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                148                 : 
                                149               0 :     PG_RETURN_POINTER(result);
                                150                 : }
                                151                 : 
                                152                 : Datum
                                153               0 : gbt_bool_picksplit(PG_FUNCTION_ARGS)
                                154                 : {
                                155               0 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                156                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                157                 :                                         &tinfo, fcinfo->flinfo));
                                158                 : }
                                159                 : 
                                160                 : Datum
                                161               0 : gbt_bool_same(PG_FUNCTION_ARGS)
                                162                 : {
                                163               0 :     boolKEY    *b1 = (boolKEY *) PG_GETARG_POINTER(0);
                                164               0 :     boolKEY    *b2 = (boolKEY *) PG_GETARG_POINTER(1);
                                165               0 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                166                 : 
                                167               0 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
                                168               0 :     PG_RETURN_POINTER(result);
                                169                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a