LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_bool.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 61.4 % 70 43
Test Date: 2026-07-03 19:57:34 Functions: 78.3 % 23 18
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 0.0 % 8 0

             Branch data     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 "utils/rel.h"
       9                 :             : #include "utils/sortsupport.h"
      10                 :             : 
      11                 :             : typedef struct boolkey
      12                 :             : {
      13                 :             :     bool        lower;
      14                 :             :     bool        upper;
      15                 :             : } boolKEY;
      16                 :             : 
      17                 :             : /* GiST support functions */
      18                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_compress);
      19                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_fetch);
      20                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_union);
      21                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_picksplit);
      22                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_consistent);
      23                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_penalty);
      24                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_same);
      25                 :           4 : PG_FUNCTION_INFO_V1(gbt_bool_sortsupport);
      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
      54                 :           0 : gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      55                 :             : {
      56                 :           0 :     boolKEY    *ia = (boolKEY *) (((const Nsrt *) a)->t);
      57                 :           0 :     boolKEY    *ib = (boolKEY *) (((const Nsrt *) b)->t);
      58                 :             : 
      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                 :             :  * GiST support functions
      87                 :             :  **************************************************/
      88                 :             : 
      89                 :             : Datum
      90                 :           2 : gbt_bool_compress(PG_FUNCTION_ARGS)
      91                 :             : {
      92                 :           2 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
      93                 :             : 
      94                 :           2 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
      95                 :             : }
      96                 :             : 
      97                 :             : Datum
      98                 :           7 : gbt_bool_fetch(PG_FUNCTION_ARGS)
      99                 :             : {
     100                 :           7 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     101                 :             : 
     102                 :           7 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     103                 :             : }
     104                 :             : 
     105                 :             : Datum
     106                 :          14 : gbt_bool_consistent(PG_FUNCTION_ARGS)
     107                 :             : {
     108                 :          14 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     109                 :          14 :     bool        query = PG_GETARG_INT16(1);
     110                 :          14 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     111                 :             : #ifdef NOT_USED
     112                 :             :     Oid         subtype = PG_GETARG_OID(3);
     113                 :             : #endif
     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, &query, strategy,
     125                 :             :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     126                 :             : }
     127                 :             : 
     128                 :             : Datum
     129                 :           0 : gbt_bool_union(PG_FUNCTION_ARGS)
     130                 :             : {
     131                 :           0 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     132                 :           0 :     void       *out = palloc(sizeof(boolKEY));
     133                 :             : 
     134                 :           0 :     *(int *) PG_GETARG_POINTER(1) = sizeof(boolKEY);
     135                 :           0 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
     136                 :             : }
     137                 :             : 
     138                 :             : Datum
     139                 :           0 : gbt_bool_penalty(PG_FUNCTION_ARGS)
     140                 :             : {
     141                 :           0 :     boolKEY    *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     142                 :           0 :     boolKEY    *newentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     143                 :           0 :     float      *result = (float *) PG_GETARG_POINTER(2);
     144                 :             : 
     145                 :           0 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     146                 :             : 
     147                 :           0 :     PG_RETURN_POINTER(result);
     148                 :             : }
     149                 :             : 
     150                 :             : Datum
     151                 :           0 : gbt_bool_picksplit(PG_FUNCTION_ARGS)
     152                 :             : {
     153                 :           0 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
     154                 :             :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
     155                 :             :                                         &tinfo, fcinfo->flinfo));
     156                 :             : }
     157                 :             : 
     158                 :             : Datum
     159                 :           0 : gbt_bool_same(PG_FUNCTION_ARGS)
     160                 :             : {
     161                 :           0 :     boolKEY    *b1 = (boolKEY *) PG_GETARG_POINTER(0);
     162                 :           0 :     boolKEY    *b2 = (boolKEY *) PG_GETARG_POINTER(1);
     163                 :           0 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     164                 :             : 
     165                 :           0 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     166                 :           0 :     PG_RETURN_POINTER(result);
     167                 :             : }
     168                 :             : 
     169                 :             : static int
     170                 :           1 : gbt_bool_ssup_cmp(Datum x, Datum y, SortSupport ssup)
     171                 :             : {
     172                 :           1 :     boolKEY    *arg1 = (boolKEY *) DatumGetPointer(x);
     173                 :           1 :     boolKEY    *arg2 = (boolKEY *) DatumGetPointer(y);
     174                 :             : 
     175                 :             :     /* for leaf items we expect lower == upper, so only compare lower */
     176                 :           1 :     return (int32) arg1->lower - (int32) arg2->lower;
     177                 :             : }
     178                 :             : 
     179                 :             : Datum
     180                 :           1 : gbt_bool_sortsupport(PG_FUNCTION_ARGS)
     181                 :             : {
     182                 :           1 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
     183                 :             : 
     184                 :           1 :     ssup->comparator = gbt_bool_ssup_cmp;
     185                 :           1 :     ssup->ssup_extra = NULL;
     186                 :             : 
     187                 :           1 :     PG_RETURN_VOID();
     188                 :             : }
        

Generated by: LCOV version 2.0-1