2021-04-07 13:06:47 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* queryjumble.h
|
|
|
|
|
* Query normalization and fingerprinting.
|
|
|
|
|
*
|
2026-01-01 13:24:10 -05:00
|
|
|
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
2021-04-07 13:06:47 -04:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
2023-01-20 21:48:37 -05:00
|
|
|
* src/include/nodes/queryjumble.h
|
2021-04-07 13:06:47 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2023-05-01 23:23:08 -04:00
|
|
|
#ifndef QUERYJUMBLE_H
|
|
|
|
|
#define QUERYJUMBLE_H
|
2021-04-07 13:06:47 -04:00
|
|
|
|
|
|
|
|
#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 */
|
2025-03-18 13:56:11 -04:00
|
|
|
|
2025-06-24 13:36:32 -04:00
|
|
|
/* Does this location represent a squashed list? */
|
2025-03-18 13:56:11 -04:00
|
|
|
bool squashed;
|
2025-06-24 13:36:32 -04:00
|
|
|
|
|
|
|
|
/* Is this location a PARAM_EXTERN parameter? */
|
|
|
|
|
bool extern_param;
|
2021-04-07 13:06:47 -04:00
|
|
|
} 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;
|
|
|
|
|
|
2025-06-24 13:36:32 -04:00
|
|
|
/*
|
|
|
|
|
* ID of the highest PARAM_EXTERN parameter we've seen in the query; used
|
|
|
|
|
* to start normalization correctly. However, if there are any squashed
|
|
|
|
|
* lists in the query, we disregard query-supplied parameter numbers and
|
|
|
|
|
* renumber everything. This is to avoid possible gaps caused by
|
|
|
|
|
* squashing in case any params are in squashed lists.
|
|
|
|
|
*/
|
2021-04-07 13:06:47 -04:00
|
|
|
int highest_extern_param_id;
|
2025-03-27 01:23:00 -04:00
|
|
|
|
2025-06-24 13:36:32 -04:00
|
|
|
/* Whether squashable lists are present */
|
|
|
|
|
bool has_squashed_lists;
|
|
|
|
|
|
2025-03-27 01:23:00 -04:00
|
|
|
/*
|
|
|
|
|
* Count of the number of NULL nodes seen since last appending a value.
|
|
|
|
|
* These are flushed out to the jumble buffer before subsequent appends
|
|
|
|
|
* and before performing the final jumble hash.
|
|
|
|
|
*/
|
|
|
|
|
unsigned int pending_nulls;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_ASSERT_CHECKING
|
|
|
|
|
/* The total number of bytes added to the jumble buffer */
|
|
|
|
|
Size total_jumble_len;
|
|
|
|
|
#endif
|
2021-04-07 13:06:47 -04:00
|
|
|
} JumbleState;
|
|
|
|
|
|
2021-05-15 14:13:09 -04:00
|
|
|
/* Values for the compute_query_id GUC */
|
|
|
|
|
enum ComputeQueryIdType
|
|
|
|
|
{
|
|
|
|
|
COMPUTE_QUERY_ID_OFF,
|
|
|
|
|
COMPUTE_QUERY_ID_ON,
|
2022-02-21 20:22:15 -05:00
|
|
|
COMPUTE_QUERY_ID_AUTO,
|
|
|
|
|
COMPUTE_QUERY_ID_REGRESS,
|
2021-05-15 14:13:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* GUC parameters */
|
2022-04-08 08:16:38 -04:00
|
|
|
extern PGDLLIMPORT int compute_query_id;
|
2021-05-15 14:13:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
extern const char *CleanQuerytext(const char *query, int *location, int *len);
|
2023-06-27 19:59:36 -04:00
|
|
|
extern JumbleState *JumbleQuery(Query *query);
|
2021-05-15 14:13:09 -04:00
|
|
|
extern void EnableQueryId(void);
|
|
|
|
|
|
2022-04-08 08:16:38 -04:00
|
|
|
extern PGDLLIMPORT bool query_id_enabled;
|
2021-05-15 14:13:09 -04: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 13:06:47 -04:00
|
|
|
|
|
|
|
|
#endif /* QUERYJUMBLE_H */
|