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 81 of file queryjumble.h.

82{
87};
@ COMPUTE_QUERY_ID_AUTO
Definition: queryjumble.h:85
@ COMPUTE_QUERY_ID_REGRESS
Definition: queryjumble.h:86
@ COMPUTE_QUERY_ID_ON
Definition: queryjumble.h:84
@ COMPUTE_QUERY_ID_OFF
Definition: queryjumble.h:83

Function Documentation

◆ CleanQuerytext()

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

Definition at line 86 of file queryjumblefuncs.c.

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

170{
172 query_id_enabled = true;
173}
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 137 of file queryjumblefuncs.c.

138{
139 JumbleState *jstate;
140
142
143 jstate = InitJumble();
144
145 query->queryId = DoJumble(jstate, (Node *) query);
146
147 /*
148 * If we are unlucky enough to get a hash of zero, use 1 instead for
149 * normal statements and 2 for utility queries.
150 */
151 if (query->queryId == INT64CONST(0))
152 {
153 if (query->utilityStmt)
154 query->queryId = INT64CONST(2);
155 else
156 query->queryId = INT64CONST(1);
157 }
158
159 return jstate;
160}
#define INT64CONST(x)
Definition: c.h:556
static bool IsQueryIdEnabled(void)
Definition: queryjumble.h:104
static int64 DoJumble(JumbleState *jstate, Node *node)
static JumbleState * InitJumble(void)
Definition: nodes.h:135
Node * utilityStmt
Definition: parsenodes.h:141

References Assert(), DoJumble(), InitJumble(), INT64CONST, IsQueryIdEnabled(), 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 52 of file queryjumblefuncs.c.

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

◆ query_id_enabled

PGDLLIMPORT bool query_id_enabled
extern

Definition at line 61 of file queryjumblefuncs.c.

Referenced by EnableQueryId(), and IsQueryIdEnabled().