LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_bool.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 0.0 % 80 0
Test Date: 2026-01-26 10:56:24 Functions: 0.0 % 23 0
Legend: Lines:     hit not hit

            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            0 : PG_FUNCTION_INFO_V1(gbt_bool_compress);
      19            0 : PG_FUNCTION_INFO_V1(gbt_bool_fetch);
      20            0 : PG_FUNCTION_INFO_V1(gbt_bool_union);
      21            0 : PG_FUNCTION_INFO_V1(gbt_bool_picksplit);
      22            0 : PG_FUNCTION_INFO_V1(gbt_bool_consistent);
      23            0 : PG_FUNCTION_INFO_V1(gbt_bool_penalty);
      24            0 : PG_FUNCTION_INFO_V1(gbt_bool_same);
      25            0 : PG_FUNCTION_INFO_V1(gbt_bool_sortsupport);
      26              : 
      27              : static bool
      28            0 : gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
      29              : {
      30            0 :         return (*((const bool *) a) > *((const bool *) b));
      31              : }
      32              : static bool
      33            0 : gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
      34              : {
      35            0 :         return (*((const bool *) a) >= *((const bool *) b));
      36              : }
      37              : static bool
      38            0 : gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
      39              : {
      40            0 :         return (*((const bool *) a) == *((const bool *) b));
      41              : }
      42              : static bool
      43            0 : gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
      44              : {
      45            0 :         return (*((const bool *) a) <= *((const bool *) b));
      46              : }
      47              : static bool
      48            0 : gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
      49              : {
      50            0 :         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            0 : }
      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            0 : gbt_bool_compress(PG_FUNCTION_ARGS)
      91              : {
      92            0 :         GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
      93              : 
      94            0 :         PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
      95            0 : }
      96              : 
      97              : Datum
      98            0 : gbt_bool_fetch(PG_FUNCTION_ARGS)
      99              : {
     100            0 :         GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     101              : 
     102            0 :         PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     103            0 : }
     104              : 
     105              : Datum
     106            0 : gbt_bool_consistent(PG_FUNCTION_ARGS)
     107              : {
     108            0 :         GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     109            0 :         bool            query = PG_GETARG_INT16(1);
     110            0 :         StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     111              : #ifdef NOT_USED
     112              :         Oid                     subtype = PG_GETARG_OID(3);
     113              : #endif
     114            0 :         bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     115            0 :         boolKEY    *kkk = (boolKEY *) DatumGetPointer(entry->key);
     116            0 :         GBT_NUMKEY_R key;
     117              : 
     118              :         /* All cases served by this function are exact */
     119            0 :         *recheck = false;
     120              : 
     121            0 :         key.lower = (GBT_NUMKEY *) &kkk->lower;
     122            0 :         key.upper = (GBT_NUMKEY *) &kkk->upper;
     123              : 
     124            0 :         PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
     125              :                                                                           GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     126            0 : }
     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            0 : }
     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            0 : }
     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            0 : }
     168              : 
     169              : static int
     170            0 : gbt_bool_ssup_cmp(Datum x, Datum y, SortSupport ssup)
     171              : {
     172            0 :         boolKEY    *arg1 = (boolKEY *) DatumGetPointer(x);
     173            0 :         boolKEY    *arg2 = (boolKEY *) DatumGetPointer(y);
     174              : 
     175              :         /* for leaf items we expect lower == upper, so only compare lower */
     176            0 :         return (int32) arg1->lower - (int32) arg2->lower;
     177            0 : }
     178              : 
     179              : Datum
     180            0 : gbt_bool_sortsupport(PG_FUNCTION_ARGS)
     181              : {
     182            0 :         SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
     183              : 
     184            0 :         ssup->comparator = gbt_bool_ssup_cmp;
     185            0 :         ssup->ssup_extra = NULL;
     186              : 
     187            0 :         PG_RETURN_VOID();
     188            0 : }
        

Generated by: LCOV version 2.3.2-1