codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * queryjumble.h4 * Query normalization and fingerprinting.5 *6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group7 * Portions Copyright (c) 1994, Regents of the University of California8 *9 * IDENTIFICATION10 * src/include/nodes/queryjumble.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef QUERYJUMBLE_H15#define QUERYJUMBLE_H16 17#include "nodes/parsenodes.h"18 19/*20 * Struct for tracking locations/lengths of constants during normalization21 */22typedef struct LocationLen23{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 normalized30 * query string31 */32typedef struct JumbleState33{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 */54enum ComputeQueryIdType55{56 COMPUTE_QUERY_ID_OFF,57 COMPUTE_QUERY_ID_ON,58 COMPUTE_QUERY_ID_AUTO,59 COMPUTE_QUERY_ID_REGRESS60};61 62/* GUC parameters */63extern PGDLLIMPORT int compute_query_id;64 65 66extern const char *CleanQuerytext(const char *query, int *location, int *len);67extern JumbleState *JumbleQuery(Query *query);68extern void EnableQueryId(void);69 70extern PGDLLIMPORT bool query_id_enabled;71 72/*73 * Returns whether query identifier computation has been enabled, either74 * directly in the GUC or by a module when the setting is 'auto'.75 */76static inline bool77IsQueryIdEnabled(void)78{79 if (compute_query_id == COMPUTE_QUERY_ID_OFF)80 return false;81 if (compute_query_id == COMPUTE_QUERY_ID_ON)82 return true;83 return query_id_enabled;84}85 86#endif /* QUERYJUMBLE_H */87 