This is my first attempt at writing a patch, so it's pretty simple.

Commit log sums it up:

Adds a convenience feature to the explain command which prints out GUC cost
parameters in explain text output.

    For example:

    explain (params) select * from table;

    will include text output like the following:

    Cost Params:
             seq_page: 1.000000, rnd_page: 4.000000, cpu_tup: 0.010000,
cpu_ind: 0.005000, cpu_op: 0.002500
             amenabled: 11111111111

    The bit vector is enable variables in the order listed in cost.h,
though mainly provides a high level view on whether or not any strategies
are disabled.

------

I recognize that this is kind of a frivolous feature which may not be worth
any potential maintenance burden, so submitted for what it's worth as an
initial effort.

Best Regards,
Robert
From 960dc64864306b554a2e150cb8e28e7a63f218d1 Mon Sep 17 00:00:00 2001
From: robert berry <berrydigi...@gmail.com>
Date: Wed, 13 Nov 2013 15:29:23 -0800
Subject: [PATCH 1/1] Adds a convenience feature to the explain command which
 prints out GUC cost parameters in explain text output.

For example:

will include text output like the following:

Cost Params:
         seq_page: 1.000000, rnd_page: 4.000000, cpu_tup: 0.010000, cpu_ind: 0.005000, cpu_op: 0.002500
         amenabled: 11111111111

The bit vector is enable variables in the order listed in cost.h, though mainly provides a high level
view on whether or not any strategies are disabled.
---
 src/backend/commands/explain.c | 18 ++++++++++++++++++
 src/include/commands/explain.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 4e93df2..8feeca8 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -31,6 +31,7 @@
 #include "utils/snapmgr.h"
 #include "utils/tuplesort.h"
 #include "utils/xml.h"
+#include "optimizer/cost.h"
 
 
 /* Hook for plugins to get control in ExplainOneQuery() */
@@ -140,6 +141,8 @@ ExplainQuery(ExplainStmt *stmt, const char *queryString,
 			es.costs = defGetBoolean(opt);
 		else if (strcmp(opt->defname, "buffers") == 0)
 			es.buffers = defGetBoolean(opt);
+		else if (strcmp(opt->defname, "params") == 0)
+			es.params = defGetBoolean(opt);
 		else if (strcmp(opt->defname, "timing") == 0)
 		{
 			timing_set = true;
@@ -516,6 +519,21 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
 
 	PopActiveSnapshot();
 
+	/* include one line display of cost parameters */
+	if (es->params) 
+	{
+		if (es->format == EXPLAIN_FORMAT_TEXT)
+		{
+		  appendStringInfo(es->str, "\nCost Params:\n");
+			appendStringInfo(es->str, "\tseq_page: %f, rnd_page: %f, cpu_tup: %f, cpu_ind: %f, cpu_op: %f",
+		    seq_page_cost, random_page_cost, cpu_tuple_cost, cpu_index_tuple_cost, cpu_operator_cost, enable_seqscan);
+		  appendStringInfo(es->str, "\n\tamenabled: %d%d%d%d%d%d%d%d%d%d%d\n\n",
+		    enable_seqscan, enable_indexscan, enable_indexonlyscan, enable_bitmapscan, 
+		    enable_tidscan, enable_sort, enable_hashagg, enable_nestloop, enable_material,
+		    enable_mergejoin, enable_hashjoin);  
+		}
+	}
+
 	/* We need a CCI just in case query expanded to multiple plans */
 	if (es->analyze)
 		CommandCounterIncrement();
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
index ca213d7..d76476c 100644
--- a/src/include/commands/explain.h
+++ b/src/include/commands/explain.h
@@ -33,6 +33,7 @@ typedef struct ExplainState
 	bool		costs;			/* print costs */
 	bool		buffers;		/* print buffer usage */
 	bool		timing;			/* print timing */
+	bool		params;			/* print optimizer cost params */
 	ExplainFormat format;		/* output format */
 	/* other states */
 	PlannedStmt *pstmt;			/* top of plan */
-- 
1.8.3.2

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to