LCOV - code coverage report
Current view: top level - src/include/nodes - queryjumble.h (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 5 6 83.3 %
Date: 2025-04-02 07:15:05 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * queryjumble.h
       4             :  *    Query normalization and fingerprinting.
       5             :  *
       6             :  * Portions Copyright (c) 1996-2025, 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             :     /*
      28             :      * Indicates that this location represents the beginning or end of a run
      29             :      * of squashed constants.
      30             :      */
      31             :     bool        squashed;
      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             :     /* highest Param id we've seen, in order to start normalization correctly */
      56             :     int         highest_extern_param_id;
      57             : 
      58             :     /*
      59             :      * Count of the number of NULL nodes seen since last appending a value.
      60             :      * These are flushed out to the jumble buffer before subsequent appends
      61             :      * and before performing the final jumble hash.
      62             :      */
      63             :     unsigned int pending_nulls;
      64             : 
      65             : #ifdef USE_ASSERT_CHECKING
      66             :     /* The total number of bytes added to the jumble buffer */
      67             :     Size        total_jumble_len;
      68             : #endif
      69             : } JumbleState;
      70             : 
      71             : /* Values for the compute_query_id GUC */
      72             : enum ComputeQueryIdType
      73             : {
      74             :     COMPUTE_QUERY_ID_OFF,
      75             :     COMPUTE_QUERY_ID_ON,
      76             :     COMPUTE_QUERY_ID_AUTO,
      77             :     COMPUTE_QUERY_ID_REGRESS,
      78             : };
      79             : 
      80             : /* GUC parameters */
      81             : extern PGDLLIMPORT int compute_query_id;
      82             : 
      83             : 
      84             : extern const char *CleanQuerytext(const char *query, int *location, int *len);
      85             : extern JumbleState *JumbleQuery(Query *query);
      86             : extern void EnableQueryId(void);
      87             : 
      88             : extern PGDLLIMPORT bool query_id_enabled;
      89             : 
      90             : /*
      91             :  * Returns whether query identifier computation has been enabled, either
      92             :  * directly in the GUC or by a module when the setting is 'auto'.
      93             :  */
      94             : static inline bool
      95      881792 : IsQueryIdEnabled(void)
      96             : {
      97      881792 :     if (compute_query_id == COMPUTE_QUERY_ID_OFF)
      98           0 :         return false;
      99      881792 :     if (compute_query_id == COMPUTE_QUERY_ID_ON)
     100         248 :         return true;
     101      881544 :     return query_id_enabled;
     102             : }
     103             : 
     104             : #endif                          /* QUERYJUMBLE_H */

Generated by: LCOV version 1.14