mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
pg_stat_statements: Widen query IDs from 32 bits to 64 bits.
This takes advantage of the infrastructure introduced by commit
81c5e46c49
to greatly reduce the
likelihood that two different queries will end up with the same query
ID. It's still possible, of course, but whereas before it the chances
of a collision reached 25% around 50,000 queries, it will now take
more than 3 billion queries.
Backward incompatibility: Because the type exposed at the SQL level is
int8, users may now see negative query IDs in the pg_stat_statements
view (and also, query IDs more than 4 billion, which was the old
limit).
Patch by me, reviewed by Michael Paquier and Peter Geoghegan.
Discussion: http://postgr.es/m/CA+TgmobG_Kp4cBKFmsznUAaM1GWW6hhRNiZC0KjRMOOeYnz5Yw@mail.gmail.com
This commit is contained in:
@ -162,7 +162,7 @@ ExecSerializePlan(Plan *plan, EState *estate)
|
||||
*/
|
||||
pstmt = makeNode(PlannedStmt);
|
||||
pstmt->commandType = CMD_SELECT;
|
||||
pstmt->queryId = 0;
|
||||
pstmt->queryId = UINT64CONST(0);
|
||||
pstmt->hasReturning = false;
|
||||
pstmt->hasModifyingCTE = false;
|
||||
pstmt->canSetTag = true;
|
||||
|
@ -54,6 +54,11 @@ static void outChar(StringInfo str, char c);
|
||||
#define WRITE_UINT_FIELD(fldname) \
|
||||
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
|
||||
|
||||
/* Write an unsigned integer field (anything written with UINT64_FORMAT) */
|
||||
#define WRITE_UINT64_FIELD(fldname) \
|
||||
appendStringInfo(str, " :" CppAsString(fldname) " " UINT64_FORMAT, \
|
||||
node->fldname)
|
||||
|
||||
/* Write an OID field (don't hard-wire assumption that OID is same as uint) */
|
||||
#define WRITE_OID_FIELD(fldname) \
|
||||
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
|
||||
@ -260,7 +265,7 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
|
||||
WRITE_NODE_TYPE("PLANNEDSTMT");
|
||||
|
||||
WRITE_ENUM_FIELD(commandType, CmdType);
|
||||
WRITE_UINT_FIELD(queryId);
|
||||
WRITE_UINT64_FIELD(queryId);
|
||||
WRITE_BOOL_FIELD(hasReturning);
|
||||
WRITE_BOOL_FIELD(hasModifyingCTE);
|
||||
WRITE_BOOL_FIELD(canSetTag);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "nodes/parsenodes.h"
|
||||
#include "nodes/plannodes.h"
|
||||
#include "nodes/readfuncs.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -70,6 +71,12 @@
|
||||
token = pg_strtok(&length); /* get field value */ \
|
||||
local_node->fldname = atoui(token)
|
||||
|
||||
/* Read an unsigned integer field (anything written using UINT64_FORMAT) */
|
||||
#define READ_UINT64_FIELD(fldname) \
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
token = pg_strtok(&length); /* get field value */ \
|
||||
local_node->fldname = pg_strtouint64(token, NULL, 10)
|
||||
|
||||
/* Read an long integer field (anything written as ":fldname %ld") */
|
||||
#define READ_LONG_FIELD(fldname) \
|
||||
token = pg_strtok(&length); /* skip :fldname */ \
|
||||
@ -231,7 +238,7 @@ _readQuery(void)
|
||||
|
||||
READ_ENUM_FIELD(commandType, CmdType);
|
||||
READ_ENUM_FIELD(querySource, QuerySource);
|
||||
local_node->queryId = 0; /* not saved in output format */
|
||||
local_node->queryId = UINT64CONST(0); /* not saved in output format */
|
||||
READ_BOOL_FIELD(canSetTag);
|
||||
READ_NODE_FIELD(utilityStmt);
|
||||
READ_INT_FIELD(resultRelation);
|
||||
@ -1456,7 +1463,7 @@ _readPlannedStmt(void)
|
||||
READ_LOCALS(PlannedStmt);
|
||||
|
||||
READ_ENUM_FIELD(commandType, CmdType);
|
||||
READ_UINT_FIELD(queryId);
|
||||
READ_UINT64_FIELD(queryId);
|
||||
READ_BOOL_FIELD(hasReturning);
|
||||
READ_BOOL_FIELD(hasModifyingCTE);
|
||||
READ_BOOL_FIELD(canSetTag);
|
||||
|
@ -3575,7 +3575,7 @@ RewriteQuery(Query *parsetree, List *rewrite_events)
|
||||
List *
|
||||
QueryRewrite(Query *parsetree)
|
||||
{
|
||||
uint32 input_query_id = parsetree->queryId;
|
||||
uint64 input_query_id = parsetree->queryId;
|
||||
List *querylist;
|
||||
List *results;
|
||||
ListCell *l;
|
||||
|
@ -111,7 +111,7 @@ typedef struct Query
|
||||
|
||||
QuerySource querySource; /* where did I come from? */
|
||||
|
||||
uint32 queryId; /* query identifier (can be set by plugins) */
|
||||
uint64 queryId; /* query identifier (can be set by plugins) */
|
||||
|
||||
bool canSetTag; /* do I set the command result tag? */
|
||||
|
||||
|
@ -44,7 +44,7 @@ typedef struct PlannedStmt
|
||||
|
||||
CmdType commandType; /* select|insert|update|delete|utility */
|
||||
|
||||
uint32 queryId; /* query identifier (copied from Query) */
|
||||
uint64 queryId; /* query identifier (copied from Query) */
|
||||
|
||||
bool hasReturning; /* is it insert|update|delete RETURNING? */
|
||||
|
||||
|
Reference in New Issue
Block a user