1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Make use of in-core query id added by commit 5fd9dfa5f5

Use the in-core query id computation for pg_stat_activity,
log_line_prefix, and EXPLAIN VERBOSE.

Similar to other fields in pg_stat_activity, only the queryid from the
top level statements are exposed, and if the backends status isn't
active then the queryid from the last executed statements is displayed.

Add a %Q placeholder to include the queryid in log_line_prefix, which
will also only expose top level statements.

For EXPLAIN VERBOSE, if a query identifier has been computed, either by
enabling compute_query_id or using a third-party module, display it.

Bump catalog version.

Discussion: https://postgr.es/m/20210407125726.tkvjdbw76hxnpwfi@nol

Author: Julien Rouhaud

Reviewed-by: Alvaro Herrera, Nitin Jadhav, Zhihong Yu
This commit is contained in:
Bruce Momjian
2021-04-07 14:03:56 -04:00
parent ec7ffb8096
commit 4f0b0966c8
21 changed files with 251 additions and 106 deletions

View File

@@ -543,6 +543,7 @@
# %t = timestamp without milliseconds
# %m = timestamp with milliseconds
# %n = timestamp with milliseconds (as a Unix epoch)
# %Q = query ID (0 if none or not computed)
# %i = command tag
# %e = SQL state
# %c = session ID

View File

@@ -39,7 +39,7 @@
#define JUMBLE_SIZE 1024 /* query serialization buffer size */
static uint64 compute_utility_queryid(const char *str, int query_len);
static uint64 compute_utility_queryid(const char *str, int query_location, int query_len);
static void AppendJumble(JumbleState *jstate,
const unsigned char *item, Size size);
static void JumbleQueryInternal(JumbleState *jstate, Query *query);
@@ -97,17 +97,9 @@ JumbleQuery(Query *query, const char *querytext)
JumbleState *jstate = NULL;
if (query->utilityStmt)
{
const char *sql;
int query_location = query->stmt_location;
int query_len = query->stmt_len;
/*
* Confine our attention to the relevant part of the string, if the
* query is a portion of a multi-statement source string.
*/
sql = CleanQuerytext(querytext, &query_location, &query_len);
query->queryId = compute_utility_queryid(sql, query_len);
query->queryId = compute_utility_queryid(querytext,
query->stmt_location,
query->stmt_len);
}
else
{
@@ -143,11 +135,18 @@ JumbleQuery(Query *query, const char *querytext)
* Compute a query identifier for the given utility query string.
*/
static uint64
compute_utility_queryid(const char *str, int query_len)
compute_utility_queryid(const char *query_text, int query_location, int query_len)
{
uint64 queryId;
const char *sql;
queryId = DatumGetUInt64(hash_any_extended((const unsigned char *) str,
/*
* Confine our attention to the relevant part of the string, if the
* query is a portion of a multi-statement source string.
*/
sql = CleanQuerytext(query_text, &query_location, &query_len);
queryId = DatumGetUInt64(hash_any_extended((const unsigned char *) sql,
query_len, 0));
/*