Patch for pgstatindex - Mailing list pgadmin-hackers

From Guillaume Lelarge
Subject Patch for pgstatindex
Date
Msg-id 45E6144E.5090803@lelarge.info
Whole thread Raw
Responses Re: Patch for pgstatindex  (Dave Page <dpage@postgresql.org>)
Re: Patch for pgstatindex  (Dave Page <dpage@postgresql.org>)
List pgadmin-hackers
Hi,

Finally, I found some time to work on this patch. It adds support for
pgstatindex function (8.2 pgstattuple contrib module).

Please, review it.

Thanks.


--
Guillaume.
<!-- http://abs.traduc.org/
      http://lfs.traduc.org/
      http://docs.postgresqlfr.org/ -->
Index: include/schema/pgIndex.h
===================================================================
--- include/schema/pgIndex.h    (révision 5962)
+++ include/schema/pgIndex.h    (copie de travail)
@@ -77,10 +77,13 @@
     wxString GetSql(ctlTree *browser);
     pgObject *Refresh(ctlTree *browser, const wxTreeItemId item);
     bool CanMaintenance() { return true; }
+    bool GetShowExtendedStatistics() { return showExtendedStatistics; }
+    void iSetShowExtendedStatistics(bool b) { showExtendedStatistics = b; }

     bool HasStats() { return true; }
     bool HasDepends() { return true; }
     bool HasReferences() { return true; }
+    bool HasPgstatindex();

 protected:
     void ReadColumnDetails();
@@ -90,7 +93,7 @@
     wxString procName, procNamespace, procArgs, procArgTypeList, typedColumns, quotedTypedColumns, operatorClasses,
operatorClassList;
     long columnCount;
     bool isUnique, isPrimary, isClustered;
-    bool deferrable, deferred;
+    bool deferrable, deferred, showExtendedStatistics;
     OID relTableOid;
 };

@@ -120,5 +123,14 @@
 };
 extern pgIndexFactory indexFactory;

+class executePgstatindexFactory : public contextActionFactory
+{
+public:
+    executePgstatindexFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar);
+    wxWindow *StartDialog(frmMain *form, pgObject *obj);
+    bool CheckEnable(pgObject *obj);
+    bool CheckChecked(pgObject *obj);
+};

+
 #endif
Index: include/utils/pgfeatures.h
===================================================================
--- include/utils/pgfeatures.h    (révision 5962)
+++ include/utils/pgfeatures.h    (copie de travail)
@@ -23,6 +23,7 @@
     FEATURE_TERMINATE_BACKEND,
     FEATURE_RELOAD_CONF,
     FEATURE_PGSTATTUPLE,
+    FEATURE_PGSTATINDEX,
     FEATURE_LAST
 };

Index: frm/frmMain.cpp
===================================================================
--- frm/frmMain.cpp    (révision 5962)
+++ frm/frmMain.cpp    (copie de travail)
@@ -65,6 +65,7 @@
 #include "dlg/dlgServer.h"
 #include "dlg/dlgDatabase.h"
 #include "schema/pgTable.h"
+#include "schema/pgIndex.h"
 #include "schema/pgTrigger.h"
 #include "schema/pgServer.h"
 #include "slony/slCluster.h"
@@ -261,9 +262,10 @@
     actionFactory *refFact=new refreshFactory(menuFactories, viewMenu, toolBar);
     new countRowsFactory(menuFactories, viewMenu, 0);
     new executePgstattupleFactory(menuFactories, viewMenu, 0);
+    new executePgstatindexFactory(menuFactories, viewMenu, 0);
     new enabledisableTriggerFactory(menuFactories, toolsMenu, 0);
     new disableAllTriggersFactory(menuFactories, toolsMenu, 0);
-    new enableAllTriggersFactory(menuFactories, toolsMenu, 0);
+    new enableAllTriggersFactory(menuFactories, toolsMenu, 0);

     //--------------------------
     new separatorFactory(menuFactories);
Index: db/pgConn.cpp
===================================================================
--- db/pgConn.cpp    (révision 5962)
+++ db/pgConn.cpp    (copie de travail)
@@ -336,8 +336,9 @@
             wxT("  FROM pg_proc\n")
             wxT("  JOIN pg_namespace n ON n.oid=pronamespace\n")
             wxT(" WHERE proname IN ('pg_tablespace_size', 'pg_file_read', 'pg_logfile_rotate',")
-            wxT(                  " 'pg_postmaster_starttime', 'pg_terminate_backend', 'pg_reload_conf' ,
'pgstattuple')\n")
-            wxT("   AND nspname IN ('pg_catalog', 'public')");
+            wxT(                  " 'pg_postmaster_starttime', 'pg_terminate_backend', 'pg_reload_conf',")
+            wxT(                  " 'pgstattuple', 'pgstatindex')\n")
+            wxT("   AND nspname IN ('pg_catalog', 'public')");

         pgSet *set=ExecuteSet(sql);

@@ -363,6 +364,8 @@
                     features[FEATURE_RELOAD_CONF] = true;
                 else if (proname == wxT("pgstattuple") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25)
                     features[FEATURE_PGSTATTUPLE]= true;
+                else if (proname == wxT("pgstatindex") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25)
+                    features[FEATURE_PGSTATINDEX]= true;

                 set->MoveNext();
             }
Index: schema/pgIndex.cpp
===================================================================
--- schema/pgIndex.cpp    (révision 5962)
+++ schema/pgIndex.cpp    (copie de travail)
@@ -14,6 +14,7 @@

 // App headers
 #include "pgAdmin3.h"
+#include "frm/frmMain.h"
 #include "utils/misc.h"
 #include "utils/pgfeatures.h"
 #include "schema/pgIndex.h"
@@ -24,6 +25,7 @@
 pgIndexBase::pgIndexBase(pgTable *newTable, pgaFactory &factory, const wxString& newName)
 : pgTableObject(newTable, factory, newName)
 {
+    showExtendedStatistics = false;
 }

 bool pgIndexBase::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
@@ -224,9 +226,35 @@

 void pgIndexBase::ShowStatistics(frmMain *form, ctlListView *statistics)
 {
+    wxString sql;
+
     if (GetConnection()->HasFeature(FEATURE_SIZE))
-        DisplayStatistics(statistics,
-            wxT("SELECT pg_size_pretty(pg_relation_size(") + GetOidStr() + wxT(")) AS ") + qtIdent(_("Index Size")));
+        sql = wxT("SELECT pg_size_pretty(pg_relation_size(") + GetOidStr() + wxT(")) AS ") + qtIdent(_("Index Size"));
+
+    if (showExtendedStatistics)
+    {
+        if (sql.Length() == 0)
+        {
+          sql = wxT("SELECT ");
+        }
+        else
+        {
+          sql += wxT(", ");
+        }
+        sql += wxT(" version AS ") + qtIdent(_("Version")) + wxT(",\n")
+               wxT("  tree_level AS ") + qtIdent(_("Tree Level")) + wxT(",\n")
+               wxT("  pg_size_pretty(index_size) AS ") + qtIdent(_("Index Size")) + wxT(",\n")
+               wxT("  root_block_no AS ") + qtIdent(_("Root Block No")) + wxT(",\n")
+               wxT("  internal_pages AS ") + qtIdent(_("Internal Pages")) + wxT(",\n")
+               wxT("  leaf_pages AS ") + qtIdent(_("Leaf Pages")) + wxT(",\n")
+               wxT("  empty_pages AS ") + qtIdent(_("Empty Pages")) + wxT(",\n")
+               wxT("  deleted_pages AS ") + qtIdent(_("Deleted Pages")) + wxT(",\n")
+               wxT("  avg_leaf_density AS ") + qtIdent(_("Average Leaf Density")) + wxT(",\n")
+               wxT("  leaf_fragmentation AS ") + qtIdent(_("Leaf Fragmentation")) + wxT("\n")
+               wxT("  FROM pgstatindex('") + GetQuotedFullIdentifier() + wxT("')");
+    }
+
+    DisplayStatistics(statistics, sql);
 }


@@ -241,6 +269,46 @@
 }


+bool pgIndexBase::HasPgstatindex()
+{
+    return GetConnection()->HasFeature(FEATURE_PGSTATINDEX);
+}
+
+executePgstatindexFactory::executePgstatindexFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) :
contextActionFactory(list)
+{
+    mnu->Append(id, _("&Extended statistics"), _("Get extended statistics via pgstatindex for the selected object."),
wxITEM_CHECK);
+}
+
+
+wxWindow *executePgstatindexFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+    if (!((pgIndexBase*)obj)->GetShowExtendedStatistics())
+    {
+        ((pgIndexBase*)obj)->iSetShowExtendedStatistics(true);
+        wxTreeItemId item=form->GetBrowser()->GetSelection();
+        if (obj == form->GetBrowser()->GetObject(item))
+            form->SelectStatisticsTab();
+    }
+    else
+        ((pgIndexBase*)obj)->iSetShowExtendedStatistics(false);
+
+    form->GetMenuFactories()->CheckMenu(obj, form->GetMenuBar(), form->GetToolBar());
+
+    return 0;
+}
+
+
+bool executePgstatindexFactory::CheckEnable(pgObject *obj)
+{
+    return obj && obj->IsCreatedBy(indexFactory) && ((pgIndexBase*)obj)->HasPgstatindex();
+}
+
+bool executePgstatindexFactory::CheckChecked(pgObject *obj)
+{
+    return obj && ((pgIndexBase*)obj)->GetShowExtendedStatistics();
+}
+
+
 pgIndex::pgIndex(pgTable *newTable, const wxString& newName)
 : pgIndexBase(newTable, indexFactory, newName)
 {

pgadmin-hackers by date:

Previous
From: svn@pgadmin.org
Date:
Subject: SVN Commit by guillaume: r5962 - in trunk/pgadmin3/i18n: zh_CN zh_TW
Next
From: Dave Page
Date:
Subject: Re: Patch for pgstatindex