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

Commitea569d6

Browse files
committed
Add SETTINGS option to EXPLAIN, to print modified settings.
Query planning is affected by a number of configuration options, and itmay be crucial to know which of those options were set to non-defaultvalues. With this patch you can say EXPLAIN (SETTINGS ON) to includethat information in the query plan. Only options affecting planning,with values different from the built-in default are printed.This patch also adds auto_explain.log_settings option, providing thesame capability in auto_explain module.Author: Tomas VondraReviewed-by: Rafia Sabih, John NaylorDiscussion:https://postgr.es/m/e1791b4c-df9c-be02-edc5-7c8874944be0@2ndquadrant.com
1 parentd1f04b9 commitea569d6

File tree

8 files changed

+333
-52
lines changed

8 files changed

+333
-52
lines changed

‎contrib/auto_explain/auto_explain.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static bool auto_explain_log_verbose = false;
2828
staticboolauto_explain_log_buffers= false;
2929
staticboolauto_explain_log_triggers= false;
3030
staticboolauto_explain_log_timing= true;
31+
staticboolauto_explain_log_settings= false;
3132
staticintauto_explain_log_format=EXPLAIN_FORMAT_TEXT;
3233
staticintauto_explain_log_level=LOG;
3334
staticboolauto_explain_log_nested_statements= false;
@@ -112,6 +113,17 @@ _PG_init(void)
112113
NULL,
113114
NULL);
114115

116+
DefineCustomBoolVariable("auto_explain.log_settings",
117+
"Log modified configuration parameters affecting query planning.",
118+
NULL,
119+
&auto_explain_log_settings,
120+
false,
121+
PGC_SUSET,
122+
0,
123+
NULL,
124+
NULL,
125+
NULL);
126+
115127
DefineCustomBoolVariable("auto_explain.log_verbose",
116128
"Use EXPLAIN VERBOSE for plan logging.",
117129
NULL,
@@ -356,6 +368,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
356368
es->timing= (es->analyze&&auto_explain_log_timing);
357369
es->summary=es->analyze;
358370
es->format=auto_explain_log_format;
371+
es->settings=auto_explain_log_settings;
359372

360373
ExplainBeginOutput(es);
361374
ExplainQueryText(es,queryDesc);

‎doc/src/sgml/auto-explain.sgml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,24 @@ LOAD 'auto_explain';
169169
</listitem>
170170
</varlistentry>
171171

172+
<varlistentry>
173+
<term>
174+
<varname>auto_explain.log_settings</varname> (<type>boolean</type>)
175+
<indexterm>
176+
<primary><varname>auto_explain.log_settings</varname> configuration parameter</primary>
177+
</indexterm>
178+
</term>
179+
<listitem>
180+
<para>
181+
<varname>auto_explain.log_settings</varname> controls whether information
182+
about modified configuration options are printed when execution plan is logged.
183+
Only options affecting query planning with value different from the built-in
184+
default value are included in the output. This parameter is off by default.
185+
Only superusers can change this setting.
186+
</para>
187+
</listitem>
188+
</varlistentry>
189+
172190
<varlistentry>
173191
<term>
174192
<varname>auto_explain.log_format</varname> (<type>enum</type>)

‎doc/src/sgml/ref/explain.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ EXPLAIN [ ANALYZE ] [ VERBOSE ] <replaceable class="parameter">statement</replac
3939
ANALYZE [ <replaceable class="parameter">boolean</replaceable> ]
4040
VERBOSE [ <replaceable class="parameter">boolean</replaceable> ]
4141
COSTS [ <replaceable class="parameter">boolean</replaceable> ]
42+
SETTINGS [ <replaceable class="parameter">boolean</replaceable> ]
4243
BUFFERS [ <replaceable class="parameter">boolean</replaceable> ]
4344
TIMING [ <replaceable class="parameter">boolean</replaceable> ]
4445
SUMMARY [ <replaceable class="parameter">boolean</replaceable> ]
@@ -152,6 +153,17 @@ ROLLBACK;
152153
</listitem>
153154
</varlistentry>
154155

156+
<varlistentry>
157+
<term><literal>SETTINGS</literal></term>
158+
<listitem>
159+
<para>
160+
Include information on configuration parameters. Specifically, include
161+
options affecting query planning with value different from the built-in
162+
default value. This parameter defaults to <literal>FALSE</literal>.
163+
</para>
164+
</listitem>
165+
</varlistentry>
166+
155167
<varlistentry>
156168
<term><literal>BUFFERS</literal></term>
157169
<listitem>

‎src/backend/commands/explain.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include"storage/bufmgr.h"
3030
#include"tcop/tcopprot.h"
3131
#include"utils/builtins.h"
32+
#include"utils/guc_tables.h"
3233
#include"utils/json.h"
3334
#include"utils/lsyscache.h"
3435
#include"utils/rel.h"
@@ -162,6 +163,8 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
162163
es->costs=defGetBoolean(opt);
163164
elseif (strcmp(opt->defname,"buffers")==0)
164165
es->buffers=defGetBoolean(opt);
166+
elseif (strcmp(opt->defname,"settings")==0)
167+
es->settings=defGetBoolean(opt);
165168
elseif (strcmp(opt->defname,"timing")==0)
166169
{
167170
timing_set= true;
@@ -596,6 +599,73 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
596599
ExplainCloseGroup("Query",NULL, true,es);
597600
}
598601

602+
/*
603+
* ExplainPrintSettings -
604+
* Print summary of modified settings affecting query planning.
605+
*/
606+
staticvoid
607+
ExplainPrintSettings(ExplainState*es)
608+
{
609+
intnum;
610+
structconfig_generic**gucs;
611+
612+
/* bail out if information about settings not requested */
613+
if (!es->settings)
614+
return;
615+
616+
/* request an array of relevant settings */
617+
gucs=get_explain_guc_options(&num);
618+
619+
/* also bail out of there are no options */
620+
if (!num)
621+
return;
622+
623+
if (es->format!=EXPLAIN_FORMAT_TEXT)
624+
{
625+
inti;
626+
627+
ExplainOpenGroup("Settings","Settings", true,es);
628+
629+
for (i=0;i<num;i++)
630+
{
631+
char*setting;
632+
structconfig_generic*conf=gucs[i];
633+
634+
setting=GetConfigOptionByName(conf->name,NULL, true);
635+
636+
ExplainPropertyText(conf->name,setting,es);
637+
}
638+
639+
ExplainCloseGroup("Settings","Settings", true,es);
640+
}
641+
else
642+
{
643+
inti;
644+
StringInfoDatastr;
645+
646+
initStringInfo(&str);
647+
648+
for (i=0;i<num;i++)
649+
{
650+
char*setting;
651+
structconfig_generic*conf=gucs[i];
652+
653+
if (i>0)
654+
appendStringInfoString(&str,", ");
655+
656+
setting=GetConfigOptionByName(conf->name,NULL, true);
657+
658+
if (setting)
659+
appendStringInfo(&str,"%s = '%s'",conf->name,setting);
660+
else
661+
appendStringInfo(&str,"%s = NULL",conf->name);
662+
}
663+
664+
if (num>0)
665+
ExplainPropertyText("Settings",str.data,es);
666+
}
667+
}
668+
599669
/*
600670
* ExplainPrintPlan -
601671
* convert a QueryDesc's plan tree to text and append it to es->str
@@ -633,6 +703,12 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
633703
if (IsA(ps,GatherState)&&((Gather*)ps->plan)->invisible)
634704
ps=outerPlanState(ps);
635705
ExplainNode(ps,NIL,NULL,NULL,es);
706+
707+
/*
708+
* If requested, include information about GUC parameters with values
709+
* that don't match the built-in defaults.
710+
*/
711+
ExplainPrintSettings(es);
636712
}
637713

638714
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp