LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_enum.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 56 60 93.3 %
Date: 2024-04-27 03:11:33 Functions: 19 20 95.0 %
Legend: Lines: hit not hit

          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           4 : PG_FUNCTION_INFO_V1(gbt_enum_compress);
      23           4 : PG_FUNCTION_INFO_V1(gbt_enum_fetch);
      24           4 : PG_FUNCTION_INFO_V1(gbt_enum_union);
      25           4 : PG_FUNCTION_INFO_V1(gbt_enum_picksplit);
      26           4 : PG_FUNCTION_INFO_V1(gbt_enum_consistent);
      27           4 : PG_FUNCTION_INFO_V1(gbt_enum_penalty);
      28           4 : PG_FUNCTION_INFO_V1(gbt_enum_same);
      29             : 
      30             : 
      31             : static bool
      32        2856 : gbt_enumgt(const void *a, const void *b, FmgrInfo *flinfo)
      33             : {
      34        2856 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_gt, flinfo, InvalidOid,
      35             :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      36             :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      37             : }
      38             : static bool
      39        1072 : gbt_enumge(const void *a, const void *b, FmgrInfo *flinfo)
      40             : {
      41        1072 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_ge, flinfo, InvalidOid,
      42             :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      43             :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      44             : }
      45             : static bool
      46        1872 : gbt_enumeq(const void *a, const void *b, FmgrInfo *flinfo)
      47             : {
      48        1872 :     return (*((const Oid *) a) == *((const Oid *) b));
      49             : }
      50             : static bool
      51        1080 : gbt_enumle(const void *a, const void *b, FmgrInfo *flinfo)
      52             : {
      53        1080 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_le, flinfo, InvalidOid,
      54             :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      55             :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      56             : }
      57             : static bool
      58        2856 : gbt_enumlt(const void *a, const void *b, FmgrInfo *flinfo)
      59             : {
      60        2856 :     return DatumGetBool(CallerFInfoFunctionCall2(enum_lt, flinfo, InvalidOid,
      61             :                                                  ObjectIdGetDatum(*((const Oid *) a)),
      62             :                                                  ObjectIdGetDatum(*((const Oid *) b))));
      63             : }
      64             : 
      65             : static int
      66        1986 : gbt_enumkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      67             : {
      68        1986 :     oidKEY     *ia = (oidKEY *) (((const Nsrt *) a)->t);
      69        1986 :     oidKEY     *ib = (oidKEY *) (((const Nsrt *) b)->t);
      70             : 
      71        1986 :     if (ia->lower == ib->lower)
      72             :     {
      73         752 :         if (ia->upper == ib->upper)
      74         752 :             return 0;
      75             : 
      76           0 :         return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp, flinfo, InvalidOid,
      77             :                                                       ObjectIdGetDatum(ia->upper),
      78             :                                                       ObjectIdGetDatum(ib->upper)));
      79             :     }
      80             : 
      81        1234 :     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        1070 : gbt_enum_compress(PG_FUNCTION_ARGS)
     108             : {
     109        1070 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     110             : 
     111        1070 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
     112             : }
     113             : 
     114             : Datum
     115           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        5340 : gbt_enum_consistent(PG_FUNCTION_ARGS)
     124             : {
     125        5340 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     126        5340 :     Oid         query = PG_GETARG_OID(1);
     127        5340 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     128             : 
     129             :     /* Oid      subtype = PG_GETARG_OID(3); */
     130        5340 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     131        5340 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     132             :     GBT_NUMKEY_R key;
     133             : 
     134             :     /* All cases served by this function are exact */
     135        5340 :     *recheck = false;
     136             : 
     137        5340 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     138        5340 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     139             : 
     140        5340 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
     141             :                                       GIST_LEAF(entry), &tinfo,
     142             :                                       fcinfo->flinfo));
     143             : }
     144             : 
     145             : Datum
     146         406 : gbt_enum_union(PG_FUNCTION_ARGS)
     147             : {
     148         406 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     149         406 :     void       *out = palloc(sizeof(oidKEY));
     150             : 
     151         406 :     *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
     152         406 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
     153             : }
     154             : 
     155             : 
     156             : Datum
     157         640 : gbt_enum_penalty(PG_FUNCTION_ARGS)
     158             : {
     159         640 :     oidKEY     *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     160         640 :     oidKEY     *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     161         640 :     float      *result = (float *) PG_GETARG_POINTER(2);
     162             : 
     163         640 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     164             : 
     165         640 :     PG_RETURN_POINTER(result);
     166             : }
     167             : 
     168             : Datum
     169           2 : gbt_enum_picksplit(PG_FUNCTION_ARGS)
     170             : {
     171           2 :     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         404 : gbt_enum_same(PG_FUNCTION_ARGS)
     178             : {
     179         404 :     oidKEY     *b1 = (oidKEY *) PG_GETARG_POINTER(0);
     180         404 :     oidKEY     *b2 = (oidKEY *) PG_GETARG_POINTER(1);
     181         404 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     182             : 
     183         404 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     184         404 :     PG_RETURN_POINTER(result);
     185             : }

Generated by: LCOV version 1.14