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-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/include/utils/queryjumble.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef QUERYJUBLE_H
15 #define QUERYJUBLE_H
16 
17 #include "nodes/parsenodes.h"
18 
19 #define JUMBLE_SIZE 1024 /* query serialization buffer size */
20 
21 /*
22  * Struct for tracking locations/lengths of constants during normalization
23  */
24 typedef struct LocationLen
25 {
26  int location; /* start offset in query text */
27  int length; /* length in bytes, or -1 to ignore */
28 } LocationLen;
29 
30 /*
31  * Working state for computing a query jumble and producing a normalized
32  * query string
33  */
34 typedef struct JumbleState
35 {
36  /* Jumble of current query tree */
37  unsigned char *jumble;
38 
39  /* Number of bytes used in jumble[] */
41 
42  /* Array of locations of constants that should be removed */
44 
45  /* Allocated length of clocations array */
47 
48  /* Current number of valid entries in clocations array */
50 
51  /* highest Param id we've seen, in order to start normalization correctly */
53 } JumbleState;
54 
55 /* Values for the compute_query_id GUC */
57 {
61 };
62 
63 /* GUC parameters */
64 extern int compute_query_id;
65 
66 
67 extern const char *CleanQuerytext(const char *query, int *location, int *len);
68 extern JumbleState *JumbleQuery(Query *query, const char *querytext);
69 extern void EnableQueryId(void);
70 
71 extern bool query_id_enabled;
72 
73 /*
74  * Returns whether query identifier computation has been enabled, either
75  * directly in the GUC or by a module when the setting is 'auto'.
76  */
77 static inline bool
79 {
81  return false;
83  return true;
84  return query_id_enabled;
85 }
86 
87 #endif /* QUERYJUMBLE_H */
Size jumble_len
Definition: queryjumble.h:40
JumbleState * JumbleQuery(Query *query, const char *querytext)
Definition: queryjumble.c:101
ComputeQueryIdType
Definition: queryjumble.h:56
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:78
void EnableQueryId(void)
Definition: queryjumble.c:150
int clocations_buf_size
Definition: queryjumble.h:46
bool query_id_enabled
Definition: queryjumble.c:46
int clocations_count
Definition: queryjumble.h:49
struct LocationLen LocationLen
int compute_query_id
Definition: queryjumble.c:43
int highest_extern_param_id
Definition: queryjumble.h:52
struct JumbleState JumbleState
const char * CleanQuerytext(const char *query, int *location, int *len)
Definition: queryjumble.c:62
unsigned char * jumble
Definition: queryjumble.h:37
size_t Size
Definition: c.h:540
LocationLen * clocations
Definition: queryjumble.h:43