From 1ae40f28af594b0a0ff74be1b3576ce574f57a6d Mon Sep 17 00:00:00 2001 From: lsv Date: Tue, 19 Jan 2021 11:23:35 +0500 Subject: [PATCH] Add reset index statistics. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлена команда "Reset index statistics". --- frm/frmMain.cpp | 1 + include/schema/pgIndex.h | 8 ++++++++ schema/pgIndex.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/frm/frmMain.cpp b/frm/frmMain.cpp index 0a875cb..c9ee036 100644 --- a/frm/frmMain.cpp +++ b/frm/frmMain.cpp @@ -315,6 +315,7 @@ void frmMain::CreateMenus() new refreshConcurrentlyMatViewFactory(menuFactories, viewMenu, 0); new executePgstattupleFactory(menuFactories, viewMenu, 0); new executePgstatindexFactory(menuFactories, viewMenu, 0); + new resetIndexStatsFactory(menuFactories, viewMenu, 0); new executePgcheckindexFactory(menuFactories, viewMenu, 0); new enabledisableRuleFactory(menuFactories, toolsMenu, 0); new enabledisableTriggerFactory(menuFactories, toolsMenu, 0); diff --git a/include/schema/pgIndex.h b/include/schema/pgIndex.h index 9a56318..3add8d7 100644 --- a/include/schema/pgIndex.h +++ b/include/schema/pgIndex.h @@ -354,5 +354,13 @@ public: bool CheckEnable(pgObject* obj); }; +class resetIndexStatsFactory : public contextActionFactory +{ +public: + resetIndexStatsFactory(menuFactoryList* list, wxMenu* mnu, ctlMenuToolbar* toolbar); + wxWindow* StartDialog(frmMain* form, pgObject* obj); + bool CheckEnable(pgObject* obj); +}; + #endif diff --git a/schema/pgIndex.cpp b/schema/pgIndex.cpp index b40ba7c..b136878 100644 --- a/schema/pgIndex.cpp +++ b/schema/pgIndex.cpp @@ -547,6 +547,34 @@ bool executePgstatindexFactory::CheckChecked(pgObject *obj) return false; } +resetIndexStatsFactory::resetIndexStatsFactory(menuFactoryList* list, wxMenu* mnu, ctlMenuToolbar* toolbar) : contextActionFactory(list) +{ + mnu->Append(id, _("&Reset index statistics"), _("Reset statistics of the selected index.")); +} + + +wxWindow* resetIndexStatsFactory::StartDialog(frmMain* form, pgObject* obj) +{ + if (wxMessageBox(_("Are you sure you wish to reset statistics of this index?"), _("Reset statistics"), wxYES_NO) != wxYES) + return 0; + + wxString sql = wxT("SELECT pg_stat_reset_single_table_counters(") + + NumToStr(obj->GetOid()) + + wxT(")"); + obj->GetDatabase()->ExecuteVoid(sql); + + ((pgIndexBase*)obj)->ShowStatistics(form, form->GetStatistics()); + + return 0; +} + + +bool resetIndexStatsFactory::CheckEnable(pgObject* obj) +{ + return obj && + (obj->IsCreatedBy(indexFactory) || obj->IsCreatedBy(primaryKeyFactory) + || obj->IsCreatedBy(uniqueFactory) || obj->IsCreatedBy(excludeFactory)); +} pgIndex::pgIndex(pgSchema *newSchema, const wxString &newName)