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

Commitccdb662

Browse files
committed
Tweak guc.c to allow underscores in the names of custom variable classes,
and change auto_explain's custom GUC variables to be named auto_explain.xxxnot just explain.xxx. Per discussion in connection with thepg_stat_statements patch, it seems like a good idea to have the conventionthat custom variable classes are named the same as their defining module.Committing separately since this should happen regardless of what happenswith pg_stat_statements itself.
1 parent65deb13 commitccdb662

File tree

3 files changed

+42
-44
lines changed

3 files changed

+42
-44
lines changed

‎contrib/auto_explain/auto_explain.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.2 2009/01/01 17:23:31 momjian Exp $
9+
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.3 2009/01/02 01:16:02 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -18,13 +18,11 @@
1818

1919
PG_MODULE_MAGIC;
2020

21-
#defineGUCNAME(name)("explain." name)
22-
2321
/* GUC variables */
24-
staticintexplain_log_min_duration=-1;/* msec or -1 */
25-
staticboolexplain_log_analyze= false;
26-
staticboolexplain_log_verbose= false;
27-
staticboolexplain_log_nested= false;
22+
staticintauto_explain_log_min_duration=-1;/* msec or -1 */
23+
staticboolauto_explain_log_analyze= false;
24+
staticboolauto_explain_log_verbose= false;
25+
staticboolauto_explain_log_nested_statements= false;
2826

2927
/* Current nesting depth of ExecutorRun calls */
3028
staticintnesting_level=0;
@@ -35,8 +33,8 @@ static ExecutorRun_hook_typeprev_ExecutorRun = NULL;
3533
staticExecutorEnd_hook_typeprev_ExecutorEnd=NULL;
3634

3735
#defineauto_explain_enabled() \
38-
(explain_log_min_duration >= 0 && \
39-
(nesting_level == 0 ||explain_log_nested))
36+
(auto_explain_log_min_duration >= 0 && \
37+
(nesting_level == 0 ||auto_explain_log_nested_statements))
4038

4139
void_PG_init(void);
4240
void_PG_fini(void);
@@ -55,41 +53,41 @@ void
5553
_PG_init(void)
5654
{
5755
/* Define custom GUC variables. */
58-
DefineCustomIntVariable(GUCNAME("log_min_duration"),
56+
DefineCustomIntVariable("auto_explain.log_min_duration",
5957
"Sets the minimum execution time above which plans will be logged.",
6058
"Zero prints all plans. -1 turns this feature off.",
61-
&explain_log_min_duration,
59+
&auto_explain_log_min_duration,
6260
-1,
6361
-1,INT_MAX /1000,
6462
PGC_SUSET,
6563
GUC_UNIT_MS,
6664
NULL,
6765
NULL);
6866

69-
DefineCustomBoolVariable(GUCNAME("log_analyze"),
67+
DefineCustomBoolVariable("auto_explain.log_analyze",
7068
"Use EXPLAIN ANALYZE for plan logging.",
7169
NULL,
72-
&explain_log_analyze,
70+
&auto_explain_log_analyze,
7371
false,
7472
PGC_SUSET,
7573
0,
7674
NULL,
7775
NULL);
7876

79-
DefineCustomBoolVariable(GUCNAME("log_verbose"),
77+
DefineCustomBoolVariable("auto_explain.log_verbose",
8078
"Use EXPLAIN VERBOSE for plan logging.",
8179
NULL,
82-
&explain_log_verbose,
80+
&auto_explain_log_verbose,
8381
false,
8482
PGC_SUSET,
8583
0,
8684
NULL,
8785
NULL);
8886

89-
DefineCustomBoolVariable(GUCNAME("log_nested_statements"),
87+
DefineCustomBoolVariable("auto_explain.log_nested_statements",
9088
"Log nested statements.",
9189
NULL,
92-
&explain_log_nested,
90+
&auto_explain_log_nested_statements,
9391
false,
9492
PGC_SUSET,
9593
0,
@@ -126,7 +124,7 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
126124
if (auto_explain_enabled())
127125
{
128126
/* Enable per-node instrumentation iff log_analyze is required. */
129-
if (explain_log_analyze&& (eflags&EXEC_FLAG_EXPLAIN_ONLY)==0)
127+
if (auto_explain_log_analyze&& (eflags&EXEC_FLAG_EXPLAIN_ONLY)==0)
130128
queryDesc->doInstrument= true;
131129
}
132130

@@ -194,14 +192,14 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
194192

195193
/* Log plan if duration is exceeded. */
196194
msec=queryDesc->totaltime->total*1000.0;
197-
if (msec >=explain_log_min_duration)
195+
if (msec >=auto_explain_log_min_duration)
198196
{
199197
StringInfoDatabuf;
200198

201199
initStringInfo(&buf);
202200
ExplainPrintPlan(&buf,queryDesc,
203-
queryDesc->doInstrument&&explain_log_analyze,
204-
explain_log_verbose);
201+
queryDesc->doInstrument&&auto_explain_log_analyze,
202+
auto_explain_log_verbose);
205203

206204
/* Remove last line break */
207205
if (buf.len>0&&buf.data[buf.len-1]=='\n')

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.2 2008/12/07 23:46:39 alvherre Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.3 2009/01/02 01:16:02 tgl Exp $ -->
22

33
<sect1 id="auto-explain">
44
<title>auto_explain</title>
@@ -38,20 +38,20 @@ LOAD 'auto_explain';
3838
There are several configuration parameters that control the behavior of
3939
<filename>auto_explain</filename>. Note that the default behavior is
4040
to do nothing, so you must set at least
41-
<varname>explain.log_min_duration</varname> if you want any results.
41+
<varname>auto_explain.log_min_duration</varname> if you want any results.
4242
</para>
4343

4444
<variablelist>
4545
<varlistentry>
4646
<term>
47-
<varname>explain.log_min_duration</varname> (<type>integer</type>)
47+
<varname>auto_explain.log_min_duration</varname> (<type>integer</type>)
4848
</term>
4949
<indexterm>
50-
<primary><varname>explain.log_min_duration</> configuration parameter</primary>
50+
<primary><varname>auto_explain.log_min_duration</> configuration parameter</primary>
5151
</indexterm>
5252
<listitem>
5353
<para>
54-
<varname>explain.log_min_duration</varname> is the minimum statement
54+
<varname>auto_explain.log_min_duration</varname> is the minimum statement
5555
execution time, in milliseconds, that will cause the statement's plan to
5656
be logged. Setting this to zero logs all plans. Minus-one (the default)
5757
disables logging of plans. For example, if you set it to
@@ -63,14 +63,14 @@ LOAD 'auto_explain';
6363

6464
<varlistentry>
6565
<term>
66-
<varname>explain.log_analyze</varname> (<type>boolean</type>)
66+
<varname>auto_explain.log_analyze</varname> (<type>boolean</type>)
6767
</term>
6868
<indexterm>
69-
<primary><varname>explain.log_analyze</> configuration parameter</primary>
69+
<primary><varname>auto_explain.log_analyze</> configuration parameter</primary>
7070
</indexterm>
7171
<listitem>
7272
<para>
73-
<varname>explain.log_analyze</varname> causes <command>EXPLAIN ANALYZE</>
73+
<varname>auto_explain.log_analyze</varname> causes <command>EXPLAIN ANALYZE</>
7474
output, rather than just <command>EXPLAIN</> output, to be printed
7575
when an execution plan is logged. This parameter is off by default.
7676
Only superusers can change this setting.
@@ -87,14 +87,14 @@ LOAD 'auto_explain';
8787

8888
<varlistentry>
8989
<term>
90-
<varname>explain.log_verbose</varname> (<type>boolean</type>)
90+
<varname>auto_explain.log_verbose</varname> (<type>boolean</type>)
9191
</term>
9292
<indexterm>
93-
<primary><varname>explain.log_verbose</> configuration parameter</primary>
93+
<primary><varname>auto_explain.log_verbose</> configuration parameter</primary>
9494
</indexterm>
9595
<listitem>
9696
<para>
97-
<varname>explain.log_verbose</varname> causes <command>EXPLAIN VERBOSE</>
97+
<varname>auto_explain.log_verbose</varname> causes <command>EXPLAIN VERBOSE</>
9898
output, rather than just <command>EXPLAIN</> output, to be printed
9999
when an execution plan is logged. This parameter is off by default.
100100
Only superusers can change this setting.
@@ -104,14 +104,14 @@ LOAD 'auto_explain';
104104

105105
<varlistentry>
106106
<term>
107-
<varname>explain.log_nested_statements</varname> (<type>boolean</type>)
107+
<varname>auto_explain.log_nested_statements</varname> (<type>boolean</type>)
108108
</term>
109109
<indexterm>
110-
<primary><varname>explain.log_nested_statements</> configuration parameter</primary>
110+
<primary><varname>auto_explain.log_nested_statements</> configuration parameter</primary>
111111
</indexterm>
112112
<listitem>
113113
<para>
114-
<varname>explain.log_nested_statements</varname> causes nested
114+
<varname>auto_explain.log_nested_statements</varname> causes nested
115115
statements (statements executed inside a function) to be considered
116116
for logging. When it is off, only top-level query plans are logged. This
117117
parameter is off by default. Only superusers can change this setting.
@@ -122,16 +122,16 @@ LOAD 'auto_explain';
122122

123123
<para>
124124
In order to set these parameters in your <filename>postgresql.conf</> file,
125-
you will need to add <literal>explain</>in
126-
<varname>custom_variable_classes</>. Typical usage might be:
125+
you will need to add <literal>auto_explain</>to
126+
<xref linkend="guc-custom-variable-classes">. Typical usage might be:
127127
</para>
128128

129129
<programlisting>
130130
# postgresql.conf
131131
shared_preload_libraries = 'auto_explain'
132132

133-
custom_variable_classes = 'explain'
134-
explain.log_min_duration = '3s'
133+
custom_variable_classes = 'auto_explain'
134+
auto_explain.log_min_duration = '3s'
135135
</programlisting>
136136
</sect2>
137137

@@ -140,7 +140,7 @@ explain.log_min_duration = '3s'
140140

141141
<programlisting>
142142
postgres=# LOAD 'auto_explain';
143-
postgres=# SETexplain.log_min_duration = 0;
143+
postgres=# SETauto_explain.log_min_duration = 0;
144144
postgres=# SELECT count(*)
145145
FROM pg_class, pg_index
146146
WHERE oid = indrelid AND indisunique;

‎src/backend/utils/misc/guc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.484 2009/01/01 17:23:53 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.485 2009/01/02 01:16:02 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -7283,11 +7283,11 @@ assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
72837283
continue;
72847284
}
72857285

7286-
if (hasSpaceAfterToken|| !isalnum((unsignedchar)c))
7286+
if (hasSpaceAfterToken|| !(isalnum((unsignedchar)c)||c=='_'))
72877287
{
72887288
/*
7289-
* Syntax error due to token following space after token or non
7290-
*alpha numeric character
7289+
* Syntax error due to token following space after token or
7290+
*non-identifier character
72917291
*/
72927292
pfree(buf.data);
72937293
returnNULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp