mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +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:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user