LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_oid.c (source / functions) Hit Total Coverage
Test: PostgreSQL 12devel Lines: 59 82 72.0 %
Date: 2018-09-20 15:21:09 Functions: 22 25 88.0 %
Legend: Lines: hit not hit

          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           4 : PG_FUNCTION_INFO_V1(gbt_oid_compress);
      19           4 : PG_FUNCTION_INFO_V1(gbt_oid_fetch);
      20           4 : PG_FUNCTION_INFO_V1(gbt_oid_union);
      21           4 : PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
      22           4 : PG_FUNCTION_INFO_V1(gbt_oid_consistent);
      23           4 : PG_FUNCTION_INFO_V1(gbt_oid_distance);
      24           4 : PG_FUNCTION_INFO_V1(gbt_oid_penalty);
      25           4 : PG_FUNCTION_INFO_V1(gbt_oid_same);
      26             : 
      27             : 
      28             : static bool
      29        3126 : gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
      30             : {
      31        3126 :     return (*((const Oid *) a) > *((const Oid *) b));
      32             : }
      33             : static bool
      34        1212 : gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
      35             : {
      36        1212 :     return (*((const Oid *) a) >= *((const Oid *) b));
      37             : }
      38             : static bool
      39        1400 : gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
      40             : {
      41        1400 :     return (*((const Oid *) a) == *((const Oid *) b));
      42             : }
      43             : static bool
      44         492 : gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
      45             : {
      46         492 :     return (*((const Oid *) a) <= *((const Oid *) b));
      47             : }
      48             : static bool
      49        2394 : gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
      50             : {
      51        2394 :     return (*((const Oid *) a) < *((const Oid *) b));
      52             : }
      53             : 
      54             : static int
      55       12140 : gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      56             : {
      57       12140 :     oidKEY     *ia = (oidKEY *) (((const Nsrt *) a)->t);
      58       12140 :     oidKEY     *ib = (oidKEY *) (((const Nsrt *) b)->t);
      59             : 
      60       12140 :     if (ia->lower == ib->lower)
      61             :     {
      62           0 :         if (ia->upper == ib->upper)
      63           0 :             return 0;
      64             : 
      65           0 :         return (ia->upper > ib->upper) ? 1 : -1;
      66             :     }
      67             : 
      68       12140 :     return (ia->lower > ib->lower) ? 1 : -1;
      69             : }
      70             : 
      71             : static float8
      72           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           2 : PG_FUNCTION_INFO_V1(oid_dist);
     100             : Datum
     101           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        1276 : gbt_oid_compress(PG_FUNCTION_ARGS)
     122             : {
     123        1276 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     124             : 
     125        1276 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
     126             : }
     127             : 
     128             : Datum
     129           2 : gbt_oid_fetch(PG_FUNCTION_ARGS)
     130             : {
     131           2 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     132             : 
     133           2 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
     134             : }
     135             : 
     136             : Datum
     137        3834 : gbt_oid_consistent(PG_FUNCTION_ARGS)
     138             : {
     139        3834 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     140        3834 :     Oid         query = PG_GETARG_OID(1);
     141        3834 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     142             : 
     143             :     /* Oid      subtype = PG_GETARG_OID(3); */
     144        3834 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     145        3834 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     146             :     GBT_NUMKEY_R key;
     147             : 
     148             :     /* All cases served by this function are exact */
     149        3834 :     *recheck = false;
     150             : 
     151        3834 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     152        3834 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     153             : 
     154        3834 :     PG_RETURN_BOOL(
     155             :                    gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
     156             :         );
     157             : }
     158             : 
     159             : 
     160             : Datum
     161           0 : gbt_oid_distance(PG_FUNCTION_ARGS)
     162             : {
     163           0 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     164           0 :     Oid         query = PG_GETARG_OID(1);
     165             : 
     166             :     /* Oid      subtype = PG_GETARG_OID(3); */
     167           0 :     oidKEY     *kkk = (oidKEY *) DatumGetPointer(entry->key);
     168             :     GBT_NUMKEY_R key;
     169             : 
     170           0 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     171           0 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     172             : 
     173           0 :     PG_RETURN_FLOAT8(
     174             :                      gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
     175             :         );
     176             : }
     177             : 
     178             : 
     179             : Datum
     180         466 : gbt_oid_union(PG_FUNCTION_ARGS)
     181             : {
     182         466 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     183         466 :     void       *out = palloc(sizeof(oidKEY));
     184             : 
     185         466 :     *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
     186         466 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
     187             : }
     188             : 
     189             : 
     190             : Datum
     191        1032 : gbt_oid_penalty(PG_FUNCTION_ARGS)
     192             : {
     193        1032 :     oidKEY     *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     194        1032 :     oidKEY     *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     195        1032 :     float      *result = (float *) PG_GETARG_POINTER(2);
     196             : 
     197        1032 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
     198             : 
     199        1032 :     PG_RETURN_POINTER(result);
     200             : }
     201             : 
     202             : Datum
     203           4 : gbt_oid_picksplit(PG_FUNCTION_ARGS)
     204             : {
     205           4 :     PG_RETURN_POINTER(gbt_num_picksplit(
     206             :                                         (GistEntryVector *) PG_GETARG_POINTER(0),
     207             :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
     208             :                                         &tinfo, fcinfo->flinfo
     209             :                                         ));
     210             : }
     211             : 
     212             : Datum
     213         466 : gbt_oid_same(PG_FUNCTION_ARGS)
     214             : {
     215         466 :     oidKEY     *b1 = (oidKEY *) PG_GETARG_POINTER(0);
     216         466 :     oidKEY     *b2 = (oidKEY *) PG_GETARG_POINTER(1);
     217         466 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     218             : 
     219         466 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     220         466 :     PG_RETURN_POINTER(result);
     221             : }

Generated by: LCOV version 1.13