LCOV - differential code coverage report
Current view: top level - contrib/ltree - ltxtquery_op.c (source / functions) Coverage Total Hit UBC CBC
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 95.2 % 42 40 2 40
Current Date: 2026-03-14 14:10:32 -0400 Functions: 83.3 % 6 5 1 5
Baseline: lcov-20260315-024220-baseline Branches: 92.3 % 26 24 2 24
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 100.0 % 4 4 4
(360..) days: 94.7 % 38 36 2 36
Function coverage date bins:
(360..) days: 83.3 % 6 5 1 5
Branch coverage date bins:
(7,30] days: 100.0 % 4 4 4
(360..) days: 90.9 % 22 20 2 20

 Age         Owner                    Branch data    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                 :                : 
 8629 bruce@momjian.us           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
 6121                            20                 :          25185 : 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 */
 3814 noah@leadboat.com          23                 :          25185 :     check_stack_depth();
                                 24                 :                : 
 8629 bruce@momjian.us           25         [ +  + ]:          25185 :     if (curitem->type == VAL)
                                 26                 :          14410 :         return (*chkcond) (checkval, curitem);
 5011 peter_e@gmx.net            27         [ +  + ]:          10775 :     else if (curitem->val == (int32) '!')
                                 28                 :                :     {
                                 29                 :                :         return calcnot ?
 8618 bruce@momjian.us           30                 :              3 :             ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
 8629                            31   [ +  -  +  + ]:              6 :             : true;
                                 32                 :                :     }
 5011 peter_e@gmx.net            33         [ +  + ]:          10772 :     else if (curitem->val == (int32) '&')
                                 34                 :                :     {
 8593 bruce@momjian.us           35         [ +  + ]:          10770 :         if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
 8618                            36                 :           3637 :             return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
                                 37                 :                :         else
 8629                            38                 :           7133 :             return false;
                                 39                 :                :     }
                                 40                 :                :     else
                                 41                 :                :     {                           /* |-operator */
 8618                            42         [ +  + ]:              2 :         if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
 8629                            43                 :              1 :             return true;
                                 44                 :                :         else
 8618                            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
 6121                            56                 :          10763 : checkcondition_str(void *checkval, ITEM *val)
                                 57                 :                : {
 8593                            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;
   17 jdavis@postgresql.or       61                 :          10763 :     bool        prefix = (val->flag & LVAR_ANYEND);
                                 62                 :          10763 :     bool        ci = (val->flag & LVAR_INCASE);
                                 63                 :                : 
 8593 bruce@momjian.us           64         [ +  + ]:          72305 :     while (tlen > 0)
                                 65                 :                :     {
 7319 neilc@samurai.com          66         [ +  + ]:          64192 :         if (val->flag & LVAR_SUBLEXEME)
                                 67                 :                :         {
   17 jdavis@postgresql.or       68         [ +  + ]:              4 :             if (compare_subnode(level, op, val->length, prefix, ci))
 8629 bruce@momjian.us           69                 :              1 :                 return true;
                                 70                 :                :         }
   17 jdavis@postgresql.or       71         [ +  + ]:          64188 :         else if (ltree_label_match(op, val->length, level->name, level->len,
                                 72                 :                :                                    prefix, ci))
 8629 bruce@momjian.us           73                 :           2649 :             return true;
                                 74                 :                : 
                                 75                 :          61542 :         tlen--;
 8593                            76                 :          61542 :         level = LEVEL_NEXT(level);
                                 77                 :                :     }
                                 78                 :                : 
 8629                            79                 :           8113 :     return false;
                                 80                 :                : }
                                 81                 :                : 
                                 82                 :                : Datum
 8593                            83                 :           8680 : ltxtq_exec(PG_FUNCTION_ARGS)
                                 84                 :                : {
 3100 tgl@sss.pgh.pa.us          85                 :           8680 :     ltree      *val = PG_GETARG_LTREE_P(0);
                                 86                 :           8680 :     ltxtquery  *query = PG_GETARG_LTXTQUERY_P(1);
                                 87                 :                :     CHKVAL      chkval;
                                 88                 :                :     bool        result;
                                 89                 :                : 
 8629 bruce@momjian.us           90                 :           8680 :     chkval.node = val;
                                 91                 :           8680 :     chkval.operand = GETOPERAND(query);
                                 92                 :                : 
 2236 alvherre@alvh.no-ip.       93                 :           8680 :     result = ltree_execute(GETQUERY(query),
                                 94                 :                :                            &chkval,
                                 95                 :                :                            true,
                                 96                 :                :                            checkcondition_str);
                                 97                 :                : 
 8629 bruce@momjian.us           98         [ +  + ]:           8680 :     PG_FREE_IF_COPY(val, 0);
                                 99         [ -  + ]:           8680 :     PG_FREE_IF_COPY(query, 1);
                                100                 :           8680 :     PG_RETURN_BOOL(result);
                                101                 :                : }
                                102                 :                : 
                                103                 :                : Datum
 8593 bruce@momjian.us          104                 :UBC           0 : ltxtq_rexec(PG_FUNCTION_ARGS)
                                105                 :                : {
                                106                 :              0 :     PG_RETURN_DATUM(DirectFunctionCall2(ltxtq_exec,
                                107                 :                :                                         PG_GETARG_DATUM(1),
                                108                 :                :                                         PG_GETARG_DATUM(0)
                                109                 :                :                                         ));
                                110                 :                : }
        

Generated by: LCOV version 2.4-beta