2021-04-07 19:06:47 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* queryjumble.h
|
|
|
|
* Query normalization and fingerprinting.
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2021-04-07 19:06:47 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2023-01-21 03:48:37 +01:00
|
|
|
* src/include/nodes/queryjumble.h
|
2021-04-07 19:06:47 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef QUERYJUBLE_H
|
|
|
|
#define QUERYJUBLE_H
|
|
|
|
|
|
|
|
#include "nodes/parsenodes.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Struct for tracking locations/lengths of constants during normalization
|
|
|
|
*/
|
|
|
|
typedef struct LocationLen
|
|
|
|
{
|
|
|
|
int location; /* start offset in query text */
|
|
|
|
int length; /* length in bytes, or -1 to ignore */
|
|
|
|
} LocationLen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Working state for computing a query jumble and producing a normalized
|
|
|
|
* query string
|
|
|
|
*/
|
|
|
|
typedef struct JumbleState
|
|
|
|
{
|
|
|
|
/* Jumble of current query tree */
|
|
|
|
unsigned char *jumble;
|
|
|
|
|
|
|
|
/* Number of bytes used in jumble[] */
|
|
|
|
Size jumble_len;
|
|
|
|
|
|
|
|
/* Array of locations of constants that should be removed */
|
|
|
|
LocationLen *clocations;
|
|
|
|
|
|
|
|
/* Allocated length of clocations array */
|
|
|
|
int clocations_buf_size;
|
|
|
|
|
|
|
|
/* Current number of valid entries in clocations array */
|
|
|
|
int clocations_count;
|
|
|
|
|
|
|
|
/* highest Param id we've seen, in order to start normalization correctly */
|
|
|
|
int highest_extern_param_id;
|
|
|
|
} JumbleState;
|
|
|
|
|
2021-05-15 20:13:09 +02:00
|
|
|
/* Values for the compute_query_id GUC */
|
|
|
|
enum ComputeQueryIdType
|
|
|
|
{
|
|
|
|
COMPUTE_QUERY_ID_OFF,
|
|
|
|
COMPUTE_QUERY_ID_ON,
|
2022-02-22 02:22:15 +01:00
|
|
|
COMPUTE_QUERY_ID_AUTO,
|
|
|
|
COMPUTE_QUERY_ID_REGRESS
|
2021-05-15 20:13:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* GUC parameters */
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT int compute_query_id;
|
2021-05-15 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
extern const char *CleanQuerytext(const char *query, int *location, int *len);
|
|
|
|
extern JumbleState *JumbleQuery(Query *query, const char *querytext);
|
|
|
|
extern void EnableQueryId(void);
|
|
|
|
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT bool query_id_enabled;
|
2021-05-15 20:13:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns whether query identifier computation has been enabled, either
|
|
|
|
* directly in the GUC or by a module when the setting is 'auto'.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
IsQueryIdEnabled(void)
|
|
|
|
{
|
|
|
|
if (compute_query_id == COMPUTE_QUERY_ID_OFF)
|
|
|
|
return false;
|
|
|
|
if (compute_query_id == COMPUTE_QUERY_ID_ON)
|
|
|
|
return true;
|
|
|
|
return query_id_enabled;
|
|
|
|
}
|
2021-04-07 19:06:47 +02:00
|
|
|
|
|
|
|
#endif /* QUERYJUMBLE_H */
|