Re: auto_explain contrib moudle

Поиск
Список
Период
Сортировка
От Martin Pihlak
Тема Re: auto_explain contrib moudle
Дата
Msg-id 491466DC.5050400@gmail.com
обсуждение исходный текст
Ответ на Re: auto_explain contrib moudle  (Jeff Davis <pgsql@j-davis.com>)
Ответы Re: auto_explain contrib moudle  (Jeff Davis <pgsql@j-davis.com>)
Re: auto_explain contrib moudle  (Jeff Davis <pgsql@j-davis.com>)
Список pgsql-hackers
Jeff Davis wrote:
> It still needs to be merged with HEAD.
>
ExecutorRun function signature has changed to return void. Other than that
it seems OK. I'll add a few additional notes:

One thing that I noticed was that tab completion queries are also explained
if "explain.log_min_duration" is set to zero. Actually this also applies to
psql \dX commands. Don't know if this is deliberate or not. Example:

load 'auto_explain';
set explain.log_min_duration = 0;
set client_min_messages = LOG;
select * from pg_catalog.^ILOG:  duration: 4.713 ms  plan:
Limit  (cost=27.41..27.44 rows=3 width=85) (actual time=4.023..4.418 rows=75 loops=1)
...

I have a feeling that this can become somewhat annoying during an interactive
troubleshooting session.

Another thing is a feature I am interested in -- ability to auto-explain statements
execututed from within functions. I'm thinking of adding an extra boolean GUC --
"explain.log_nested_statements" (defaults to false). Quick test seems to give
expected results, but there maybe something I missed.

regards,
Martin

*** a/contrib/auto_explain/auto_explain.c
--- b/contrib/auto_explain/auto_explain.c
***************
*** 15,20 **** PG_MODULE_MAGIC;
--- 15,21 ----
  static int        explain_log_min_duration = -1;    /* msec or -1 */
  static bool        explain_log_analyze = false;
  static bool        explain_log_verbose = false;
+ static bool        explain_log_nested = false;

  static bool        toplevel = true;
  static ExecutorRun_hook_type    prev_ExecutorRun = NULL;
***************
*** 28,33 **** static void explain_ExecutorRun(QueryDesc *queryDesc,
--- 29,35 ----
  static bool assign_log_min_duration(int newval, bool doit, GucSource source);
  static bool assign_log_analyze(bool newval, bool doit, GucSource source);
  static bool assign_log_verbose(bool newval, bool doit, GucSource source);
+ static bool assign_log_nested(bool newval, bool doit, GucSource source);

  static struct config_int def_log_min_duration =
  {
***************
*** 67,78 **** static struct config_bool def_log_verbose =
--- 69,93 ----
      false, assign_log_verbose, NULL
  };

+ static struct config_bool def_log_nested_statements =
+ {
+     {
+         GUCNAME("log_nested_statements"),
+         PGC_USERSET,
+         STATS_MONITORING,
+         "Log nested statements."
+     },
+     &explain_log_nested,
+     false, assign_log_nested, NULL
+ };
+
  void
  _PG_init(void)
  {
      DefineCustomVariable(PGC_INT, &def_log_min_duration);
      DefineCustomVariable(PGC_BOOL, &def_log_analyze);
      DefineCustomVariable(PGC_BOOL, &def_log_verbose);
+     DefineCustomVariable(PGC_BOOL, &def_log_nested_statements);

      /* install ExecutorRun_hook */
      prev_ExecutorRun = ExecutorRun_hook;
***************
*** 89,95 **** _PG_fini(void)
  void
  explain_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count)
  {
!     if (toplevel && explain_log_min_duration >= 0)
      {
          instr_time        starttime;
          instr_time        duration;
--- 104,110 ----
  void
  explain_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count)
  {
!     if ((toplevel || explain_log_nested) && explain_log_min_duration >= 0)
      {
          instr_time        starttime;
          instr_time        duration;
***************
*** 188,190 **** assign_log_verbose(bool newval, bool doit, GucSource source)
--- 203,211 ----
  {
      return suset_assign(source, GUCNAME("log_verbose"));
  }
+
+ static bool
+ assign_log_nested(bool newval, bool doit, GucSource source)
+ {
+     return suset_assign(source, GUCNAME("log_nested_statements"));
+ }

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: ALTER DATABASE SET TABLESPACE vs crash safety
Следующее
От: Tom Lane
Дата:
Сообщение: Re: ALTER DATABASE SET TABLESPACE vs crash safety