LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_bool.c (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 33 60 55.0 %
Date: 2024-12-12 17:14:55 Functions: 15 20 75.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             : 
       9             : typedef struct boolkey
      10             : {
      11             :     bool        lower;
      12             :     bool        upper;
      13             : } boolKEY;
      14             : 
      15             : /*
      16             : ** bool ops
      17             : */
      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             : 
      26             : static bool
      27           4 : gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
      28             : {
      29           4 :     return (*((const bool *) a) > *((const bool *) b));
      30             : }
      31             : static bool
      32           4 : gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
      33             : {
      34           4 :     return (*((const bool *) a) >= *((const bool *) b));
      35             : }
      36             : static bool
      37          12 : gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
      38             : {
      39          12 :     return (*((const bool *) a) == *((const bool *) b));
      40             : }
      41             : static bool
      42           4 : gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
      43             : {
      44           4 :     return (*((const bool *) a) <= *((const bool *) b));
      45             : }
      46             : static bool
      47           4 : gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
      48             : {
      49           4 :     return (*((const bool *) a) < *((const bool *) b));
      50             : }
      51             : 
      52             : static int
      53           0 : gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      54             : {
      55           0 :     boolKEY    *ia = (boolKEY *) (((const Nsrt *) a)->t);
      56           0 :     boolKEY    *ib = (boolKEY *) (((const Nsrt *) b)->t);
      57             : 
      58           0 :     if (ia->lower == ib->lower)
      59             :     {
      60           0 :         if (ia->upper == ib->upper)
      61           0 :             return 0;
      62             : 
      63           0 :         return (ia->upper > ib->upper) ? 1 : -1;
      64             :     }
      65             : 
      66           0 :     return (ia->lower > ib->lower) ? 1 : -1;
      67             : }
      68             : 
      69             : 
      70             : static const gbtree_ninfo tinfo =
      71             : {
      72             :     gbt_t_bool,
      73             :     sizeof(bool),
      74             :     2,                          /* sizeof(gbtreekey2) */
      75             :     gbt_boolgt,
      76             :     gbt_boolge,
      77             :     gbt_booleq,
      78             :     gbt_boolle,
      79             :     gbt_boollt,
      80             :     gbt_boolkey_cmp,
      81             : };
      82             : 
      83             : 
      84             : /**************************************************
      85             :  * bool ops
      86             :  **************************************************/
      87             : 
      88             : 
      89             : Datum
      90           4 : gbt_bool_compress(PG_FUNCTION_ARGS)
      91             : {
      92           4 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
      93             : 
      94           4 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
      95             : }
      96             : 
      97             : Datum
      98          14 : gbt_bool_fetch(PG_FUNCTION_ARGS)
      99             : {
     100          14 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     101             : 
     102          14 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     103             : }
     104             : 
     105             : Datum
     106          28 : gbt_bool_consistent(PG_FUNCTION_ARGS)
     107             : {
     108          28 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     109          28 :     bool        query = PG_GETARG_INT16(1);
     110          28 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     111             : 
     112             :     /* Oid      subtype = PG_GETARG_OID(3); */
     113          28 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     114          28 :     boolKEY    *kkk = (boolKEY *) DatumGetPointer(entry->key);
     115             :     GBT_NUMKEY_R key;
     116             : 
     117             :     /* All cases served by this function are exact */
     118          28 :     *recheck = false;
     119             : 
     120          28 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     121          28 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     122             : 
     123          28 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
     124             :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     125             : }
     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             : 
     139             : Datum
     140           0 : gbt_bool_penalty(PG_FUNCTION_ARGS)
     141             : {
     142           0 :     boolKEY    *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     143           0 :     boolKEY    *newentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     144           0 :     float      *result = (float *) PG_GETARG_POINTER(2);
     145             : 
     146           0 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     147             : 
     148           0 :     PG_RETURN_POINTER(result);
     149             : }
     150             : 
     151             : Datum
     152           0 : gbt_bool_picksplit(PG_FUNCTION_ARGS)
     153             : {
     154           0 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
     155             :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
     156             :                                         &tinfo, fcinfo->flinfo));
     157             : }
     158             : 
     159             : Datum
     160           0 : gbt_bool_same(PG_FUNCTION_ARGS)
     161             : {
     162           0 :     boolKEY    *b1 = (boolKEY *) PG_GETARG_POINTER(0);
     163           0 :     boolKEY    *b2 = (boolKEY *) PG_GETARG_POINTER(1);
     164           0 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     165             : 
     166           0 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     167           0 :     PG_RETURN_POINTER(result);
     168             : }

Generated by: LCOV version 1.14