Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3eda50

Browse files
committed
Change internal queryid type from uint64 to int64
uint64 was perhaps chosen incff440d as the type was uint32 prior tothat widening work.Having this as uint64 doesn't make much sense and just adds the overhead ofhaving to remember that we always output this in its signed form. Let'sremove that overhead.The signed form output is seemingly required since we have no way torepresent the full range of uint64 in an SQL type. We use BIGINT in placeslike pg_stat_statements, which maps directly to int64.The release notes "Source Code" section may want to mention thisadjustment as some extensions may wish to adjust their code.Author: David Rowley <dgrowleyml@gmail.com>Suggested-by: Peter Eisentraut <peter@eisentraut.org>Reviewed-by: Sami Imseih <samimseih@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/50cb0c8b-994b-48f9-a1c4-13039eb3536b@eisentraut.org
1 parent03c53a7 commitc3eda50

File tree

16 files changed

+73
-55
lines changed

16 files changed

+73
-55
lines changed

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ typedef struct pgssHashKey
144144
{
145145
Oiduserid;/* user OID */
146146
Oiddbid;/* database OID */
147-
uint64queryid;/* query identifier */
147+
int64queryid;/* query identifier */
148148
booltoplevel;/* query executed at top level */
149149
}pgssHashKey;
150150

@@ -346,7 +346,7 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
346346
ProcessUtilityContextcontext,ParamListInfoparams,
347347
QueryEnvironment*queryEnv,
348348
DestReceiver*dest,QueryCompletion*qc);
349-
staticvoidpgss_store(constchar*query,uint64queryId,
349+
staticvoidpgss_store(constchar*query,int64queryId,
350350
intquery_location,intquery_len,
351351
pgssStoreKindkind,
352352
doubletotal_time,uint64rows,
@@ -370,7 +370,7 @@ static char *qtext_fetch(Size query_offset, int query_len,
370370
char*buffer,Sizebuffer_size);
371371
staticboolneed_gc_qtexts(void);
372372
staticvoidgc_qtexts(void);
373-
staticTimestampTzentry_reset(Oiduserid,Oiddbid,uint64queryid,boolminmax_only);
373+
staticTimestampTzentry_reset(Oiduserid,Oiddbid,int64queryid,boolminmax_only);
374374
staticchar*generate_normalized_query(JumbleState*jstate,constchar*query,
375375
intquery_loc,int*query_len_p);
376376
staticvoidfill_in_constant_lengths(JumbleState*jstate,constchar*query,
@@ -852,7 +852,7 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
852852
{
853853
if (pgss_track_utility&&IsA(query->utilityStmt,ExecuteStmt))
854854
{
855-
query->queryId=UINT64CONST(0);
855+
query->queryId=INT64CONST(0);
856856
return;
857857
}
858858
}
@@ -899,7 +899,7 @@ pgss_planner(Query *parse,
899899
*/
900900
if (pgss_enabled(nesting_level)
901901
&&pgss_track_planning&&query_string
902-
&&parse->queryId!=UINT64CONST(0))
902+
&&parse->queryId!=INT64CONST(0))
903903
{
904904
instr_timestart;
905905
instr_timeduration;
@@ -1002,7 +1002,7 @@ pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
10021002
* counting of optimizable statements that are directly contained in
10031003
* utility statements.
10041004
*/
1005-
if (pgss_enabled(nesting_level)&&queryDesc->plannedstmt->queryId!=UINT64CONST(0))
1005+
if (pgss_enabled(nesting_level)&&queryDesc->plannedstmt->queryId!=INT64CONST(0))
10061006
{
10071007
/*
10081008
* Set up to track total elapsed time in ExecutorRun. Make sure the
@@ -1068,9 +1068,9 @@ pgss_ExecutorFinish(QueryDesc *queryDesc)
10681068
staticvoid
10691069
pgss_ExecutorEnd(QueryDesc*queryDesc)
10701070
{
1071-
uint64queryId=queryDesc->plannedstmt->queryId;
1071+
int64queryId=queryDesc->plannedstmt->queryId;
10721072

1073-
if (queryId!=UINT64CONST(0)&&queryDesc->totaltime&&
1073+
if (queryId!=INT64CONST(0)&&queryDesc->totaltime&&
10741074
pgss_enabled(nesting_level))
10751075
{
10761076
/*
@@ -1111,7 +1111,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
11111111
DestReceiver*dest,QueryCompletion*qc)
11121112
{
11131113
Node*parsetree=pstmt->utilityStmt;
1114-
uint64saved_queryId=pstmt->queryId;
1114+
int64saved_queryId=pstmt->queryId;
11151115
intsaved_stmt_location=pstmt->stmt_location;
11161116
intsaved_stmt_len=pstmt->stmt_len;
11171117
boolenabled=pgss_track_utility&&pgss_enabled(nesting_level);
@@ -1131,7 +1131,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
11311131
* only.
11321132
*/
11331133
if (enabled)
1134-
pstmt->queryId=UINT64CONST(0);
1134+
pstmt->queryId=INT64CONST(0);
11351135

11361136
/*
11371137
* If it's an EXECUTE statement, we don't track it and don't increment the
@@ -1278,7 +1278,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
12781278
* for the arrays in the Counters field.
12791279
*/
12801280
staticvoid
1281-
pgss_store(constchar*query,uint64queryId,
1281+
pgss_store(constchar*query,int64queryId,
12821282
intquery_location,intquery_len,
12831283
pgssStoreKindkind,
12841284
doubletotal_time,uint64rows,
@@ -1304,7 +1304,7 @@ pgss_store(const char *query, uint64 queryId,
13041304
* Nothing to do if compute_query_id isn't enabled and no other module
13051305
* computed a query identifier.
13061306
*/
1307-
if (queryId==UINT64CONST(0))
1307+
if (queryId==INT64CONST(0))
13081308
return;
13091309

13101310
/*
@@ -1514,11 +1514,11 @@ pg_stat_statements_reset_1_7(PG_FUNCTION_ARGS)
15141514
{
15151515
Oiduserid;
15161516
Oiddbid;
1517-
uint64queryid;
1517+
int64queryid;
15181518

15191519
userid=PG_GETARG_OID(0);
15201520
dbid=PG_GETARG_OID(1);
1521-
queryid=(uint64)PG_GETARG_INT64(2);
1521+
queryid=PG_GETARG_INT64(2);
15221522

15231523
entry_reset(userid,dbid,queryid, false);
15241524

@@ -1530,12 +1530,12 @@ pg_stat_statements_reset_1_11(PG_FUNCTION_ARGS)
15301530
{
15311531
Oiduserid;
15321532
Oiddbid;
1533-
uint64queryid;
1533+
int64queryid;
15341534
boolminmax_only;
15351535

15361536
userid=PG_GETARG_OID(0);
15371537
dbid=PG_GETARG_OID(1);
1538-
queryid=(uint64)PG_GETARG_INT64(2);
1538+
queryid=PG_GETARG_INT64(2);
15391539
minmax_only=PG_GETARG_BOOL(3);
15401540

15411541
PG_RETURN_TIMESTAMPTZ(entry_reset(userid,dbid,queryid,minmax_only));
@@ -2671,7 +2671,7 @@ if (e) { \
26712671
* Reset entries corresponding to parameters passed.
26722672
*/
26732673
staticTimestampTz
2674-
entry_reset(Oiduserid,Oiddbid,uint64queryid,boolminmax_only)
2674+
entry_reset(Oiduserid,Oiddbid,int64queryid,boolminmax_only)
26752675
{
26762676
HASH_SEQ_STATUShash_seq;
26772677
pgssEntry*entry;
@@ -2691,7 +2691,7 @@ entry_reset(Oid userid, Oid dbid, uint64 queryid, bool minmax_only)
26912691

26922692
stats_reset=GetCurrentTimestamp();
26932693

2694-
if (userid!=0&&dbid!=0&&queryid!=UINT64CONST(0))
2694+
if (userid!=0&&dbid!=0&&queryid!=INT64CONST(0))
26952695
{
26962696
/* If all the parameters are available, use the fast path. */
26972697
memset(&key,0,sizeof(pgssHashKey));
@@ -2714,7 +2714,7 @@ entry_reset(Oid userid, Oid dbid, uint64 queryid, bool minmax_only)
27142714

27152715
SINGLE_ENTRY_RESET(entry);
27162716
}
2717-
elseif (userid!=0||dbid!=0||queryid!=UINT64CONST(0))
2717+
elseif (userid!=0||dbid!=0||queryid!=INT64CONST(0))
27182718
{
27192719
/* Reset entries corresponding to valid parameters. */
27202720
hash_seq_init(&hash_seq,pgss_hash);

‎src/backend/access/brin/brin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ typedef struct BrinShared
6868
intscantuplesortstates;
6969

7070
/* Query ID, for report in worker processes */
71-
uint64queryid;
71+
int64queryid;
7272

7373
/*
7474
* workersdonecv is used to monitor the progress of workers. All parallel

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ typedef struct BTShared
105105
intscantuplesortstates;
106106

107107
/* Query ID, for report in worker processes */
108-
uint64queryid;
108+
int64queryid;
109109

110110
/*
111111
* workersdonecv is used to monitor the progress of workers. All parallel

‎src/backend/commands/explain.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,14 +811,10 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
811811
* the queryid in any of the EXPLAIN plans to keep stable the results
812812
* generated by regression test suites.
813813
*/
814-
if (es->verbose&&queryDesc->plannedstmt->queryId!=UINT64CONST(0)&&
814+
if (es->verbose&&queryDesc->plannedstmt->queryId!=INT64CONST(0)&&
815815
compute_query_id!=COMPUTE_QUERY_ID_REGRESS)
816816
{
817-
/*
818-
* Output the queryid as an int64 rather than a uint64 so we match
819-
* what would be seen in the BIGINT pg_stat_statements.queryid column.
820-
*/
821-
ExplainPropertyInteger("Query Identifier",NULL, (int64)
817+
ExplainPropertyInteger("Query Identifier",NULL,
822818
queryDesc->plannedstmt->queryId,es);
823819
}
824820
}

‎src/backend/commands/vacuumparallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct PVShared
6363
*/
6464
Oidrelid;
6565
intelevel;
66-
uint64queryid;
66+
int64queryid;
6767

6868
/*
6969
* Fields for both index vacuum and cleanup.

‎src/backend/nodes/gen_node_support.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,11 @@ sub elem
10391039
print$off"\tWRITE_UINT_FIELD($f);\n";
10401040
print$rff"\tREAD_UINT_FIELD($f);\n"unless$no_read;
10411041
}
1042+
elsif ($teq'int64')
1043+
{
1044+
print$off"\tWRITE_INT64_FIELD($f);\n";
1045+
print$rff"\tREAD_INT64_FIELD($f);\n"unless$no_read;
1046+
}
10421047
elsif ($teq'uint64'
10431048
||$teq'AclMode')
10441049
{

‎src/backend/nodes/outfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static void outDouble(StringInfo str, double d);
5151
#defineWRITE_UINT_FIELD(fldname) \
5252
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
5353

54+
/* Write a signed integer field (anything written with INT64_FORMAT) */
55+
#defineWRITE_INT64_FIELD(fldname) \
56+
appendStringInfo(str, \
57+
" :" CppAsString(fldname) " " INT64_FORMAT, \
58+
node->fldname)
59+
5460
/* Write an unsigned integer field (anything written with UINT64_FORMAT) */
5561
#defineWRITE_UINT64_FIELD(fldname) \
5662
appendStringInfo(str, " :" CppAsString(fldname) " " UINT64_FORMAT, \

‎src/backend/nodes/queryjumblefuncs.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ intcompute_query_id = COMPUTE_QUERY_ID_AUTO;
5656
boolquery_id_enabled= false;
5757

5858
staticJumbleState*InitJumble(void);
59-
staticuint64DoJumble(JumbleState*jstate,Node*node);
59+
staticint64DoJumble(JumbleState*jstate,Node*node);
6060
staticvoidAppendJumble(JumbleState*jstate,
6161
constunsignedchar*value,Sizesize);
6262
staticvoidFlushPendingNulls(JumbleState*jstate);
@@ -141,12 +141,12 @@ JumbleQuery(Query *query)
141141
* If we are unlucky enough to get a hash of zero, use 1 instead for
142142
* normal statements and 2 for utility queries.
143143
*/
144-
if (query->queryId==UINT64CONST(0))
144+
if (query->queryId==INT64CONST(0))
145145
{
146146
if (query->utilityStmt)
147-
query->queryId=UINT64CONST(2);
147+
query->queryId=INT64CONST(2);
148148
else
149-
query->queryId=UINT64CONST(1);
149+
query->queryId=INT64CONST(1);
150150
}
151151

152152
returnjstate;
@@ -197,7 +197,7 @@ InitJumble(void)
197197
*Jumble the given Node using the given JumbleState and return the resulting
198198
*jumble hash.
199199
*/
200-
staticuint64
200+
staticint64
201201
DoJumble(JumbleState*jstate,Node*node)
202202
{
203203
/* Jumble the given node */
@@ -208,9 +208,9 @@ DoJumble(JumbleState *jstate, Node *node)
208208
FlushPendingNulls(jstate);
209209

210210
/* Process the jumble buffer and produce the hash value */
211-
returnDatumGetUInt64(hash_any_extended(jstate->jumble,
212-
jstate->jumble_len,
213-
0));
211+
returnDatumGetInt64(hash_any_extended(jstate->jumble,
212+
jstate->jumble_len,
213+
0));
214214
}
215215

216216
/*
@@ -256,10 +256,10 @@ AppendJumbleInternal(JumbleState *jstate, const unsigned char *item,
256256

257257
if (unlikely(jumble_len >=JUMBLE_SIZE))
258258
{
259-
uint64start_hash;
259+
int64start_hash;
260260

261-
start_hash=DatumGetUInt64(hash_any_extended(jumble,
262-
JUMBLE_SIZE,0));
261+
start_hash=DatumGetInt64(hash_any_extended(jumble,
262+
JUMBLE_SIZE,0));
263263
memcpy(jumble,&start_hash,sizeof(start_hash));
264264
jumble_len=sizeof(start_hash);
265265
}

‎src/backend/nodes/readfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
token=pg_strtok(&length);/* get field value */ \
6969
local_node->fldname=atoui(token)
7070

71+
/* Read a signed integer field (anything written using INT64_FORMAT) */
72+
#defineREAD_INT64_FIELD(fldname) \
73+
token = pg_strtok(&length);/* skip :fldname */ \
74+
token=pg_strtok(&length);/* get field value */ \
75+
local_node->fldname=strtoi64(token,NULL,10)
76+
7177
/* Read an unsigned integer field (anything written using UINT64_FORMAT) */
7278
#defineREAD_UINT64_FIELD(fldname) \
7379
token = pg_strtok(&length);/* skip :fldname */ \

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4544,7 +4544,7 @@ build_generation_expression(Relation rel, int attrno)
45444544
List*
45454545
QueryRewrite(Query*parsetree)
45464546
{
4547-
uint64input_query_id=parsetree->queryId;
4547+
int64input_query_id=parsetree->queryId;
45484548
List*querylist;
45494549
List*results;
45504550
ListCell*l;

‎src/backend/tcop/postgres.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ exec_bind_message(StringInfo input_message)
16821682
{
16831683
Query*query=lfirst_node(Query,lc);
16841684

1685-
if (query->queryId!=UINT64CONST(0))
1685+
if (query->queryId!=INT64CONST(0))
16861686
{
16871687
pgstat_report_query_id(query->queryId, false);
16881688
break;
@@ -2174,7 +2174,7 @@ exec_execute_message(const char *portal_name, long max_rows)
21742174
{
21752175
PlannedStmt*stmt=lfirst_node(PlannedStmt,lc);
21762176

2177-
if (stmt->queryId!=UINT64CONST(0))
2177+
if (stmt->queryId!=INT64CONST(0))
21782178
{
21792179
pgstat_report_query_id(stmt->queryId, false);
21802180
break;

‎src/backend/utils/activity/backend_status.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pgstat_bestart_initial(void)
320320
lbeentry.st_state=STATE_STARTING;
321321
lbeentry.st_progress_command=PROGRESS_COMMAND_INVALID;
322322
lbeentry.st_progress_command_target=InvalidOid;
323-
lbeentry.st_query_id=UINT64CONST(0);
323+
lbeentry.st_query_id=INT64CONST(0);
324324
lbeentry.st_plan_id=UINT64CONST(0);
325325

326326
/*
@@ -599,7 +599,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
599599
beentry->st_activity_start_timestamp=0;
600600
/* st_xact_start_timestamp and wait_event_info are also disabled */
601601
beentry->st_xact_start_timestamp=0;
602-
beentry->st_query_id=UINT64CONST(0);
602+
beentry->st_query_id=INT64CONST(0);
603603
beentry->st_plan_id=UINT64CONST(0);
604604
proc->wait_event_info=0;
605605
PGSTAT_END_WRITE_ACTIVITY(beentry);
@@ -662,7 +662,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
662662
*/
663663
if (state==STATE_RUNNING)
664664
{
665-
beentry->st_query_id=UINT64CONST(0);
665+
beentry->st_query_id=INT64CONST(0);
666666
beentry->st_plan_id=UINT64CONST(0);
667667
}
668668

@@ -683,7 +683,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
683683
* --------
684684
*/
685685
void
686-
pgstat_report_query_id(uint64query_id,boolforce)
686+
pgstat_report_query_id(int64query_id,boolforce)
687687
{
688688
volatilePgBackendStatus*beentry=MyBEEntry;
689689

@@ -702,7 +702,7 @@ pgstat_report_query_id(uint64 query_id, bool force)
702702
* command, so ignore the one provided unless it's an explicit call to
703703
* reset the identifier.
704704
*/
705-
if (beentry->st_query_id!=0&& !force)
705+
if (beentry->st_query_id!=INT64CONST(0)&& !force)
706706
return;
707707

708708
/*
@@ -1134,7 +1134,7 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
11341134
*
11351135
* Return current backend's query identifier.
11361136
*/
1137-
uint64
1137+
int64
11381138
pgstat_get_my_query_id(void)
11391139
{
11401140
if (!MyBEEntry)

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
640640
values[28]=BoolGetDatum(false);/* GSS credentials not
641641
* delegated */
642642
}
643-
if (beentry->st_query_id==0)
643+
if (beentry->st_query_id==INT64CONST(0))
644644
nulls[30]= true;
645645
else
646-
values[30]=UInt64GetDatum(beentry->st_query_id);
646+
values[30]=Int64GetDatum(beentry->st_query_id);
647647
}
648648
else
649649
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp