Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d2d972

Browse files
committed
Make auto_explain print the query identifier in verbose mode
When auto_explain.log_verbose is on, auto_explain should print in the logs plans equivalent to the EXPLAIN (VERBOSE). However, when compute_query_id is on, query identifiers were not showing up, being only handled by EXPLAIN (VERBOSE). This brings auto_explain on par with EXPLAIN regarding that. Note that like EXPLAIN, auto_explain does not show the query identifier when compute_query_id=regress. The change is done so as the choice of printing the query identifier is done in ExplainPrintPlan() rather than in ExplainOnePlan(), to avoid a duplication of the logic dealing with the query ID. auto_explain is the only in-core caller of ExplainPrintPlan(). While looking at the area, I have noticed that more consolidation between EXPLAIN and auto_explain would be in order for the logging of the plan duration and the buffer usage. This refactoring is left as a future change. Author: Atsushi Torikoshi Reviewed-by: Justin Pryzby, Julien Rouhaud Discussion: https://postgr.es/m/1ea21936981f161bccfce05765c03bee@oss.nttdata.com
1 parent ffcf6f4 commit 9d2d972

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

contrib/auto_explain/t/001_auto_explain.pl

+29
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

+16-16
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)