LCOV - differential code coverage report
Current view: top level - contrib/ltree - ltxtquery_op.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 95.3 % 43 41 2 41
Current Date: 2023-04-08 15:15:32 Functions: 83.3 % 6 5 1 5
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*
       2                 :  * txtquery operations with ltree
       3                 :  * Teodor Sigaev <teodor@stack.net>
       4                 :  * contrib/ltree/ltxtquery_op.c
       5                 :  */
       6                 : #include "postgres.h"
       7                 : 
       8                 : #include <ctype.h>
       9                 : 
      10                 : #include "ltree.h"
      11                 : #include "miscadmin.h"
      12                 : 
      13 CBC           3 : PG_FUNCTION_INFO_V1(ltxtq_exec);
      14               2 : PG_FUNCTION_INFO_V1(ltxtq_rexec);
      15                 : 
      16                 : /*
      17                 :  * check for boolean condition
      18                 :  */
      19                 : bool
      20           25660 : ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *val))
      21                 : {
      22                 :     /* since this function recurses, it could be driven to stack overflow */
      23           25660 :     check_stack_depth();
      24                 : 
      25           25660 :     if (curitem->type == VAL)
      26           14664 :         return (*chkcond) (checkval, curitem);
      27           10996 :     else if (curitem->val == (int32) '!')
      28                 :     {
      29                 :         return calcnot ?
      30               3 :             ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
      31               6 :             : true;
      32                 :     }
      33           10993 :     else if (curitem->val == (int32) '&')
      34                 :     {
      35           10991 :         if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
      36            3670 :             return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
      37                 :         else
      38            7321 :             return false;
      39                 :     }
      40                 :     else
      41                 :     {                           /* |-operator */
      42               2 :         if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
      43               1 :             return true;
      44                 :         else
      45               1 :             return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
      46                 :     }
      47                 : }
      48                 : 
      49                 : typedef struct
      50                 : {
      51                 :     ltree      *node;
      52                 :     char       *operand;
      53                 : } CHKVAL;
      54                 : 
      55                 : static bool
      56           10763 : checkcondition_str(void *checkval, ITEM *val)
      57                 : {
      58           10763 :     ltree_level *level = LTREE_FIRST(((CHKVAL *) checkval)->node);
      59           10763 :     int         tlen = ((CHKVAL *) checkval)->node->numlevel;
      60           10763 :     char       *op = ((CHKVAL *) checkval)->operand + val->distance;
      61                 :     int         (*cmpptr) (const char *, const char *, size_t);
      62                 : 
      63           10763 :     cmpptr = (val->flag & LVAR_INCASE) ? ltree_strncasecmp : strncmp;
      64           72305 :     while (tlen > 0)
      65                 :     {
      66           64192 :         if (val->flag & LVAR_SUBLEXEME)
      67                 :         {
      68               4 :             if (compare_subnode(level, op, val->length, cmpptr, (val->flag & LVAR_ANYEND)))
      69               1 :                 return true;
      70                 :         }
      71           64188 :         else if ((val->length == level->len ||
      72           64194 :                   (level->len > val->length && (val->flag & LVAR_ANYEND))) &&
      73           39106 :                  (*cmpptr) (op, level->name, val->length) == 0)
      74            2649 :             return true;
      75                 : 
      76           61542 :         tlen--;
      77           61542 :         level = LEVEL_NEXT(level);
      78                 :     }
      79                 : 
      80            8113 :     return false;
      81                 : }
      82                 : 
      83                 : Datum
      84            8680 : ltxtq_exec(PG_FUNCTION_ARGS)
      85                 : {
      86            8680 :     ltree      *val = PG_GETARG_LTREE_P(0);
      87            8680 :     ltxtquery  *query = PG_GETARG_LTXTQUERY_P(1);
      88                 :     CHKVAL      chkval;
      89                 :     bool        result;
      90                 : 
      91            8680 :     chkval.node = val;
      92            8680 :     chkval.operand = GETOPERAND(query);
      93                 : 
      94            8680 :     result = ltree_execute(GETQUERY(query),
      95                 :                            &chkval,
      96                 :                            true,
      97                 :                            checkcondition_str);
      98                 : 
      99            8680 :     PG_FREE_IF_COPY(val, 0);
     100            8680 :     PG_FREE_IF_COPY(query, 1);
     101            8680 :     PG_RETURN_BOOL(result);
     102                 : }
     103                 : 
     104                 : Datum
     105 UBC           0 : ltxtq_rexec(PG_FUNCTION_ARGS)
     106                 : {
     107               0 :     PG_RETURN_DATUM(DirectFunctionCall2(ltxtq_exec,
     108                 :                                         PG_GETARG_DATUM(1),
     109                 :                                         PG_GETARG_DATUM(0)
     110                 :                                         ));
     111                 : }
        

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