]> granicus.if.org Git - postgresql/commitdiff
Expose a routine to print triggers during EXPLAIN ANALYZE
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 20 Jan 2014 20:12:50 +0000 (17:12 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 20 Jan 2014 20:13:47 +0000 (17:13 -0300)
This is so that auto_explain can use it.

Kyotaro HORIGUCHI

src/backend/commands/explain.c
src/include/commands/explain.h

index e604be31f9d741dc39835bd7c1526419d8034220..0dba9283f1ce2689439b49feec5d722590243908 100644 (file)
@@ -486,29 +486,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
 
        /* Print info about runtime of triggers */
        if (es->analyze)
-       {
-               ResultRelInfo *rInfo;
-               bool            show_relname;
-               int                     numrels = queryDesc->estate->es_num_result_relations;
-               List       *targrels = queryDesc->estate->es_trig_target_relations;
-               int                     nr;
-               ListCell   *l;
-
-               ExplainOpenGroup("Triggers", "Triggers", false, es);
-
-               show_relname = (numrels > 1 || targrels != NIL);
-               rInfo = queryDesc->estate->es_result_relations;
-               for (nr = 0; nr < numrels; rInfo++, nr++)
-                       report_triggers(rInfo, show_relname, es);
-
-               foreach(l, targrels)
-               {
-                       rInfo = (ResultRelInfo *) lfirst(l);
-                       report_triggers(rInfo, show_relname, es);
-               }
-
-               ExplainCloseGroup("Triggers", "Triggers", false, es);
-       }
+               ExplainPrintTriggers(es, queryDesc);
 
        /*
         * Close down the query and free resources.  Include time for this in the
@@ -564,6 +542,42 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
        ExplainNode(queryDesc->planstate, NIL, NULL, NULL, es);
 }
 
+/*
+ * ExplainPrintTriggers -
+
+ *       convert a QueryDesc's trigger statistics to text and append it to
+ *       es->str
+ *
+ * The caller should have set up the options fields of *es, as well as
+ * initializing the output buffer es->str.     Other fields in *es are
+ * initialized here.
+ */
+void
+ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
+{
+       ResultRelInfo *rInfo;
+       bool            show_relname;
+       int                     numrels = queryDesc->estate->es_num_result_relations;
+       List       *targrels = queryDesc->estate->es_trig_target_relations;
+       int                     nr;
+       ListCell   *l;
+
+       ExplainOpenGroup("Triggers", "Triggers", false, es);
+
+       show_relname = (numrels > 1 || targrels != NIL);
+       rInfo = queryDesc->estate->es_result_relations;
+       for (nr = 0; nr < numrels; rInfo++, nr++)
+               report_triggers(rInfo, show_relname, es);
+
+       foreach(l, targrels)
+       {
+               rInfo = (ResultRelInfo *) lfirst(l);
+               report_triggers(rInfo, show_relname, es);
+       }
+
+       ExplainCloseGroup("Triggers", "Triggers", false, es);
+}
+
 /*
  * ExplainQueryText -
  *       add a "Query Text" node that contains the actual text of the query
index 9e71206b505c1b801b12aca458277235be65bfdd..e097710ddddae958bc5f040e968cfeced7c5d2b2 100644 (file)
@@ -71,6 +71,7 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
                           const char *queryString, ParamListInfo params);
 
 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
+extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
 
 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);