LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_bytea.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 52 52 100.0 %
Date: 2024-04-25 23:11:32 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * contrib/btree_gist/btree_bytea.c
       3             :  */
       4             : #include "postgres.h"
       5             : 
       6             : #include "btree_gist.h"
       7             : #include "btree_utils_var.h"
       8             : #include "utils/builtins.h"
       9             : #include "utils/bytea.h"
      10             : 
      11             : 
      12             : /*
      13             : ** Bytea ops
      14             : */
      15           4 : PG_FUNCTION_INFO_V1(gbt_bytea_compress);
      16           4 : PG_FUNCTION_INFO_V1(gbt_bytea_union);
      17           4 : PG_FUNCTION_INFO_V1(gbt_bytea_picksplit);
      18           4 : PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
      19           4 : PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
      20           4 : PG_FUNCTION_INFO_V1(gbt_bytea_same);
      21             : 
      22             : 
      23             : /* define for comparison */
      24             : 
      25             : static bool
      26        1190 : gbt_byteagt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      27             : {
      28        1190 :     return DatumGetBool(DirectFunctionCall2(byteagt,
      29             :                                             PointerGetDatum(a),
      30             :                                             PointerGetDatum(b)));
      31             : }
      32             : 
      33             : static bool
      34        1190 : gbt_byteage(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      35             : {
      36        1190 :     return DatumGetBool(DirectFunctionCall2(byteage,
      37             :                                             PointerGetDatum(a),
      38             :                                             PointerGetDatum(b)));
      39             : }
      40             : 
      41             : static bool
      42        2380 : gbt_byteaeq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      43             : {
      44        2380 :     return DatumGetBool(DirectFunctionCall2(byteaeq,
      45             :                                             PointerGetDatum(a),
      46             :                                             PointerGetDatum(b)));
      47             : }
      48             : 
      49             : static bool
      50        1978 : gbt_byteale(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      51             : {
      52        1978 :     return DatumGetBool(DirectFunctionCall2(byteale,
      53             :                                             PointerGetDatum(a),
      54             :                                             PointerGetDatum(b)));
      55             : }
      56             : 
      57             : static bool
      58        3280 : gbt_bytealt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      59             : {
      60        3280 :     return DatumGetBool(DirectFunctionCall2(bytealt,
      61             :                                             PointerGetDatum(a),
      62             :                                             PointerGetDatum(b)));
      63             : }
      64             : 
      65             : static int32
      66       39160 : gbt_byteacmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      67             : {
      68       39160 :     return DatumGetInt32(DirectFunctionCall2(byteacmp,
      69             :                                              PointerGetDatum(a),
      70             :                                              PointerGetDatum(b)));
      71             : }
      72             : 
      73             : 
      74             : static const gbtree_vinfo tinfo =
      75             : {
      76             :     gbt_t_bytea,
      77             :     0,
      78             :     true,
      79             :     gbt_byteagt,
      80             :     gbt_byteage,
      81             :     gbt_byteaeq,
      82             :     gbt_byteale,
      83             :     gbt_bytealt,
      84             :     gbt_byteacmp,
      85             :     NULL
      86             : };
      87             : 
      88             : 
      89             : /**************************************************
      90             :  * Text ops
      91             :  **************************************************/
      92             : 
      93             : 
      94             : Datum
      95        2000 : gbt_bytea_compress(PG_FUNCTION_ARGS)
      96             : {
      97        2000 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
      98             : 
      99        2000 :     PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
     100             : }
     101             : 
     102             : 
     103             : 
     104             : Datum
     105       10102 : gbt_bytea_consistent(PG_FUNCTION_ARGS)
     106             : {
     107       10102 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     108       10102 :     void       *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
     109       10102 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     110             : 
     111             :     /* Oid      subtype = PG_GETARG_OID(3); */
     112       10102 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     113             :     bool        retval;
     114       10102 :     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
     115       10102 :     GBT_VARKEY_R r = gbt_var_key_readable(key);
     116             : 
     117             :     /* All cases served by this function are exact */
     118       10102 :     *recheck = false;
     119             : 
     120       20204 :     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
     121       10102 :                                 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
     122       10102 :     PG_RETURN_BOOL(retval);
     123             : }
     124             : 
     125             : 
     126             : 
     127             : Datum
     128        1714 : gbt_bytea_union(PG_FUNCTION_ARGS)
     129             : {
     130        1714 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     131        1714 :     int32      *size = (int *) PG_GETARG_POINTER(1);
     132             : 
     133        1714 :     PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
     134             :                                     &tinfo, fcinfo->flinfo));
     135             : }
     136             : 
     137             : 
     138             : Datum
     139          10 : gbt_bytea_picksplit(PG_FUNCTION_ARGS)
     140             : {
     141          10 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     142          10 :     GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
     143             : 
     144          10 :     gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
     145             :                       &tinfo, fcinfo->flinfo);
     146          10 :     PG_RETURN_POINTER(v);
     147             : }
     148             : 
     149             : Datum
     150        1712 : gbt_bytea_same(PG_FUNCTION_ARGS)
     151             : {
     152        1712 :     Datum       d1 = PG_GETARG_DATUM(0);
     153        1712 :     Datum       d2 = PG_GETARG_DATUM(1);
     154        1712 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     155             : 
     156        1712 :     *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
     157        1712 :     PG_RETURN_POINTER(result);
     158             : }
     159             : 
     160             : 
     161             : Datum
     162        6420 : gbt_bytea_penalty(PG_FUNCTION_ARGS)
     163             : {
     164        6420 :     GISTENTRY  *o = (GISTENTRY *) PG_GETARG_POINTER(0);
     165        6420 :     GISTENTRY  *n = (GISTENTRY *) PG_GETARG_POINTER(1);
     166        6420 :     float      *result = (float *) PG_GETARG_POINTER(2);
     167             : 
     168        6420 :     PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
     169             :                                       &tinfo, fcinfo->flinfo));
     170             : }

Generated by: LCOV version 1.14