LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_enum.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 93.3 % 60 56 4 56
Current Date: 2023-04-08 15:15:32 Functions: 95.0 % 20 19 1 19
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*
       2                 :  * contrib/btree_gist/btree_enum.c
       3                 :  */
       4                 : #include "postgres.h"
       5                 : 
       6                 : #include "btree_gist.h"
       7                 : #include "btree_utils_num.h"
       8                 : #include "fmgr.h"
       9                 : #include "utils/builtins.h"
      10                 : 
      11                 : /* enums are really Oids, so we just use the same structure */
      12                 : 
      13                 : typedef struct
      14                 : {
      15                 :     Oid         lower;
      16                 :     Oid         upper;
      17                 : } oidKEY;
      18                 : 
      19                 : /*
      20                 : ** enum ops
      21                 : */
      22 CBC           2 : PG_FUNCTION_INFO_V1(gbt_enum_compress);
      23               2 : PG_FUNCTION_INFO_V1(gbt_enum_fetch);
      24               2 : PG_FUNCTION_INFO_V1(gbt_enum_union);
      25               2 : PG_FUNCTION_INFO_V1(gbt_enum_picksplit);
      26               2 : PG_FUNCTION_INFO_V1(gbt_enum_consistent);
      27               2 : PG_FUNCTION_INFO_V1(gbt_enum_penalty);
      28               2 : PG_FUNCTION_INFO_V1(gbt_enum_same);
      29                 : 
      30                 : 
      31                 : static bool
      32            1428 : gbt_enumgt(const void *a, const void *b, FmgrInfo *flinfo)
      33                 : {
      34            1428 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_gt, flinfo, InvalidOid,
      35                 :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      36                 :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      37                 : }
      38                 : static bool
      39             536 : gbt_enumge(const void *a, const void *b, FmgrInfo *flinfo)
      40                 : {
      41             536 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_ge, flinfo, InvalidOid,
      42                 :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      43                 :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      44                 : }
      45                 : static bool
      46             936 : gbt_enumeq(const void *a, const void *b, FmgrInfo *flinfo)
      47                 : {
      48             936 :     return (*((const Oid *) a) == *((const Oid *) b));
      49                 : }
      50                 : static bool
      51             540 : gbt_enumle(const void *a, const void *b, FmgrInfo *flinfo)
      52                 : {
      53             540 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_le, flinfo, InvalidOid,
      54                 :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      55                 :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      56                 : }
      57                 : static bool
      58            1428 : gbt_enumlt(const void *a, const void *b, FmgrInfo *flinfo)
      59                 : {
      60            1428 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_lt, flinfo, InvalidOid,
      61                 :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      62                 :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      63                 : }
      64                 : 
      65                 : static int
      66             993 : gbt_enumkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      67                 : {
      68             993 :     oidKEY     *ia = (oidKEY *) (((const Nsrt *) a)->t);
      69             993 :     oidKEY     *ib = (oidKEY *) (((const Nsrt *) b)->t);
      70                 : 
      71             993 :     if (ia->lower == ib->lower)
      72                 :     {
      73             376 :         if (ia->upper == ib->upper)
      74             376 :             return 0;
      75                 : 
      76 UBC           0 :         return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp, flinfo, InvalidOid,
      77                 :                                                       ObjectIdGetDatum(ia->upper),
      78                 :                                                       ObjectIdGetDatum(ib->upper)));
      79                 :     }
      80                 : 
      81 CBC         617 :     return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp, flinfo, InvalidOid,
      82                 :                                                   ObjectIdGetDatum(ia->lower),
      83                 :                                                   ObjectIdGetDatum(ib->lower)));
      84                 : }
      85                 : 
      86                 : static const gbtree_ninfo tinfo =
      87                 : {
      88                 :     gbt_t_enum,
      89                 :     sizeof(Oid),
      90                 :     8,                          /* sizeof(gbtreekey8) */
      91                 :     gbt_enumgt,
      92                 :     gbt_enumge,
      93                 :     gbt_enumeq,
      94                 :     gbt_enumle,
      95                 :     gbt_enumlt,
      96                 :     gbt_enumkey_cmp,
      97                 :     NULL                        /* no KNN support at least for now */
      98                 : };
      99                 : 
     100                 : 
     101                 : /**************************************************
     102                 :  * Enum ops
     103                 :  **************************************************/
     104                 : 
     105                 : 
     106                 : Datum
     107             535 : gbt_enum_compress(PG_FUNCTION_ARGS)
     108                 : {
     109             535 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     110                 : 
     111             535 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
     112                 : }
     113                 : 
     114                 : Datum
     115 UBC           0 : gbt_enum_fetch(PG_FUNCTION_ARGS)
     116                 : {
     117               0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     118                 : 
     119               0 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     120                 : }
     121                 : 
     122                 : Datum
     123 CBC        2670 : gbt_enum_consistent(PG_FUNCTION_ARGS)
     124                 : {
     125            2670 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     126            2670 :     Oid         query = PG_GETARG_OID(1);
     127            2670 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     128                 : 
     129                 :     /* Oid      subtype = PG_GETARG_OID(3); */
     130            2670 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     131            2670 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     132                 :     GBT_NUMKEY_R key;
     133                 : 
     134                 :     /* All cases served by this function are exact */
     135            2670 :     *recheck = false;
     136                 : 
     137            2670 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     138            2670 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     139                 : 
     140            2670 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
     141                 :                                       GIST_LEAF(entry), &tinfo,
     142                 :                                       fcinfo->flinfo));
     143                 : }
     144                 : 
     145                 : Datum
     146             203 : gbt_enum_union(PG_FUNCTION_ARGS)
     147                 : {
     148             203 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     149             203 :     void       *out = palloc(sizeof(oidKEY));
     150                 : 
     151             203 :     *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
     152             203 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
     153                 : }
     154                 : 
     155                 : 
     156                 : Datum
     157             328 : gbt_enum_penalty(PG_FUNCTION_ARGS)
     158                 : {
     159             328 :     oidKEY     *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     160             328 :     oidKEY     *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     161             328 :     float      *result = (float *) PG_GETARG_POINTER(2);
     162                 : 
     163             328 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     164                 : 
     165             328 :     PG_RETURN_POINTER(result);
     166                 : }
     167                 : 
     168                 : Datum
     169               1 : gbt_enum_picksplit(PG_FUNCTION_ARGS)
     170                 : {
     171               1 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
     172                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
     173                 :                                         &tinfo, fcinfo->flinfo));
     174                 : }
     175                 : 
     176                 : Datum
     177             202 : gbt_enum_same(PG_FUNCTION_ARGS)
     178                 : {
     179             202 :     oidKEY     *b1 = (oidKEY *) PG_GETARG_POINTER(0);
     180             202 :     oidKEY     *b2 = (oidKEY *) PG_GETARG_POINTER(1);
     181             202 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     182                 : 
     183             202 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     184             202 :     PG_RETURN_POINTER(result);
     185                 : }
        

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