LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_oid.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 68.3 % 82 56 26 56
Current Date: 2023-04-08 15:15:32 Functions: 84.0 % 25 21 4 21
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_oid.c
       3                 :  */
       4                 : #include "postgres.h"
       5                 : 
       6                 : #include "btree_gist.h"
       7                 : #include "btree_utils_num.h"
       8                 : 
       9                 : typedef struct
      10                 : {
      11                 :     Oid         lower;
      12                 :     Oid         upper;
      13                 : } oidKEY;
      14                 : 
      15                 : /*
      16                 : ** OID ops
      17                 : */
      18 CBC           2 : PG_FUNCTION_INFO_V1(gbt_oid_compress);
      19               2 : PG_FUNCTION_INFO_V1(gbt_oid_fetch);
      20               2 : PG_FUNCTION_INFO_V1(gbt_oid_union);
      21               2 : PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
      22               2 : PG_FUNCTION_INFO_V1(gbt_oid_consistent);
      23               2 : PG_FUNCTION_INFO_V1(gbt_oid_distance);
      24               2 : PG_FUNCTION_INFO_V1(gbt_oid_penalty);
      25               2 : PG_FUNCTION_INFO_V1(gbt_oid_same);
      26                 : 
      27                 : 
      28                 : static bool
      29            2276 : gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
      30                 : {
      31            2276 :     return (*((const Oid *) a) > *((const Oid *) b));
      32                 : }
      33                 : static bool
      34             193 : gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
      35                 : {
      36             193 :     return (*((const Oid *) a) >= *((const Oid *) b));
      37                 : }
      38                 : static bool
      39            1449 : gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
      40                 : {
      41            1449 :     return (*((const Oid *) a) == *((const Oid *) b));
      42                 : }
      43                 : static bool
      44            1016 : gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
      45                 : {
      46            1016 :     return (*((const Oid *) a) <= *((const Oid *) b));
      47                 : }
      48                 : static bool
      49            3093 : gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
      50                 : {
      51            3093 :     return (*((const Oid *) a) < *((const Oid *) b));
      52                 : }
      53                 : 
      54                 : static int
      55            1464 : gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      56                 : {
      57            1464 :     oidKEY     *ia = (oidKEY *) (((const Nsrt *) a)->t);
      58            1464 :     oidKEY     *ib = (oidKEY *) (((const Nsrt *) b)->t);
      59                 : 
      60            1464 :     if (ia->lower == ib->lower)
      61                 :     {
      62 UBC           0 :         if (ia->upper == ib->upper)
      63               0 :             return 0;
      64                 : 
      65               0 :         return (ia->upper > ib->upper) ? 1 : -1;
      66                 :     }
      67                 : 
      68 CBC        1464 :     return (ia->lower > ib->lower) ? 1 : -1;
      69                 : }
      70                 : 
      71                 : static float8
      72 UBC           0 : gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
      73                 : {
      74               0 :     Oid         aa = *(const Oid *) a;
      75               0 :     Oid         bb = *(const Oid *) b;
      76                 : 
      77               0 :     if (aa < bb)
      78               0 :         return (float8) (bb - aa);
      79                 :     else
      80               0 :         return (float8) (aa - bb);
      81                 : }
      82                 : 
      83                 : 
      84                 : static const gbtree_ninfo tinfo =
      85                 : {
      86                 :     gbt_t_oid,
      87                 :     sizeof(Oid),
      88                 :     8,                          /* sizeof(gbtreekey8) */
      89                 :     gbt_oidgt,
      90                 :     gbt_oidge,
      91                 :     gbt_oideq,
      92                 :     gbt_oidle,
      93                 :     gbt_oidlt,
      94                 :     gbt_oidkey_cmp,
      95                 :     gbt_oid_dist
      96                 : };
      97                 : 
      98                 : 
      99 CBC           1 : PG_FUNCTION_INFO_V1(oid_dist);
     100                 : Datum
     101 UBC           0 : oid_dist(PG_FUNCTION_ARGS)
     102                 : {
     103               0 :     Oid         a = PG_GETARG_OID(0);
     104               0 :     Oid         b = PG_GETARG_OID(1);
     105                 :     Oid         res;
     106                 : 
     107               0 :     if (a < b)
     108               0 :         res = b - a;
     109                 :     else
     110               0 :         res = a - b;
     111               0 :     PG_RETURN_OID(res);
     112                 : }
     113                 : 
     114                 : 
     115                 : /**************************************************
     116                 :  * Oid ops
     117                 :  **************************************************/
     118                 : 
     119                 : 
     120                 : Datum
     121 CBC        1641 : gbt_oid_compress(PG_FUNCTION_ARGS)
     122                 : {
     123            1641 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     124                 : 
     125            1641 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
     126                 : }
     127                 : 
     128                 : Datum
     129 UBC           0 : gbt_oid_fetch(PG_FUNCTION_ARGS)
     130                 : {
     131               0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     132                 : 
     133               0 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     134                 : }
     135                 : 
     136                 : Datum
     137 CBC        2574 : gbt_oid_consistent(PG_FUNCTION_ARGS)
     138                 : {
     139            2574 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     140            2574 :     Oid         query = PG_GETARG_OID(1);
     141            2574 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     142                 : 
     143                 :     /* Oid      subtype = PG_GETARG_OID(3); */
     144            2574 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     145            2574 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     146                 :     GBT_NUMKEY_R key;
     147                 : 
     148                 :     /* All cases served by this function are exact */
     149            2574 :     *recheck = false;
     150                 : 
     151            2574 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     152            2574 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     153                 : 
     154            2574 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
     155                 :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     156                 : }
     157                 : 
     158                 : 
     159                 : Datum
     160 UBC           0 : gbt_oid_distance(PG_FUNCTION_ARGS)
     161                 : {
     162               0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     163               0 :     Oid         query = PG_GETARG_OID(1);
     164                 : 
     165                 :     /* Oid      subtype = PG_GETARG_OID(3); */
     166               0 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     167                 :     GBT_NUMKEY_R key;
     168                 : 
     169               0 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     170               0 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     171                 : 
     172               0 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
     173                 :                                       &tinfo, fcinfo->flinfo));
     174                 : }
     175                 : 
     176                 : 
     177                 : Datum
     178 CBC         633 : gbt_oid_union(PG_FUNCTION_ARGS)
     179                 : {
     180             633 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     181             633 :     void       *out = palloc(sizeof(oidKEY));
     182                 : 
     183             633 :     *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
     184             633 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
     185                 : }
     186                 : 
     187                 : 
     188                 : Datum
     189            2067 : gbt_oid_penalty(PG_FUNCTION_ARGS)
     190                 : {
     191            2067 :     oidKEY     *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     192            2067 :     oidKEY     *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     193            2067 :     float      *result = (float *) PG_GETARG_POINTER(2);
     194                 : 
     195            2067 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     196                 : 
     197            2067 :     PG_RETURN_POINTER(result);
     198                 : }
     199                 : 
     200                 : Datum
     201               4 : gbt_oid_picksplit(PG_FUNCTION_ARGS)
     202                 : {
     203               4 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
     204                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
     205                 :                                         &tinfo, fcinfo->flinfo));
     206                 : }
     207                 : 
     208                 : Datum
     209             633 : gbt_oid_same(PG_FUNCTION_ARGS)
     210                 : {
     211             633 :     oidKEY     *b1 = (oidKEY *) PG_GETARG_POINTER(0);
     212             633 :     oidKEY     *b2 = (oidKEY *) PG_GETARG_POINTER(1);
     213             633 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     214                 : 
     215             633 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     216             633 :     PG_RETURN_POINTER(result);
     217                 : }
        

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