Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

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-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 /* Does this location represent a squashed list? */
29
30 /* Is this location a PARAM_EXTERN parameter? */
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 /*
56 * ID of the highest PARAM_EXTERN parameter we've seen in the query; used
57 * to start normalization correctly. However, if there are any squashed
58 * lists in the query, we disregard query-supplied parameter numbers and
59 * renumber everything. This is to avoid possible gaps caused by
60 * squashing in case any params are in squashed lists.
61 */
63
64 /* Whether squashable lists are present */
66
67 /*
68 * Count of the number of NULL nodes seen since last appending a value.
69 * These are flushed out to the jumble buffer before subsequent appends
70 * and before performing the final jumble hash.
71 */
72 unsigned int pending_nulls;
73
74#ifdef USE_ASSERT_CHECKING
75 /* The total number of bytes added to the jumble buffer */
76 Size total_jumble_len;
77#endif
79
80/* Values for the compute_query_id GUC */
82{
87};
88
89/* GUC parameters */
91
92
93extern const char *CleanQuerytext(const char *query, int *location, int *len);
94extern JumbleState *JumbleQuery(Query *query);
95extern void EnableQueryId(void);
96
98
99/*
100 * Returns whether query identifier computation has been enabled, either
101 * directly in the GUC or by a module when the setting is 'auto'.
102 */
103static inline bool
105{
107 return false;
109 return true;
110 return query_id_enabled;
111}
112
113#endif /* QUERYJUMBLE_H */
#define PGDLLIMPORT
Definition: c.h:1320
size_t Size
Definition: c.h:611
const void size_t len
struct JumbleState JumbleState
JumbleState * JumbleQuery(Query *query)
ComputeQueryIdType
Definition: queryjumble.h:82
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:85
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:86
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:84
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:83
const char * CleanQuerytext(const char *query, int *location, int *len)
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:104
PGDLLIMPORT bool query_id_enabled
void EnableQueryId(void)
PGDLLIMPORT int compute_query_id
struct LocationLen LocationLen
bool has_squashed_lists
Definition: queryjumble.h:65
unsigned int pending_nulls
Definition: queryjumble.h:72
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:62
LocationLen * clocations
Definition: queryjumble.h:47
int clocations_count
Definition: queryjumble.h:53
bool squashed
Definition: queryjumble.h:28
bool extern_param
Definition: queryjumble.h:31