Age Owner TLA Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * queryjumble.h
4 : * Query normalization and fingerprinting.
5 : *
6 : * Portions Copyright (c) 1996-2023, 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 QUERYJUBLE_H
15 : #define QUERYJUBLE_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 */
26 : } LocationLen;
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[] */
38 : Size jumble_len;
39 :
40 : /* Array of locations of constants that should be removed */
41 : LocationLen *clocations;
42 :
43 : /* Allocated length of clocations array */
44 : int clocations_buf_size;
45 :
46 : /* Current number of valid entries in clocations array */
47 : int clocations_count;
48 :
49 : /* highest Param id we've seen, in order to start normalization correctly */
50 : int highest_extern_param_id;
51 : } JumbleState;
52 :
53 : /* Values for the compute_query_id GUC */
54 : enum ComputeQueryIdType
55 : {
56 : COMPUTE_QUERY_ID_OFF,
57 : COMPUTE_QUERY_ID_ON,
58 : COMPUTE_QUERY_ID_AUTO,
59 : COMPUTE_QUERY_ID_REGRESS
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, const char *querytext);
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'.
694 alvherre 75 ECB : */
76 : static inline bool
694 alvherre 77 CBC 640143 : IsQueryIdEnabled(void)
694 alvherre 78 EUB : {
694 alvherre 79 CBC 640143 : if (compute_query_id == COMPUTE_QUERY_ID_OFF)
694 alvherre 80 LBC 0 : return false;
694 alvherre 81 CBC 640143 : if (compute_query_id == COMPUTE_QUERY_ID_ON)
694 alvherre 82 GIC 20 : return true;
83 640123 : return query_id_enabled;
84 : }
85 :
86 : #endif /* QUERYJUMBLE_H */
|