PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
queryjumble.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for queryjumble.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LocationLen
 
struct  JumbleState
 

Typedefs

typedef struct LocationLen LocationLen
 
typedef struct JumbleState JumbleState
 

Enumerations

enum  ComputeQueryIdType { COMPUTE_QUERY_ID_OFF , COMPUTE_QUERY_ID_ON , COMPUTE_QUERY_ID_AUTO , COMPUTE_QUERY_ID_REGRESS }
 

Functions

const char * CleanQuerytext (const char *query, int *location, int *len)
 
JumbleStateJumbleQuery (Query *query)
 
void EnableQueryId (void)
 
static bool IsQueryIdEnabled (void)
 

Variables

PGDLLIMPORT int compute_query_id
 
PGDLLIMPORT bool query_id_enabled
 

Typedef Documentation

◆ JumbleState

typedef struct JumbleState JumbleState

◆ LocationLen

typedef struct LocationLen LocationLen

Enumeration Type Documentation

◆ ComputeQueryIdType

Enumerator
COMPUTE_QUERY_ID_OFF 
COMPUTE_QUERY_ID_ON 
COMPUTE_QUERY_ID_AUTO 
COMPUTE_QUERY_ID_REGRESS 

Definition at line 72 of file queryjumble.h.

73{
78};
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:76
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:77
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:75
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:74

Function Documentation

◆ CleanQuerytext()

const char * CleanQuerytext ( const char *  query,
int *  location,
int *  len 
)

Definition at line 79 of file queryjumblefuncs.c.

80{
81 int query_location = *location;
82 int query_len = *len;
83
84 /* First apply starting offset, unless it's -1 (unknown). */
85 if (query_location >= 0)
86 {
87 Assert(query_location <= strlen(query));
88 query += query_location;
89 /* Length of 0 (or -1) means "rest of string" */
90 if (query_len <= 0)
91 query_len = strlen(query);
92 else
93 Assert(query_len <= strlen(query));
94 }
95 else
96 {
97 /* If query location is unknown, distrust query_len as well */
98 query_location = 0;
99 query_len = strlen(query);
100 }
101
102 /*
103 * Discard leading and trailing whitespace, too. Use scanner_isspace()
104 * not libc's isspace(), because we want to match the lexer's behavior.
105 *
106 * Note: the parser now strips leading comments and whitespace from the
107 * reported stmt_location, so this first loop will only iterate in the
108 * unusual case that the location didn't propagate to here. But the
109 * statement length will extend to the end-of-string or terminating
110 * semicolon, so the second loop often does something useful.
111 */
112 while (query_len > 0 && scanner_isspace(query[0]))
113 query++, query_location++, query_len--;
114 while (query_len > 0 && scanner_isspace(query[query_len - 1]))
115 query_len--;
116
117 *location = query_location;
118 *len = query_len;
119
120 return query;
121}
Assert(PointerIsAligned(start, uint64))
const void size_t len
bool scanner_isspace(char ch)
Definition: scansup.c:117

References Assert(), len, and scanner_isspace().

Referenced by pgss_store(), and script_error_callback().

◆ EnableQueryId()

void EnableQueryId ( void  )

Definition at line 162 of file queryjumblefuncs.c.

163{
165 query_id_enabled = true;
166}
bool query_id_enabled
int compute_query_id

References compute_query_id, COMPUTE_QUERY_ID_OFF, and query_id_enabled.

Referenced by _PG_init().

◆ IsQueryIdEnabled()

static bool IsQueryIdEnabled ( void  )
inlinestatic

◆ JumbleQuery()

JumbleState * JumbleQuery ( Query query)

Definition at line 130 of file queryjumblefuncs.c.

131{
132 JumbleState *jstate;
133
135
136 jstate = InitJumble();
137
138 query->queryId = DoJumble(jstate, (Node *) query);
139
140 /*
141 * If we are unlucky enough to get a hash of zero, use 1 instead for
142 * normal statements and 2 for utility queries.
143 */
144 if (query->queryId == UINT64CONST(0))
145 {
146 if (query->utilityStmt)
147 query->queryId = UINT64CONST(2);
148 else
149 query->queryId = UINT64CONST(1);
150 }
151
152 return jstate;
153}
#define UINT64CONST(x)
Definition: c.h:517
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:95
static uint64 DoJumble(JumbleState *jstate, Node *node)
static JumbleState * InitJumble(void)
Definition: nodes.h:135
Node * utilityStmt
Definition: parsenodes.h:136

References Assert(), DoJumble(), InitJumble(), IsQueryIdEnabled(), UINT64CONST, and Query::utilityStmt.

Referenced by ExecCreateTableAs(), ExplainOneUtility(), ExplainQuery(), parse_analyze_fixedparams(), parse_analyze_varparams(), parse_analyze_withcb(), and PerformCursorOpen().

Variable Documentation

◆ compute_query_id

PGDLLIMPORT int compute_query_id
extern

Definition at line 47 of file queryjumblefuncs.c.

Referenced by EnableQueryId(), ExplainPrintPlan(), and IsQueryIdEnabled().

◆ query_id_enabled

PGDLLIMPORT bool query_id_enabled
extern

Definition at line 56 of file queryjumblefuncs.c.

Referenced by EnableQueryId(), and IsQueryIdEnabled().