OSDN Git Service

d197de9b3e3f691b8a7c1a8501c49885d2cff8f5
[pghintplan/pg_hint_plan.git] / normalize_query.h
1 /*-------------------------------------------------------------------------
2  *
3  * normalize_query.h
4  *              Normalize query string.
5  *
6  * This header file is created from pg_stat_statements.c to implement
7  * normalization of query string.
8  *
9  * Portions Copyright (c) 2008-2017, PostgreSQL Global Development Group
10  */
11 #ifndef NORMALIZE_QUERY_H
12 #define NORMALIZE_QUERY_H
13
14 /*
15  * Struct for tracking locations/lengths of constants during normalization
16  */
17 typedef struct pgssLocationLen
18 {
19         int                     location;               /* start offset in query text */
20         int                     length;                 /* length in bytes, or -1 to ignore */
21 } pgssLocationLen;
22
23 /*
24  * Working state for computing a query jumble and producing a normalized
25  * query string
26  */
27 typedef struct pgssJumbleState
28 {
29         /* Jumble of current query tree */
30         unsigned char *jumble;
31
32         /* Number of bytes used in jumble[] */
33         Size            jumble_len;
34
35         /* Array of locations of constants that should be removed */
36         pgssLocationLen *clocations;
37
38         /* Allocated length of clocations array */
39         int                     clocations_buf_size;
40
41         /* Current number of valid entries in clocations array */
42         int                     clocations_count;
43 } pgssJumbleState;
44
45 static char *
46 generate_normalized_query(pgssJumbleState *jstate, const char *query,
47                                                   int *query_len_p, int encoding);
48 static void JumbleQuery(pgssJumbleState *jstate, Query *query);
49
50 #define JUMBLE_SIZE             1024
51
52 #endif  /* NORMALIZE_QUERY_H */