LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_text.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 98.8 % 85 84 1 84
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 28 28 28
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_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 CBC           4 : PG_FUNCTION_INFO_V1(gbt_text_compress);
      14               2 : PG_FUNCTION_INFO_V1(gbt_bpchar_compress);
      15               5 : PG_FUNCTION_INFO_V1(gbt_text_union);
      16               5 : PG_FUNCTION_INFO_V1(gbt_text_picksplit);
      17               4 : PG_FUNCTION_INFO_V1(gbt_text_consistent);
      18               2 : PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
      19               5 : PG_FUNCTION_INFO_V1(gbt_text_penalty);
      20               5 : PG_FUNCTION_INFO_V1(gbt_text_same);
      21                 : 
      22                 : 
      23                 : /* define for comparison */
      24                 : 
      25                 : static bool
      26            1195 : gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      27                 : {
      28            1195 :     return DatumGetBool(DirectFunctionCall2Coll(text_gt,
      29                 :                                                 collation,
      30                 :                                                 PointerGetDatum(a),
      31                 :                                                 PointerGetDatum(b)));
      32                 : }
      33                 : 
      34                 : static bool
      35            1202 : gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      36                 : {
      37            1202 :     return DatumGetBool(DirectFunctionCall2Coll(text_ge,
      38                 :                                                 collation,
      39                 :                                                 PointerGetDatum(a),
      40                 :                                                 PointerGetDatum(b)));
      41                 : }
      42                 : 
      43                 : static bool
      44             291 : gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      45                 : {
      46             291 :     return DatumGetBool(DirectFunctionCall2Coll(texteq,
      47                 :                                                 collation,
      48                 :                                                 PointerGetDatum(a),
      49                 :                                                 PointerGetDatum(b)));
      50                 : }
      51                 : 
      52                 : static bool
      53            1061 : gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      54                 : {
      55            1061 :     return DatumGetBool(DirectFunctionCall2Coll(text_le,
      56                 :                                                 collation,
      57                 :                                                 PointerGetDatum(a),
      58                 :                                                 PointerGetDatum(b)));
      59                 : }
      60                 : 
      61                 : static bool
      62             991 : gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      63                 : {
      64             991 :     return DatumGetBool(DirectFunctionCall2Coll(text_lt,
      65                 :                                                 collation,
      66                 :                                                 PointerGetDatum(a),
      67                 :                                                 PointerGetDatum(b)));
      68                 : }
      69                 : 
      70                 : static int32
      71           61673 : gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      72                 : {
      73           61673 :     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             595 : gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
      97                 : {
      98             595 :     return DatumGetBool(DirectFunctionCall2Coll(bpchargt,
      99                 :                                                 collation,
     100                 :                                                 PointerGetDatum(a),
     101                 :                                                 PointerGetDatum(b)));
     102                 : }
     103                 : 
     104                 : static bool
     105             603 : gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     106                 : {
     107             603 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharge,
     108                 :                                                 collation,
     109                 :                                                 PointerGetDatum(a),
     110                 :                                                 PointerGetDatum(b)));
     111                 : }
     112                 : 
     113                 : static bool
     114              71 : gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     115                 : {
     116              71 :     return DatumGetBool(DirectFunctionCall2Coll(bpchareq,
     117                 :                                                 collation,
     118                 :                                                 PointerGetDatum(a),
     119                 :                                                 PointerGetDatum(b)));
     120                 : }
     121                 : 
     122                 : static bool
     123             535 : gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     124                 : {
     125             535 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharle,
     126                 :                                                 collation,
     127                 :                                                 PointerGetDatum(a),
     128                 :                                                 PointerGetDatum(b)));
     129                 : }
     130                 : 
     131                 : static bool
     132             464 : gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     133                 : {
     134             464 :     return DatumGetBool(DirectFunctionCall2Coll(bpcharlt,
     135                 :                                                 collation,
     136                 :                                                 PointerGetDatum(a),
     137                 :                                                 PointerGetDatum(b)));
     138                 : }
     139                 : 
     140                 : static int32
     141              71 : gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
     142                 : {
     143              71 :     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            3019 : gbt_text_compress(PG_FUNCTION_ARGS)
     171                 : {
     172            3019 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     173                 : 
     174            3019 :     if (tinfo.eml == 0)
     175                 :     {
     176               4 :         tinfo.eml = pg_database_encoding_max_length();
     177                 :     }
     178                 : 
     179            3019 :     PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
     180                 : }
     181                 : 
     182                 : Datum
     183            1010 : gbt_bpchar_compress(PG_FUNCTION_ARGS)
     184                 : {
     185                 :     /* This should never have been distinct from gbt_text_compress */
     186            1010 :     return gbt_text_compress(fcinfo);
     187                 : }
     188                 : 
     189                 : 
     190                 : 
     191                 : Datum
     192            4811 : gbt_text_consistent(PG_FUNCTION_ARGS)
     193                 : {
     194            4811 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     195            4811 :     void       *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
     196            4811 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     197                 : 
     198                 :     /* Oid      subtype = PG_GETARG_OID(3); */
     199            4811 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     200                 :     bool        retval;
     201            4811 :     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
     202            4811 :     GBT_VARKEY_R r = gbt_var_key_readable(key);
     203                 : 
     204                 :     /* All cases served by this function are exact */
     205            4811 :     *recheck = false;
     206                 : 
     207            4811 :     if (tinfo.eml == 0)
     208                 :     {
     209 UBC           0 :         tinfo.eml = pg_database_encoding_max_length();
     210                 :     }
     211                 : 
     212 CBC        9622 :     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
     213            4811 :                                 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
     214                 : 
     215            4811 :     PG_RETURN_BOOL(retval);
     216                 : }
     217                 : 
     218                 : 
     219                 : Datum
     220            2332 : gbt_bpchar_consistent(PG_FUNCTION_ARGS)
     221                 : {
     222            2332 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     223            2332 :     void       *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
     224            2332 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
     225                 : 
     226                 :     /* Oid      subtype = PG_GETARG_OID(3); */
     227            2332 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
     228                 :     bool        retval;
     229            2332 :     GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
     230            2332 :     GBT_VARKEY_R r = gbt_var_key_readable(key);
     231                 : 
     232                 :     /* All cases served by this function are exact */
     233            2332 :     *recheck = false;
     234                 : 
     235            2332 :     if (bptinfo.eml == 0)
     236                 :     {
     237               1 :         bptinfo.eml = pg_database_encoding_max_length();
     238                 :     }
     239                 : 
     240            4664 :     retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
     241            2332 :                                 GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
     242            2332 :     PG_RETURN_BOOL(retval);
     243                 : }
     244                 : 
     245                 : 
     246                 : Datum
     247            2492 : gbt_text_union(PG_FUNCTION_ARGS)
     248                 : {
     249            2492 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     250            2492 :     int32      *size = (int *) PG_GETARG_POINTER(1);
     251                 : 
     252            2492 :     PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
     253                 :                                     &tinfo, fcinfo->flinfo));
     254                 : }
     255                 : 
     256                 : 
     257                 : Datum
     258              19 : gbt_text_picksplit(PG_FUNCTION_ARGS)
     259                 : {
     260              19 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     261              19 :     GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
     262                 : 
     263              19 :     gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
     264                 :                       &tinfo, fcinfo->flinfo);
     265              19 :     PG_RETURN_POINTER(v);
     266                 : }
     267                 : 
     268                 : Datum
     269            2489 : gbt_text_same(PG_FUNCTION_ARGS)
     270                 : {
     271            2489 :     Datum       d1 = PG_GETARG_DATUM(0);
     272            2489 :     Datum       d2 = PG_GETARG_DATUM(1);
     273            2489 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
     274                 : 
     275            2489 :     *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
     276            2489 :     PG_RETURN_POINTER(result);
     277                 : }
     278                 : 
     279                 : 
     280                 : Datum
     281            9492 : gbt_text_penalty(PG_FUNCTION_ARGS)
     282                 : {
     283            9492 :     GISTENTRY  *o = (GISTENTRY *) PG_GETARG_POINTER(0);
     284            9492 :     GISTENTRY  *n = (GISTENTRY *) PG_GETARG_POINTER(1);
     285            9492 :     float      *result = (float *) PG_GETARG_POINTER(2);
     286                 : 
     287            9492 :     PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
     288                 :                                       &tinfo, fcinfo->flinfo));
     289                 : }
        

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