~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to contrib/auto_explain/auto_explain.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Copyright (c) 2008-2009, PostgreSQL Global Development Group
7
7
 *
8
8
 * IDENTIFICATION
9
 
 *        $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.4 2009/01/05 13:35:38 tgl Exp $
 
9
 *        $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.5 2009/06/11 14:48:50 momjian Exp $
10
10
 *
11
11
 *-------------------------------------------------------------------------
12
12
 */
19
19
PG_MODULE_MAGIC;
20
20
 
21
21
/* GUC variables */
22
 
static int      auto_explain_log_min_duration = -1;             /* msec or -1 */
 
22
static int      auto_explain_log_min_duration = -1; /* msec or -1 */
23
23
static bool auto_explain_log_analyze = false;
24
24
static bool auto_explain_log_verbose = false;
25
25
static bool auto_explain_log_nested_statements = false;
28
28
static int      nesting_level = 0;
29
29
 
30
30
/* Saved hook values in case of unload */
31
 
static ExecutorStart_hook_type  prev_ExecutorStart = NULL;
32
 
static ExecutorRun_hook_type    prev_ExecutorRun = NULL;
33
 
static ExecutorEnd_hook_type    prev_ExecutorEnd = NULL;
 
31
static ExecutorStart_hook_type prev_ExecutorStart = NULL;
 
32
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
 
33
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
34
34
 
35
35
#define auto_explain_enabled() \
36
36
        (auto_explain_log_min_duration >= 0 && \
37
37
         (nesting_level == 0 || auto_explain_log_nested_statements))
38
38
 
39
 
void    _PG_init(void);
40
 
void    _PG_fini(void);
 
39
void            _PG_init(void);
 
40
void            _PG_fini(void);
41
41
 
42
42
static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags);
43
43
static void explain_ExecutorRun(QueryDesc *queryDesc,
44
 
                                                                ScanDirection direction,
45
 
                                                                long count);
 
44
                                        ScanDirection direction,
 
45
                                        long count);
46
46
static void explain_ExecutorEnd(QueryDesc *queryDesc);
47
47
 
48
48
 
54
54
{
55
55
        /* Define custom GUC variables. */
56
56
        DefineCustomIntVariable("auto_explain.log_min_duration",
57
 
                                                        "Sets the minimum execution time above which plans will be logged.",
58
 
                                                        "Zero prints all plans. -1 turns this feature off.",
 
57
                 "Sets the minimum execution time above which plans will be logged.",
 
58
                                                 "Zero prints all plans. -1 turns this feature off.",
59
59
                                                        &auto_explain_log_min_duration,
60
60
                                                        -1,
61
61
                                                        -1, INT_MAX / 1000,
138
138
        if (auto_explain_enabled())
139
139
        {
140
140
                /*
141
 
                 * Set up to track total elapsed time in ExecutorRun.  Make sure
142
 
                 * the space is allocated in the per-query context so it will go
143
 
                 * away at ExecutorEnd.
 
141
                 * Set up to track total elapsed time in ExecutorRun.  Make sure the
 
142
                 * space is allocated in the per-query context so it will go away at
 
143
                 * ExecutorEnd.
144
144
                 */
145
145
                if (queryDesc->totaltime == NULL)
146
146
                {
184
184
{
185
185
        if (queryDesc->totaltime && auto_explain_enabled())
186
186
        {
187
 
                double  msec;
 
187
                double          msec;
188
188
 
189
189
                /*
190
 
                 * Make sure stats accumulation is done.  (Note: it's okay if
191
 
                 * several levels of hook all do this.)
 
190
                 * Make sure stats accumulation is done.  (Note: it's okay if several
 
191
                 * levels of hook all do this.)
192
192
                 */
193
193
                InstrEndLoop(queryDesc->totaltime);
194
194
 
196
196
                msec = queryDesc->totaltime->total * 1000.0;
197
197
                if (msec >= auto_explain_log_min_duration)
198
198
                {
199
 
                        StringInfoData  buf;
 
199
                        StringInfoData buf;
200
200
 
201
201
                        initStringInfo(&buf);
202
202
                        ExplainPrintPlan(&buf, queryDesc,
203
 
                                                         queryDesc->doInstrument && auto_explain_log_analyze,
 
203
                                                 queryDesc->doInstrument && auto_explain_log_analyze,
204
204
                                                         auto_explain_log_verbose);
205
205
 
206
206
                        /* Remove last line break */