Hi,
This patch handles two new parameters for EXPLAIN: COSTS and BUFFERS.
I'm not sure that we need to add support for format. I would like to
have your opinion on this?
--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com
diff --git a/pgadmin/ctl/explainShape.cpp b/pgadmin/ctl/explainShape.cpp
index 01bd216..f58197e 100644
--- a/pgadmin/ctl/explainShape.cpp
+++ b/pgadmin/ctl/explainShape.cpp
@@ -163,6 +163,7 @@ ExplainShape *ExplainShape::Create(long level, ExplainShape *last, const wxStrin
ExplainShape *s=0;
int costPos=str.Find(wxT("(cost="));
+ int actPos = str.Find(wxT("(actual"));
wxStringTokenizer tokens(str, wxT(" "));
wxString token = tokens.GetNextToken();
@@ -171,7 +172,13 @@ ExplainShape *ExplainShape::Create(long level, ExplainShape *last, const wxStrin
wxString token4;
if (tokens.HasMoreTokens())
token4 = tokens.GetNextToken();
- wxString descr = costPos > 0 ? str.Left(costPos) : str;
+ wxString descr;
+ if (costPos > 0)
+ descr = str.Left(costPos);
+ else if (actPos > 0)
+ descr = str.Left(actPos);
+ else
+ descr = str;
// possible keywords can be found in postgresql/src/backend/commands/explain.c
@@ -344,7 +351,6 @@ ExplainShape *ExplainShape::Create(long level, ExplainShape *last, const wxStrin
if (costPos > 0)
{
- int actPos = str.Find(wxT("(actual"));
if (actPos > 0)
{
s->actual = str.Mid(actPos);
@@ -353,6 +359,8 @@ ExplainShape *ExplainShape::Create(long level, ExplainShape *last, const wxStrin
else
s->cost = str.Mid(costPos);
}
+ else if (actPos > 0)
+ s->actual = str.Mid(actPos);
int w=50, h=20;
diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp
index b11324a..86b2320 100644
--- a/pgadmin/frm/frmQuery.cpp
+++ b/pgadmin/frm/frmQuery.cpp
@@ -279,6 +279,8 @@ pgsTimer(new pgScriptTimer(this))
wxMenu *eo=new wxMenu();
eo->Append(MNU_VERBOSE, _("Verbose"), _("Explain verbose query"), wxITEM_CHECK);
eo->Append(MNU_ANALYZE, _("Analyze"), _("Explain analyze query"), wxITEM_CHECK);
+ eo->Append(MNU_COSTS, _("Costs"), _("Explain analyze query with (or without costs)"), wxITEM_CHECK);
+ eo->Append(MNU_BUFFERS, _("Buffers"), _("Explain analyze query with (or without buffers)"), wxITEM_CHECK);
queryMenu->Append(MNU_EXPLAINOPTIONS, _("Explain &options"), eo, _("Options modifying Explain output"));
queryMenu->AppendSeparator();
queryMenu->Append(MNU_SAVEHISTORY, _("Save history"), _("Save history of executed commands."));
@@ -330,6 +332,8 @@ pgsTimer(new pgScriptTimer(this))
queryMenu->Check(MNU_VERBOSE, settings->GetExplainVerbose());
queryMenu->Check(MNU_ANALYZE, settings->GetExplainAnalyze());
+ queryMenu->Check(MNU_COSTS, settings->GetExplainCosts());
+ queryMenu->Check(MNU_BUFFERS, settings->GetExplainBuffers());
UpdateRecentFiles();
@@ -1480,6 +1484,8 @@ void frmQuery::OnClose(wxCloseEvent& event)
settings->SetExplainAnalyze(queryMenu->IsChecked(MNU_ANALYZE));
settings->SetExplainVerbose(queryMenu->IsChecked(MNU_VERBOSE));
+ settings->SetExplainCosts(queryMenu->IsChecked(MNU_COSTS));
+ settings->SetExplainBuffers(queryMenu->IsChecked(MNU_BUFFERS));
sqlResult->Abort(); // to make sure conn is unused
@@ -1836,10 +1842,37 @@ void frmQuery::OnExplain(wxCommandEvent& event)
resultToRetrieve++;
}
sql += wxT("EXPLAIN ");
- if (analyze)
- sql += wxT("ANALYZE ");
- if (verbose)
- sql += wxT("VERBOSE ");
+ if (conn->BackendMinimumVersion(8, 5))
+ {
+ bool costs=queryMenu->IsChecked(MNU_COSTS);
+ bool buffers=queryMenu->IsChecked(MNU_BUFFERS);
+
+ sql += wxT("(");
+ if (analyze)
+ sql += wxT("ANALYZE on, ");
+ else
+ sql += wxT("ANALYZE off, ");
+ if (verbose)
+ sql += wxT("VERBOSE on, ");
+ else
+ sql += wxT("VERBOSE off, ");
+ if (costs)
+ sql += wxT("COSTS on, ");
+ else
+ sql += wxT("COSTS off, ");
+ if (buffers)
+ sql += wxT("BUFFERS on ");
+ else
+ sql += wxT("BUFFERS off ");
+ sql += wxT(")");
+ }
+ else
+ {
+ if (analyze)
+ sql += wxT("ANALYZE ");
+ if (verbose)
+ sql += wxT("VERBOSE ");
+ }
int offset=sql.Length();
diff --git a/pgadmin/include/frm/menu.h b/pgadmin/include/frm/menu.h
index febe74a..e1b069a 100644
--- a/pgadmin/include/frm/menu.h
+++ b/pgadmin/include/frm/menu.h
@@ -65,6 +65,8 @@ enum
MNU_EXPLAINOPTIONS,
MNU_VERBOSE,
MNU_ANALYZE,
+ MNU_COSTS,
+ MNU_BUFFERS,
MNU_AUTOROLLBACK,
MNU_CLEARHISTORY,
MNU_SAVEHISTORY,
diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h
index 984f287..5c814be 100644
--- a/pgadmin/include/utils/sysSettings.h
+++ b/pgadmin/include/utils/sysSettings.h
@@ -94,6 +94,10 @@ public:
void SetExplainVerbose(const bool newval) { Write(wxT("frmQuery/ExplainVerbose"), newval); }
bool GetExplainAnalyze() const { bool b; Read(wxT("frmQuery/ExplainAnalyze"), &b, false); return b; }
void SetExplainAnalyze(const bool newval) { Write(wxT("frmQuery/ExplainAnalyze"), newval); }
+ bool GetExplainCosts() const { bool b; Read(wxT("frmQuery/ExplainCosts"), &b, true); return b; }
+ void SetExplainCosts(const bool newval) { Write(wxT("frmQuery/ExplainCosts"), newval); }
+ bool GetExplainBuffers() const { bool b; Read(wxT("frmQuery/ExplainBuffers"), &b, false); return b; }
+ void SetExplainBuffers(const bool newval) { Write(wxT("frmQuery/ExplainBuffers"), newval); }
// Display options
wxString GetSystemSchemas() const { wxString s; Read(wxT("SystemSchemas"), &s, wxEmptyString); return s; }
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers