LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_text.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 84 85 98.8 %
Date: 2024-03-28 16:11:17 Functions: 28 28 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * contrib/btree_gist/btree_text.c
       3             :  */
       4             : #include "postgres.h"
       5             : 
       6             : #include "btree_gist.h"
       7             : #include "btree_utils_var.h"
       8             : #include "utils/builtins.h"
       9             : 
      10             : /*
      11             : ** Text ops
      12             : */
      13           8 : PG_FUNCTION_INFO_V1(gbt_text_compress);
      14           4 : PG_FUNCTION_INFO_V1(gbt_bpchar_compress);
      15          10 : PG_FUNCTION_INFO_V1(gbt_text_union);
      16          10 : PG_FUNCTION_INFO_V1(gbt_text_picksplit);
      17           8 : PG_FUNCTION_INFO_V1(gbt_text_consistent);
      18           4 : PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
      19          10 : PG_FUNCTION_INFO_V1(gbt_text_penalty);
      20          10 : PG_FUNCTION_INFO_V1(gbt_text_same);
      21             : 
      22             : 
      23             : /* define for comparison */
      24             : 
      25             : static bool
      26        2390 : gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      27             : {
      28        2390 :     return DatumGetBool(DirectFunctionCall2Coll(text_gt,
      29             :                                                 collation,
      30             :                                                 PointerGetDatum(a),
      31             :                                                 PointerGetDatum(b)));
      32             : }
      33             : 
      34             : static bool
      35        2404 : gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      36             : {
      37        2404 :     return DatumGetBool(DirectFunctionCall2Coll(text_ge,
      38             :                                                 collation,
      39             :                                                 PointerGetDatum(a),
      40             :                                                 PointerGetDatum(b)));
      41             : }
      42             : 
      43             : static bool
      44         596 : gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      45             : {
      46         596 :     return DatumGetBool(DirectFunctionCall2Coll(texteq,
      47             :                                                 collation,
      48             :                                                 PointerGetDatum(a),
      49             :                                                 PointerGetDatum(b)));
      50             : }
      51             : 
      52             : static bool
      53        2136 : gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      54             : {
      55        2136 :     return DatumGetBool(DirectFunctionCall2Coll(text_le,
      56             :                                                 collation,
      57             :                                                 PointerGetDatum(a),
      58             :                                                 PointerGetDatum(b)));
      59             : }
      60             : 
      61             : static bool
      62        1996 : gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      63             : {
      64        1996 :     return DatumGetBool(DirectFunctionCall2Coll(text_lt,
      65             :                                                 collation,
      66             :                                                 PointerGetDatum(a),
      67             :                                                 PointerGetDatum(b)));
      68             : }
      69             : 
      70             : static int32
      71      123280 : gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      72             : {
      73      123280 :     return DatumGetInt32(DirectFunctionCall2Coll(bttextcmp,
      74             :                                                  collation,
      75             :                                                  PointerGetDatum(a),
      76             :                                                  PointerGetDatum(b)));
      77             : }
      78             : 
      79             : static gbtree_vinfo tinfo =
      80             : {
      81             :     gbt_t_text,
      82             :     0,
      83             :     false,
      84             :     gbt_textgt,
      85             :     gbt_textge,
      86             :     gbt_texteq,
      87             :     gbt_textle,
      88             :     gbt_textlt,
      89             :     gbt_textcmp,
      90             :     NULL
      91             : };
      92             : 
      93             : /* bpchar needs its own comparison rules */
      94             : 
      95             : static bool
      96        1190 : gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      97             : {
      98        1190 :     return DatumGetBool(DirectFunctionCall2Coll(bpchargt,
      99             :                                                 collation,
     100             :                                                 PointerGetDatum(a),
     101             :                                                 PointerGetDatum(b)));
     102             : }
     103             : 
     104             : static bool
     105        1206 : gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     106             : {
     107        1206 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharge,
     108             :                                                 collation,
     109             :                                                 PointerGetDatum(a),
     110             :                                                 PointerGetDatum(b)));
     111             : }
     112             : 
     113             : static bool
     114         142 : gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     115             : {
     116         142 :     return DatumGetBool(DirectFunctionCall2Coll(bpchareq,
     117             :                                                 collation,
     118             :                                                 PointerGetDatum(a),
     119             :                                                 PointerGetDatum(b)));
     120             : }
     121             : 
     122             : static bool
     123        1070 : gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     124             : {
     125        1070 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharle,
     126             :                                                 collation,
     127             :                                                 PointerGetDatum(a),
     128             :                                                 PointerGetDatum(b)));
     129             : }
     130             : 
     131             : static bool
     132         928 : gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     133             : {
     134         928 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharlt,
     135             :                                                 collation,
     136             :                                                 PointerGetDatum(a),
     137             :                                                 PointerGetDatum(b)));
     138             : }
     139             : 
     140             : static int32
     141         142 : gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     142             : {
     143         142 :     return DatumGetInt32(DirectFunctionCall2Coll(bpcharcmp,
     144             :                                                  collation,
     145             :                                                  PointerGetDatum(a),
     146             :                                                  PointerGetDatum(b)));
     147             : }
     148             : 
     149             : static gbtree_vinfo bptinfo =
     150             : {
     151             :     gbt_t_bpchar,
     152             :     0,
     153             :     false,
     154             :     gbt_bpchargt,
     155             :     gbt_bpcharge,
     156             :     gbt_bpchareq,
     157             :     gbt_bpcharle,
     158             :     gbt_bpcharlt,
     159             :     gbt_bpcharcmp,
     160             :     NULL
     161             : };
     162             : 
     163             : 
     164             : /**************************************************
     165             :  * Text ops
     166             :  **************************************************/
     167             : 
     168             : 
     169             : Datum
     170        6040 : gbt_text_compress(PG_FUNCTION_ARGS)
     171             : {
     172        6040 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     173             : 
     174        6040 :     if (tinfo.eml == 0)
     175             :     {
     176           8 :         tinfo.eml = pg_database_encoding_max_length();
     177             :     }
     178             : 
     179        6040 :     PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
     180             : }
     181             : 
     182             : Datum
     183        2022 : gbt_bpchar_compress(PG_FUNCTION_ARGS)
     184             : {
     185             :     /* This should never have been distinct from gbt_text_compress */
     186        2022 :     return gbt_text_compress(fcinfo);
     187             : }
     188             : 
     189             : 
     190             : 
     191             : Datum
     192        9664 : gbt_text_consistent(PG_FUNCTION_ARGS)
     193             : {
     194        9664 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     195        9664 :     void       *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
     196        9664 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     197             : 
     198             :     /* Oid      subtype = PG_GETARG_OID(3); */
     199        9664 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     200             :     bool        retval;
     201        9664 :     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
     202        9664 :     GBT_VARKEY_R r = gbt_var_key_readable(key);
     203             : 
     204             :     /* All cases served by this function are exact */
     205        9664 :     *recheck = false;
     206             : 
     207        9664 :     if (tinfo.eml == 0)
     208             :     {
     209           0 :         tinfo.eml = pg_database_encoding_max_length();
     210             :     }
     211             : 
     212       19328 :     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
     213        9664 :                                 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
     214             : 
     215        9664 :     PG_RETURN_BOOL(retval);
     216             : }
     217             : 
     218             : 
     219             : Datum
     220        4664 : gbt_bpchar_consistent(PG_FUNCTION_ARGS)
     221             : {
     222        4664 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     223        4664 :     void       *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
     224        4664 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     225             : 
     226             :     /* Oid      subtype = PG_GETARG_OID(3); */
     227        4664 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     228             :     bool        retval;
     229        4664 :     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
     230        4664 :     GBT_VARKEY_R r = gbt_var_key_readable(key);
     231             : 
     232             :     /* All cases served by this function are exact */
     233        4664 :     *recheck = false;
     234             : 
     235        4664 :     if (bptinfo.eml == 0)
     236             :     {
     237           2 :         bptinfo.eml = pg_database_encoding_max_length();
     238             :     }
     239             : 
     240        9328 :     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
     241        4664 :                                 GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
     242        4664 :     PG_RETURN_BOOL(retval);
     243             : }
     244             : 
     245             : 
     246             : Datum
     247        4984 : gbt_text_union(PG_FUNCTION_ARGS)
     248             : {
     249        4984 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     250        4984 :     int32      *size = (int *) PG_GETARG_POINTER(1);
     251             : 
     252        4984 :     PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
     253             :                                     &tinfo, fcinfo->flinfo));
     254             : }
     255             : 
     256             : 
     257             : Datum
     258          38 : gbt_text_picksplit(PG_FUNCTION_ARGS)
     259             : {
     260          38 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     261          38 :     GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
     262             : 
     263          38 :     gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
     264             :                       &tinfo, fcinfo->flinfo);
     265          38 :     PG_RETURN_POINTER(v);
     266             : }
     267             : 
     268             : Datum
     269        4978 : gbt_text_same(PG_FUNCTION_ARGS)
     270             : {
     271        4978 :     Datum       d1 = PG_GETARG_DATUM(0);
     272        4978 :     Datum       d2 = PG_GETARG_DATUM(1);
     273        4978 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     274             : 
     275        4978 :     *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
     276        4978 :     PG_RETURN_POINTER(result);
     277             : }
     278             : 
     279             : 
     280             : Datum
     281       18998 : gbt_text_penalty(PG_FUNCTION_ARGS)
     282             : {
     283       18998 :     GISTENTRY  *o = (GISTENTRY *) PG_GETARG_POINTER(0);
     284       18998 :     GISTENTRY  *n = (GISTENTRY *) PG_GETARG_POINTER(1);
     285       18998 :     float      *result = (float *) PG_GETARG_POINTER(2);
     286             : 
     287       18998 :     PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
     288             :                                       &tinfo, fcinfo->flinfo));
     289             : }

Generated by: LCOV version 1.14