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.xxx not just explain.xxx. Per discussion in connection with the pg_stat_statements patch, it seems like a good idea to have the convention that custom variable classes are named the same as their defining module. Committing separately since this should happen regardless of what happens with pg_stat_statements itself.
This commit is contained in:
parent
65deb13436
commit
ccdb6627ee
|
@ -6,7 +6,7 @@
|
||||||
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
|
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.2 2009/01/01 17:23:31 momjian Exp $
|
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.3 2009/01/02 01:16:02 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -18,13 +18,11 @@
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
#define GUCNAME(name) ("explain." name)
|
|
||||||
|
|
||||||
/* GUC variables */
|
/* GUC variables */
|
||||||
static int explain_log_min_duration = -1; /* msec or -1 */
|
static int auto_explain_log_min_duration = -1; /* msec or -1 */
|
||||||
static bool explain_log_analyze = false;
|
static bool auto_explain_log_analyze = false;
|
||||||
static bool explain_log_verbose = false;
|
static bool auto_explain_log_verbose = false;
|
||||||
static bool explain_log_nested = false;
|
static bool auto_explain_log_nested_statements = false;
|
||||||
|
|
||||||
/* Current nesting depth of ExecutorRun calls */
|
/* Current nesting depth of ExecutorRun calls */
|
||||||
static int nesting_level = 0;
|
static int nesting_level = 0;
|
||||||
|
@ -35,8 +33,8 @@ static ExecutorRun_hook_type prev_ExecutorRun = NULL;
|
||||||
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
|
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
|
||||||
|
|
||||||
#define auto_explain_enabled() \
|
#define auto_explain_enabled() \
|
||||||
(explain_log_min_duration >= 0 && \
|
(auto_explain_log_min_duration >= 0 && \
|
||||||
(nesting_level == 0 || explain_log_nested))
|
(nesting_level == 0 || auto_explain_log_nested_statements))
|
||||||
|
|
||||||
void _PG_init(void);
|
void _PG_init(void);
|
||||||
void _PG_fini(void);
|
void _PG_fini(void);
|
||||||
|
@ -55,10 +53,10 @@ void
|
||||||
_PG_init(void)
|
_PG_init(void)
|
||||||
{
|
{
|
||||||
/* Define custom GUC variables. */
|
/* Define custom GUC variables. */
|
||||||
DefineCustomIntVariable(GUCNAME("log_min_duration"),
|
DefineCustomIntVariable("auto_explain.log_min_duration",
|
||||||
"Sets the minimum execution time above which plans will be logged.",
|
"Sets the minimum execution time above which plans will be logged.",
|
||||||
"Zero prints all plans. -1 turns this feature off.",
|
"Zero prints all plans. -1 turns this feature off.",
|
||||||
&explain_log_min_duration,
|
&auto_explain_log_min_duration,
|
||||||
-1,
|
-1,
|
||||||
-1, INT_MAX / 1000,
|
-1, INT_MAX / 1000,
|
||||||
PGC_SUSET,
|
PGC_SUSET,
|
||||||
|
@ -66,30 +64,30 @@ _PG_init(void)
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
DefineCustomBoolVariable(GUCNAME("log_analyze"),
|
DefineCustomBoolVariable("auto_explain.log_analyze",
|
||||||
"Use EXPLAIN ANALYZE for plan logging.",
|
"Use EXPLAIN ANALYZE for plan logging.",
|
||||||
NULL,
|
NULL,
|
||||||
&explain_log_analyze,
|
&auto_explain_log_analyze,
|
||||||
false,
|
false,
|
||||||
PGC_SUSET,
|
PGC_SUSET,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
DefineCustomBoolVariable(GUCNAME("log_verbose"),
|
DefineCustomBoolVariable("auto_explain.log_verbose",
|
||||||
"Use EXPLAIN VERBOSE for plan logging.",
|
"Use EXPLAIN VERBOSE for plan logging.",
|
||||||
NULL,
|
NULL,
|
||||||
&explain_log_verbose,
|
&auto_explain_log_verbose,
|
||||||
false,
|
false,
|
||||||
PGC_SUSET,
|
PGC_SUSET,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
DefineCustomBoolVariable(GUCNAME("log_nested_statements"),
|
DefineCustomBoolVariable("auto_explain.log_nested_statements",
|
||||||
"Log nested statements.",
|
"Log nested statements.",
|
||||||
NULL,
|
NULL,
|
||||||
&explain_log_nested,
|
&auto_explain_log_nested_statements,
|
||||||
false,
|
false,
|
||||||
PGC_SUSET,
|
PGC_SUSET,
|
||||||
0,
|
0,
|
||||||
|
@ -126,7 +124,7 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
|
||||||
if (auto_explain_enabled())
|
if (auto_explain_enabled())
|
||||||
{
|
{
|
||||||
/* Enable per-node instrumentation iff log_analyze is required. */
|
/* Enable per-node instrumentation iff log_analyze is required. */
|
||||||
if (explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0)
|
if (auto_explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0)
|
||||||
queryDesc->doInstrument = true;
|
queryDesc->doInstrument = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +192,14 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
|
||||||
|
|
||||||
/* Log plan if duration is exceeded. */
|
/* Log plan if duration is exceeded. */
|
||||||
msec = queryDesc->totaltime->total * 1000.0;
|
msec = queryDesc->totaltime->total * 1000.0;
|
||||||
if (msec >= explain_log_min_duration)
|
if (msec >= auto_explain_log_min_duration)
|
||||||
{
|
{
|
||||||
StringInfoData buf;
|
StringInfoData buf;
|
||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
ExplainPrintPlan(&buf, queryDesc,
|
ExplainPrintPlan(&buf, queryDesc,
|
||||||
queryDesc->doInstrument && explain_log_analyze,
|
queryDesc->doInstrument && auto_explain_log_analyze,
|
||||||
explain_log_verbose);
|
auto_explain_log_verbose);
|
||||||
|
|
||||||
/* Remove last line break */
|
/* Remove last line break */
|
||||||
if (buf.len > 0 && buf.data[buf.len - 1] == '\n')
|
if (buf.len > 0 && buf.data[buf.len - 1] == '\n')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.2 2008/12/07 23:46:39 alvherre Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.3 2009/01/02 01:16:02 tgl Exp $ -->
|
||||||
|
|
||||||
<sect1 id="auto-explain">
|
<sect1 id="auto-explain">
|
||||||
<title>auto_explain</title>
|
<title>auto_explain</title>
|
||||||
|
@ -38,20 +38,20 @@ LOAD 'auto_explain';
|
||||||
There are several configuration parameters that control the behavior of
|
There are several configuration parameters that control the behavior of
|
||||||
<filename>auto_explain</filename>. Note that the default behavior is
|
<filename>auto_explain</filename>. Note that the default behavior is
|
||||||
to do nothing, so you must set at least
|
to do nothing, so you must set at least
|
||||||
<varname>explain.log_min_duration</varname> if you want any results.
|
<varname>auto_explain.log_min_duration</varname> if you want any results.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<varname>explain.log_min_duration</varname> (<type>integer</type>)
|
<varname>auto_explain.log_min_duration</varname> (<type>integer</type>)
|
||||||
</term>
|
</term>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary><varname>explain.log_min_duration</> configuration parameter</primary>
|
<primary><varname>auto_explain.log_min_duration</> configuration parameter</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<varname>explain.log_min_duration</varname> is the minimum statement
|
<varname>auto_explain.log_min_duration</varname> is the minimum statement
|
||||||
execution time, in milliseconds, that will cause the statement's plan to
|
execution time, in milliseconds, that will cause the statement's plan to
|
||||||
be logged. Setting this to zero logs all plans. Minus-one (the default)
|
be logged. Setting this to zero logs all plans. Minus-one (the default)
|
||||||
disables logging of plans. For example, if you set it to
|
disables logging of plans. For example, if you set it to
|
||||||
|
@ -63,14 +63,14 @@ LOAD 'auto_explain';
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<varname>explain.log_analyze</varname> (<type>boolean</type>)
|
<varname>auto_explain.log_analyze</varname> (<type>boolean</type>)
|
||||||
</term>
|
</term>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary><varname>explain.log_analyze</> configuration parameter</primary>
|
<primary><varname>auto_explain.log_analyze</> configuration parameter</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<varname>explain.log_analyze</varname> causes <command>EXPLAIN ANALYZE</>
|
<varname>auto_explain.log_analyze</varname> causes <command>EXPLAIN ANALYZE</>
|
||||||
output, rather than just <command>EXPLAIN</> output, to be printed
|
output, rather than just <command>EXPLAIN</> output, to be printed
|
||||||
when an execution plan is logged. This parameter is off by default.
|
when an execution plan is logged. This parameter is off by default.
|
||||||
Only superusers can change this setting.
|
Only superusers can change this setting.
|
||||||
|
@ -87,14 +87,14 @@ LOAD 'auto_explain';
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<varname>explain.log_verbose</varname> (<type>boolean</type>)
|
<varname>auto_explain.log_verbose</varname> (<type>boolean</type>)
|
||||||
</term>
|
</term>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary><varname>explain.log_verbose</> configuration parameter</primary>
|
<primary><varname>auto_explain.log_verbose</> configuration parameter</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<varname>explain.log_verbose</varname> causes <command>EXPLAIN VERBOSE</>
|
<varname>auto_explain.log_verbose</varname> causes <command>EXPLAIN VERBOSE</>
|
||||||
output, rather than just <command>EXPLAIN</> output, to be printed
|
output, rather than just <command>EXPLAIN</> output, to be printed
|
||||||
when an execution plan is logged. This parameter is off by default.
|
when an execution plan is logged. This parameter is off by default.
|
||||||
Only superusers can change this setting.
|
Only superusers can change this setting.
|
||||||
|
@ -104,14 +104,14 @@ LOAD 'auto_explain';
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<varname>explain.log_nested_statements</varname> (<type>boolean</type>)
|
<varname>auto_explain.log_nested_statements</varname> (<type>boolean</type>)
|
||||||
</term>
|
</term>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary><varname>explain.log_nested_statements</> configuration parameter</primary>
|
<primary><varname>auto_explain.log_nested_statements</> configuration parameter</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<varname>explain.log_nested_statements</varname> causes nested
|
<varname>auto_explain.log_nested_statements</varname> causes nested
|
||||||
statements (statements executed inside a function) to be considered
|
statements (statements executed inside a function) to be considered
|
||||||
for logging. When it is off, only top-level query plans are logged. This
|
for logging. When it is off, only top-level query plans are logged. This
|
||||||
parameter is off by default. Only superusers can change this setting.
|
parameter is off by default. Only superusers can change this setting.
|
||||||
|
@ -122,16 +122,16 @@ LOAD 'auto_explain';
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
In order to set these parameters in your <filename>postgresql.conf</> file,
|
In order to set these parameters in your <filename>postgresql.conf</> file,
|
||||||
you will need to add <literal>explain</> in
|
you will need to add <literal>auto_explain</> to
|
||||||
<varname>custom_variable_classes</>. Typical usage might be:
|
<xref linkend="guc-custom-variable-classes">. Typical usage might be:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
# postgresql.conf
|
# postgresql.conf
|
||||||
shared_preload_libraries = 'auto_explain'
|
shared_preload_libraries = 'auto_explain'
|
||||||
|
|
||||||
custom_variable_classes = 'explain'
|
custom_variable_classes = 'auto_explain'
|
||||||
explain.log_min_duration = '3s'
|
auto_explain.log_min_duration = '3s'
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ explain.log_min_duration = '3s'
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
postgres=# LOAD 'auto_explain';
|
postgres=# LOAD 'auto_explain';
|
||||||
postgres=# SET explain.log_min_duration = 0;
|
postgres=# SET auto_explain.log_min_duration = 0;
|
||||||
postgres=# SELECT count(*)
|
postgres=# SELECT count(*)
|
||||||
FROM pg_class, pg_index
|
FROM pg_class, pg_index
|
||||||
WHERE oid = indrelid AND indisunique;
|
WHERE oid = indrelid AND indisunique;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.484 2009/01/01 17:23:53 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.485 2009/01/02 01:16:02 tgl Exp $
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------
|
*--------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -7283,11 +7283,11 @@ assign_custom_variable_classes(const char *newval, bool doit, GucSource source)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSpaceAfterToken || !isalnum((unsigned char) c))
|
if (hasSpaceAfterToken || !(isalnum((unsigned char) c) || c == '_'))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Syntax error due to token following space after token or non
|
* Syntax error due to token following space after token or
|
||||||
* alpha numeric character
|
* non-identifier character
|
||||||
*/
|
*/
|
||||||
pfree(buf.data);
|
pfree(buf.data);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue