PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-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 */
22typedef 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 */
33
34/*
35 * Working state for computing a query jumble and producing a normalized
36 * query string
37 */
38typedef struct JumbleState
39{
40 /* Jumble of current query tree */
41 unsigned char *jumble;
42
43 /* Number of bytes used in jumble[] */
45
46 /* Array of locations of constants that should be removed */
48
49 /* Allocated length of clocations array */
51
52 /* Current number of valid entries in clocations array */
54
55 /* highest Param id we've seen, in order to start normalization correctly */
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
70
71/* Values for the compute_query_id GUC */
73{
78};
79
80/* GUC parameters */
82
83
84extern const char *CleanQuerytext(const char *query, int *location, int *len);
85extern JumbleState *JumbleQuery(Query *query);
86extern void EnableQueryId(void);
87
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 */
94static inline bool
96{
98 return false;
100 return true;
101 return query_id_enabled;
102}
103
104#endif /* QUERYJUMBLE_H */
#define PGDLLIMPORT
Definition: c.h:1291
size_t Size
Definition: c.h:576
const void size_t len
struct JumbleState JumbleState
JumbleState * JumbleQuery(Query *query)
ComputeQueryIdType
Definition: queryjumble.h:73
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:76
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:77
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:75
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:74
const char * CleanQuerytext(const char *query, int *location, int *len)
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:95
PGDLLIMPORT bool query_id_enabled
void EnableQueryId(void)
PGDLLIMPORT int compute_query_id
struct LocationLen LocationLen
unsigned int pending_nulls
Definition: queryjumble.h:63
unsigned char * jumble
Definition: queryjumble.h:41
int clocations_buf_size
Definition: queryjumble.h:50
Size jumble_len
Definition: queryjumble.h:44
int highest_extern_param_id
Definition: queryjumble.h:56
LocationLen * clocations
Definition: queryjumble.h:47
int clocations_count
Definition: queryjumble.h:53
bool squashed
Definition: queryjumble.h:31