Skip to content

Commit 9660834

Browse files
committed
adjust query id feature to use pg_stat_activity.query_id
Previously, it was pg_stat_activity.queryid to match the pg_stat_statements queryid column. This is an adjustment to patch 4f0b096. This also adjusts some of the internal function calls to match. Catversion bumped. Reported-by: Álvaro Herrera, Julien Rouhaud Discussion: https://postgr.es/m/20210408032704.GA7498@alvherre.pgsql
1 parent 7645376 commit 9660834

File tree

14 files changed

+40
-40
lines changed

14 files changed

+40
-40
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
919919

920920
<row>
921921
<entry role="catalog_table_entry"><para role="column_definition">
922-
<structfield>queryid</structfield> <type>bigint</type>
922+
<structfield>query_id</structfield> <type>bigint</type>
923923
</para>
924924
<para>
925925
Identifier of this backend's most recent query. If

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ CREATE VIEW pg_stat_activity AS
833833
S.state,
834834
S.backend_xid,
835835
s.backend_xmin,
836-
S.queryid,
836+
S.query_id,
837837
S.query,
838838
S.backend_type
839839
FROM pg_stat_get_activity(NULL) AS S

src/backend/executor/execMain.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ ExecutorStart(QueryDesc *queryDesc, int eflags)
131131
{
132132
/*
133133
* In some cases (e.g. an EXECUTE statement) a query execution will skip
134-
* parse analysis, which means that the queryid won't be reported. Note
135-
* that it's harmless to report the queryid multiple time, as the call will
136-
* be ignored if the top level queryid has already been reported.
134+
* parse analysis, which means that the query_id won't be reported. Note
135+
* that it's harmless to report the query_id multiple time, as the call will
136+
* be ignored if the top level query_id has already been reported.
137137
*/
138-
pgstat_report_queryid(queryDesc->plannedstmt->queryId, false);
138+
pgstat_report_query_id(queryDesc->plannedstmt->queryId, false);
139139

140140
if (ExecutorStart_hook)
141141
(*ExecutorStart_hook) (queryDesc, eflags);

src/backend/executor/execParallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ExecSerializePlan(Plan *plan, EState *estate)
175175
*/
176176
pstmt = makeNode(PlannedStmt);
177177
pstmt->commandType = CMD_SELECT;
178-
pstmt->queryId = pgstat_get_my_queryid();
178+
pstmt->queryId = pgstat_get_my_query_id();
179179
pstmt->hasReturning = false;
180180
pstmt->hasModifyingCTE = false;
181181
pstmt->canSetTag = true;

src/backend/parser/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ parse_analyze(RawStmt *parseTree, const char *sourceText,
132132

133133
free_parsestate(pstate);
134134

135-
pgstat_report_queryid(query->queryId, false);
135+
pgstat_report_query_id(query->queryId, false);
136136

137137
return query;
138138
}
@@ -171,7 +171,7 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
171171

172172
free_parsestate(pstate);
173173

174-
pgstat_report_queryid(query->queryId, false);
174+
pgstat_report_query_id(query->queryId, false);
175175

176176
return query;
177177
}

src/backend/tcop/postgres.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ pg_analyze_and_rewrite_params(RawStmt *parsetree,
694694

695695
free_parsestate(pstate);
696696

697-
pgstat_report_queryid(query->queryId, false);
697+
pgstat_report_query_id(query->queryId, false);
698698

699699
if (log_parser_stats)
700700
ShowUsage("PARSE ANALYSIS STATISTICS");
@@ -1031,7 +1031,7 @@ exec_simple_query(const char *query_string)
10311031
DestReceiver *receiver;
10321032
int16 format;
10331033

1034-
pgstat_report_queryid(0, true);
1034+
pgstat_report_query_id(0, true);
10351035

10361036
/*
10371037
* Get the command name for use in status display (it also becomes the

src/backend/utils/activity/backend_status.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
544544
beentry->st_activity_start_timestamp = 0;
545545
/* st_xact_start_timestamp and wait_event_info are also disabled */
546546
beentry->st_xact_start_timestamp = 0;
547-
beentry->st_queryid = UINT64CONST(0);
547+
beentry->st_query_id = UINT64CONST(0);
548548
proc->wait_event_info = 0;
549549
PGSTAT_END_WRITE_ACTIVITY(beentry);
550550
}
@@ -605,7 +605,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
605605
* identifier.
606606
*/
607607
if (state == STATE_RUNNING)
608-
beentry->st_queryid = UINT64CONST(0);
608+
beentry->st_query_id = UINT64CONST(0);
609609

610610
if (cmd_str != NULL)
611611
{
@@ -618,32 +618,32 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
618618
}
619619

620620
/* --------
621-
* pgstat_report_queryid() -
621+
* pgstat_report_query_id() -
622622
*
623623
* Called to update top-level query identifier.
624624
* --------
625625
*/
626626
void
627-
pgstat_report_queryid(uint64 queryId, bool force)
627+
pgstat_report_query_id(uint64 query_id, bool force)
628628
{
629629
volatile PgBackendStatus *beentry = MyBEEntry;
630630

631631
/*
632-
* if track_activities is disabled, st_queryid should already have been
632+
* if track_activities is disabled, st_query_id should already have been
633633
* reset
634634
*/
635635
if (!beentry || !pgstat_track_activities)
636636
return;
637637

638638
/*
639-
* We only report the top-level query identifiers. The stored queryid is
639+
* We only report the top-level query identifiers. The stored query_id is
640640
* reset when a backend calls pgstat_report_activity(STATE_RUNNING), or
641641
* with an explicit call to this function using the force flag. If the
642642
* saved query identifier is not zero it means that it's not a top-level
643643
* command, so ignore the one provided unless it's an explicit call to
644644
* reset the identifier.
645645
*/
646-
if (beentry->st_queryid != 0 && !force)
646+
if (beentry->st_query_id != 0 && !force)
647647
return;
648648

649649
/*
@@ -652,7 +652,7 @@ pgstat_report_queryid(uint64 queryId, bool force)
652652
* ensure the compiler doesn't try to get cute.
653653
*/
654654
PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
655-
beentry->st_queryid = queryId;
655+
beentry->st_query_id = query_id;
656656
PGSTAT_END_WRITE_ACTIVITY(beentry);
657657
}
658658

@@ -1022,12 +1022,12 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
10221022
}
10231023

10241024
/* ----------
1025-
* pgstat_get_my_queryid() -
1025+
* pgstat_get_my_query_id() -
10261026
*
10271027
* Return current backend's query identifier.
10281028
*/
10291029
uint64
1030-
pgstat_get_my_queryid(void)
1030+
pgstat_get_my_query_id(void)
10311031
{
10321032
if (!MyBEEntry)
10331033
return 0;
@@ -1037,7 +1037,7 @@ pgstat_get_my_queryid(void)
10371037
* pg_stat_get_activity which is already protected, or from the same
10381038
* backend which means that there won't be concurrent writes.
10391039
*/
1040-
return MyBEEntry->st_queryid;
1040+
return MyBEEntry->st_query_id;
10411041
}
10421042

10431043

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
914914
values[27] = BoolGetDatum(false); /* GSS Encryption not in
915915
* use */
916916
}
917-
if (beentry->st_queryid == 0)
917+
if (beentry->st_query_id == 0)
918918
nulls[29] = true;
919919
else
920-
values[29] = UInt64GetDatum(beentry->st_queryid);
920+
values[29] = UInt64GetDatum(beentry->st_query_id);
921921
}
922922
else
923923
{

src/backend/utils/error/elog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,10 +2717,10 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
27172717
case 'Q':
27182718
if (padding != 0)
27192719
appendStringInfo(buf, "%*lld", padding,
2720-
(long long) pgstat_get_my_queryid());
2720+
(long long) pgstat_get_my_query_id());
27212721
else
27222722
appendStringInfo(buf, "%lld",
2723-
(long long) pgstat_get_my_queryid());
2723+
(long long) pgstat_get_my_query_id());
27242724
break;
27252725
default:
27262726
/* format error - ignore it */
@@ -2967,7 +2967,7 @@ write_csvlog(ErrorData *edata)
29672967
appendStringInfoChar(&buf, ',');
29682968

29692969
/* query id */
2970-
appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_queryid());
2970+
appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_query_id());
29712971

29722972
appendStringInfoChar(&buf, '\n');
29732973

src/backend/utils/misc/queryjumble.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#define JUMBLE_SIZE 1024 /* query serialization buffer size */
4141

42-
static uint64 compute_utility_queryid(const char *str, int query_location, int query_len);
42+
static uint64 compute_utility_query_id(const char *str, int query_location, int query_len);
4343
static void AppendJumble(JumbleState *jstate,
4444
const unsigned char *item, Size size);
4545
static void JumbleQueryInternal(JumbleState *jstate, Query *query);
@@ -97,7 +97,7 @@ JumbleQuery(Query *query, const char *querytext)
9797
JumbleState *jstate = NULL;
9898
if (query->utilityStmt)
9999
{
100-
query->queryId = compute_utility_queryid(querytext,
100+
query->queryId = compute_utility_query_id(querytext,
101101
query->stmt_location,
102102
query->stmt_len);
103103
}
@@ -135,7 +135,7 @@ JumbleQuery(Query *query, const char *querytext)
135135
* Compute a query identifier for the given utility query string.
136136
*/
137137
static uint64
138-
compute_utility_queryid(const char *query_text, int query_location, int query_len)
138+
compute_utility_query_id(const char *query_text, int query_location, int query_len)
139139
{
140140
uint64 queryId;
141141
const char *sql;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy