This patch implements
        explain_analyze_timer = off

which prevents time instrumentation being taken during an 
EXPLAIN ANALYZE. The output of EA is unaffected, so that all the times
come out as zero - this is done to ensure any programs that are parsing
this output can still recognise it.

I'm not claiming there has been agreement towards this approach, so an
approach may yet be found which is acceptable to all. In the meantime...

-- 
  Simon Riggs             
  EnterpriseDB   http://www.enterprisedb.com

Index: src/backend/executor/instrument.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/executor/instrument.c,v
retrieving revision 1.18
diff -c -r1.18 instrument.c
*** src/backend/executor/instrument.c	9 Jun 2006 19:30:56 -0000	1.18
--- src/backend/executor/instrument.c	19 Dec 2006 08:31:38 -0000
***************
*** 17,22 ****
--- 17,23 ----
  
  #include "executor/instrument.h"
  
+ bool    explain_analyzetimer = true;
  
  /* Allocate new instrumentation structure(s) */
  Instrumentation *
***************
*** 33,38 ****
--- 34,42 ----
  void
  InstrStartNode(Instrumentation *instr)
  {
+     if (!explain_analyzetimer)
+         return;
+ 
  	if (INSTR_TIME_IS_ZERO(instr->starttime))
  		INSTR_TIME_SET_CURRENT(instr->starttime);
  	else
***************
*** 48,53 ****
--- 52,64 ----
  	/* count the returned tuples */
  	instr->tuplecount += nTuples;
  
+     if (!explain_analyzetimer)
+     {
+     	if (!instr->running)
+     		instr->running = true;
+         return;
+     }
+ 
  	if (INSTR_TIME_IS_ZERO(instr->starttime))
  	{
  		elog(DEBUG2, "InstrStopNode called without start");
***************
*** 95,100 ****
--- 106,121 ----
  	if (!instr->running)
  		return;
  
+ 	instr->ntuples += instr->tuplecount;
+ 	instr->nloops += 1;
+ 
+ 	/* Reset for next cycle (if any) */
+ 	instr->tuplecount = 0;
+ 	instr->running = false;
+ 
+     if (!explain_analyzetimer)
+         return;
+ 
  	if (!INSTR_TIME_IS_ZERO(instr->starttime))
  		elog(DEBUG2, "InstrEndLoop called on running node");
  
***************
*** 103,115 ****
  
  	instr->startup += instr->firsttuple;
  	instr->total += totaltime;
- 	instr->ntuples += instr->tuplecount;
- 	instr->nloops += 1;
  
- 	/* Reset for next cycle (if any) */
- 	instr->running = false;
  	INSTR_TIME_SET_ZERO(instr->starttime);
  	INSTR_TIME_SET_ZERO(instr->counter);
  	instr->firsttuple = 0;
- 	instr->tuplecount = 0;
  }
--- 124,131 ----
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.361
diff -c -r1.361 guc.c
*** src/backend/utils/misc/guc.c	6 Dec 2006 17:35:49 -0000	1.361
--- src/backend/utils/misc/guc.c	19 Dec 2006 08:31:46 -0000
***************
*** 33,38 ****
--- 33,39 ----
  #include "commands/async.h"
  #include "commands/vacuum.h"
  #include "commands/variable.h"
+ #include "executor/instrument.h"
  #include "funcapi.h"
  #include "libpq/auth.h"
  #include "libpq/pqformat.h"
***************
*** 474,479 ****
--- 475,488 ----
  		true, NULL, NULL
  	},
  	{
+ 		{"explain_analyze_timer", PGC_USERSET, QUERY_TUNING_OTHER,
+ 			gettext_noop("Enables the planner's use of timers in an EXPLAIN ANALYZE."),
+ 			NULL
+ 		},
+ 		&explain_analyzetimer,
+ 		true, NULL, NULL
+ 	},
+ 	{
  		{"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
  			gettext_noop("Enables the planner to use constraints to optimize queries."),
  			gettext_noop("Child table scans will be skipped if their "
Index: src/include/executor/instrument.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/executor/instrument.h,v
retrieving revision 1.16
diff -c -r1.16 instrument.h
*** src/include/executor/instrument.h	9 Jun 2006 19:30:56 -0000	1.16
--- src/include/executor/instrument.h	19 Dec 2006 08:31:47 -0000
***************
*** 73,76 ****
--- 73,78 ----
  extern void InstrStopNode(Instrumentation *instr, double nTuples);
  extern void InstrEndLoop(Instrumentation *instr);
  
+ extern bool explain_analyzetimer;
+ 
  #endif   /* INSTRUMENT_H */
---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

                http://www.postgresql.org/about/donate

Reply via email to