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-2022, 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 */
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 */
54 
55 /* Values for the compute_query_id GUC */
57 {
62 };
63 
64 /* GUC parameters */
65 extern PGDLLIMPORT int compute_query_id;
66 
67 
68 extern const char *CleanQuerytext(const char *query, int *location, int *len);
69 extern JumbleState *JumbleQuery(Query *query, const char *querytext);
70 extern void EnableQueryId(void);
71 
72 extern PGDLLIMPORT bool query_id_enabled;
73 
74 /*
75  * Returns whether query identifier computation has been enabled, either
76  * directly in the GUC or by a module when the setting is 'auto'.
77  */
78 static inline bool
80 {
82  return false;
84  return true;
85  return query_id_enabled;
86 }
87 
88 #endif /* QUERYJUMBLE_H */
#define PGDLLIMPORT
Definition: c.h:1331
size_t Size
Definition: c.h:540
const void size_t len
struct JumbleState JumbleState
JumbleState * JumbleQuery(Query *query, const char *querytext)
Definition: queryjumble.c:101
ComputeQueryIdType
Definition: queryjumble.h:57
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:60
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:61
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:59
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:58
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:79
const char * CleanQuerytext(const char *query, int *location, int *len)
Definition: queryjumble.c:62
PGDLLIMPORT bool query_id_enabled
Definition: queryjumble.c:46
void EnableQueryId(void)
Definition: queryjumble.c:150
PGDLLIMPORT int compute_query_id
Definition: queryjumble.c:43
struct LocationLen LocationLen
unsigned char * jumble
Definition: queryjumble.h:37
int clocations_buf_size
Definition: queryjumble.h:46
Size jumble_len
Definition: queryjumble.h:40
int highest_extern_param_id
Definition: queryjumble.h:52
LocationLen * clocations
Definition: queryjumble.h:43
int clocations_count
Definition: queryjumble.h:49