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

Commit7dcbeca

Browse files
michaelpqpull[bot]
authored andcommitted
Make auto_explain print the query identifier in verbose mode
When auto_explain.log_verbose is on, auto_explain should print in thelogs plans equivalent to the EXPLAIN (VERBOSE). However, whencompute_query_id is on, query identifiers were not showing up, beingonly handled by EXPLAIN (VERBOSE). This brings auto_explain on par withEXPLAIN regarding that. Note that like EXPLAIN, auto_explain does notshow the query identifier when compute_query_id=regress.The change is done so as the choice of printing the query identifier isdone in ExplainPrintPlan() rather than in ExplainOnePlan(), to avoid aduplication of the logic dealing with the query ID. auto_explain is theonly in-core caller of ExplainPrintPlan().While looking at the area, I have noticed that more consolidationbetween EXPLAIN and auto_explain would be in order for the logging ofthe plan duration and the buffer usage. This refactoring is left as afuture change.Author: Atsushi TorikoshiReviewed-by: Justin Pryzby, Julien RouhaudDiscussion:https://postgr.es/m/1ea21936981f161bccfce05765c03bee@oss.nttdata.com
1 parentc832047 commit7dcbeca

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

‎contrib/auto_explain/t/001_auto_explain.pl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ sub query_log
106106
qr/Query Parameters:/,
107107
"query parameters not logged when disabled, text mode");
108108

109+
# Query Identifier.
110+
# Logging enabled.
111+
$log_contents = query_log(
112+
$node,
113+
"SELECT * FROM pg_class;",
114+
{
115+
"auto_explain.log_verbose"=>"on",
116+
"compute_query_id"=>"on"
117+
});
118+
119+
like(
120+
$log_contents,
121+
qr/Query Identifier:/,
122+
"query identifier logged with compute_query_id=on, text mode");
123+
124+
# Logging disabled.
125+
$log_contents = query_log(
126+
$node,
127+
"SELECT * FROM pg_class;",
128+
{
129+
"auto_explain.log_verbose"=>"on",
130+
"compute_query_id"=>"regress"
131+
});
132+
133+
unlike(
134+
$log_contents,
135+
qr/Query Identifier:/,
136+
"query identifier not logged with compute_query_id=regress, text mode");
137+
109138
# JSON format.
110139
$log_contents = query_log(
111140
$node,

‎src/backend/commands/explain.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -604,22 +604,6 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
604604
/* Create textual dump of plan tree */
605605
ExplainPrintPlan(es,queryDesc);
606606

607-
/*
608-
* COMPUTE_QUERY_ID_REGRESS means COMPUTE_QUERY_ID_AUTO, but we don't show
609-
* the queryid in any of the EXPLAIN plans to keep stable the results
610-
* generated by regression test suites.
611-
*/
612-
if (es->verbose&&plannedstmt->queryId!=UINT64CONST(0)&&
613-
compute_query_id!=COMPUTE_QUERY_ID_REGRESS)
614-
{
615-
/*
616-
* Output the queryid as an int64 rather than a uint64 so we match
617-
* what would be seen in the BIGINT pg_stat_statements.queryid column.
618-
*/
619-
ExplainPropertyInteger("Query Identifier",NULL, (int64)
620-
plannedstmt->queryId,es);
621-
}
622-
623607
/* Show buffer usage in planning */
624608
if (bufusage)
625609
{
@@ -791,6 +775,22 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
791775
* don't match the built-in defaults.
792776
*/
793777
ExplainPrintSettings(es);
778+
779+
/*
780+
* COMPUTE_QUERY_ID_REGRESS means COMPUTE_QUERY_ID_AUTO, but we don't show
781+
* the queryid in any of the EXPLAIN plans to keep stable the results
782+
* generated by regression test suites.
783+
*/
784+
if (es->verbose&&queryDesc->plannedstmt->queryId!=UINT64CONST(0)&&
785+
compute_query_id!=COMPUTE_QUERY_ID_REGRESS)
786+
{
787+
/*
788+
* Output the queryid as an int64 rather than a uint64 so we match
789+
* what would be seen in the BIGINT pg_stat_statements.queryid column.
790+
*/
791+
ExplainPropertyInteger("Query Identifier",NULL, (int64)
792+
queryDesc->plannedstmt->queryId,es);
793+
}
794794
}
795795

796796
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp