LCOV - code coverage report
Current view: top level - src/include/nodes - queryjumble.h (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 83.3 % 6 5
Test Date: 2026-07-12 22:15:32 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 75.0 % 4 3

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * queryjumble.h
       4                 :             :  *    Query normalization and fingerprinting.
       5                 :             :  *
       6                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :             :  *
       9                 :             :  * IDENTIFICATION
      10                 :             :  *    src/include/nodes/queryjumble.h
      11                 :             :  *
      12                 :             :  *-------------------------------------------------------------------------
      13                 :             :  */
      14                 :             : #ifndef QUERYJUMBLE_H
      15                 :             : #define QUERYJUMBLE_H
      16                 :             : 
      17                 :             : #include "nodes/parsenodes.h"
      18                 :             : 
      19                 :             : /*
      20                 :             :  * Struct for tracking locations/lengths of constants during normalization
      21                 :             :  */
      22                 :             : typedef struct LocationLen
      23                 :             : {
      24                 :             :     int         location;       /* start offset in query text */
      25                 :             :     int         length;         /* length in bytes, or -1 to ignore */
      26                 :             : 
      27                 :             :     /* Does this location represent a squashed list? */
      28                 :             :     bool        squashed;
      29                 :             : 
      30                 :             :     /* Is this location a PARAM_EXTERN parameter? */
      31                 :             :     bool        extern_param;
      32                 :             : } LocationLen;
      33                 :             : 
      34                 :             : /*
      35                 :             :  * Working state for computing a query jumble and producing a normalized
      36                 :             :  * query string
      37                 :             :  */
      38                 :             : typedef struct JumbleState
      39                 :             : {
      40                 :             :     /* Jumble of current query tree */
      41                 :             :     unsigned char *jumble;
      42                 :             : 
      43                 :             :     /* Number of bytes used in jumble[] */
      44                 :             :     Size        jumble_len;
      45                 :             : 
      46                 :             :     /* Array of locations of constants that should be removed */
      47                 :             :     LocationLen *clocations;
      48                 :             : 
      49                 :             :     /* Allocated length of clocations array */
      50                 :             :     int         clocations_buf_size;
      51                 :             : 
      52                 :             :     /* Current number of valid entries in clocations array */
      53                 :             :     int         clocations_count;
      54                 :             : 
      55                 :             :     /*
      56                 :             :      * ID of the highest PARAM_EXTERN parameter we've seen in the query; used
      57                 :             :      * to start normalization correctly.  However, if there are any squashed
      58                 :             :      * lists in the query, we disregard query-supplied parameter numbers and
      59                 :             :      * renumber everything.  This is to avoid possible gaps caused by
      60                 :             :      * squashing in case any params are in squashed lists.
      61                 :             :      */
      62                 :             :     int         highest_extern_param_id;
      63                 :             : 
      64                 :             :     /* Whether squashable lists are present */
      65                 :             :     bool        has_squashed_lists;
      66                 :             : 
      67                 :             :     /*
      68                 :             :      * Count of the number of NULL nodes seen since last appending a value.
      69                 :             :      * These are flushed out to the jumble buffer before subsequent appends
      70                 :             :      * and before performing the final jumble hash.
      71                 :             :      */
      72                 :             :     unsigned int pending_nulls;
      73                 :             : 
      74                 :             : #ifdef USE_ASSERT_CHECKING
      75                 :             :     /* The total number of bytes added to the jumble buffer */
      76                 :             :     Size        total_jumble_len;
      77                 :             : #endif
      78                 :             : } JumbleState;
      79                 :             : 
      80                 :             : /* Values for the compute_query_id GUC */
      81                 :             : enum ComputeQueryIdType
      82                 :             : {
      83                 :             :     COMPUTE_QUERY_ID_OFF,
      84                 :             :     COMPUTE_QUERY_ID_ON,
      85                 :             :     COMPUTE_QUERY_ID_AUTO,
      86                 :             :     COMPUTE_QUERY_ID_REGRESS,
      87                 :             : };
      88                 :             : 
      89                 :             : /* GUC parameters */
      90                 :             : extern PGDLLIMPORT int compute_query_id;
      91                 :             : 
      92                 :             : 
      93                 :             : extern const char *CleanQuerytext(const char *query, int *location, int *len);
      94                 :             : extern LocationLen *ComputeConstantLengths(const JumbleState *jstate,
      95                 :             :                                            const char *query,
      96                 :             :                                            int query_loc);
      97                 :             : extern JumbleState *JumbleQuery(Query *query);
      98                 :             : extern void EnableQueryId(void);
      99                 :             : 
     100                 :             : extern PGDLLIMPORT bool query_id_enabled;
     101                 :             : 
     102                 :             : /*
     103                 :             :  * Returns whether query identifier computation has been enabled, either
     104                 :             :  * directly in the GUC or by a module when the setting is 'auto'.
     105                 :             :  */
     106                 :             : static inline bool
     107                 :      536305 : IsQueryIdEnabled(void)
     108                 :             : {
     109         [ -  + ]:      536305 :     if (compute_query_id == COMPUTE_QUERY_ID_OFF)
     110                 :           0 :         return false;
     111         [ +  + ]:      536305 :     if (compute_query_id == COMPUTE_QUERY_ID_ON)
     112                 :         224 :         return true;
     113                 :      536081 :     return query_id_enabled;
     114                 :             : }
     115                 :             : 
     116                 :             : #endif                          /* QUERYJUMBLE_H */
        

Generated by: LCOV version 2.0-1