PostgreSQL Source Code  git master
queryjumble.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * queryjumble.h
4  * Query normalization and fingerprinting.
5  *
6  * Portions Copyright (c) 1996-2024, 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 */
27 
28 /*
29  * Working state for computing a query jumble and producing a normalized
30  * query string
31  */
32 typedef struct JumbleState
33 {
34  /* Jumble of current query tree */
35  unsigned char *jumble;
36 
37  /* Number of bytes used in jumble[] */
39 
40  /* Array of locations of constants that should be removed */
42 
43  /* Allocated length of clocations array */
45 
46  /* Current number of valid entries in clocations array */
48 
49  /* highest Param id we've seen, in order to start normalization correctly */
52 
53 /* Values for the compute_query_id GUC */
55 {
60 };
61 
62 /* GUC parameters */
63 extern PGDLLIMPORT int compute_query_id;
64 
65 
66 extern const char *CleanQuerytext(const char *query, int *location, int *len);
67 extern JumbleState *JumbleQuery(Query *query);
68 extern void EnableQueryId(void);
69 
70 extern PGDLLIMPORT bool query_id_enabled;
71 
72 /*
73  * Returns whether query identifier computation has been enabled, either
74  * directly in the GUC or by a module when the setting is 'auto'.
75  */
76 static inline bool
78 {
80  return false;
82  return true;
83  return query_id_enabled;
84 }
85 
86 #endif /* QUERYJUMBLE_H */
#define PGDLLIMPORT
Definition: c.h:1274
size_t Size
Definition: c.h:559
const void size_t len
struct JumbleState JumbleState
JumbleState * JumbleQuery(Query *query)
ComputeQueryIdType
Definition: queryjumble.h:55
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:58
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:59
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:57
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:56
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:77
const char * CleanQuerytext(const char *query, int *location, int *len)
PGDLLIMPORT bool query_id_enabled
void EnableQueryId(void)
PGDLLIMPORT int compute_query_id
struct LocationLen LocationLen
unsigned char * jumble
Definition: queryjumble.h:35
int clocations_buf_size
Definition: queryjumble.h:44
Size jumble_len
Definition: queryjumble.h:38
int highest_extern_param_id
Definition: queryjumble.h:50
LocationLen * clocations
Definition: queryjumble.h:41
int clocations_count
Definition: queryjumble.h:47