From b1da480ca81f59edccb5117bb1b32d4dcfff3804 Mon Sep 17 00:00:00 2001 From: lsv Date: Wed, 6 Jan 2021 16:59:23 +0500 Subject: [PATCH] Add CFS defragmentation for table or index. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit В frmMaintenance добавлено выполнение принудительной дефрагментации сжатой таблицы или индекса. При выборе сжатой таблицы, автоматически дефрагментируются её сжатые индексы если их деврагметация более 1%. --- frm/frmMaintenance.cpp | 23 ++++++++++++++++++++++- pgAdmin3.vcxproj.user | 10 ++++++++++ ui/frmMaintenance.xrc | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/frm/frmMaintenance.cpp b/frm/frmMaintenance.cpp index ca3df29..7dfef44 100644 --- a/frm/frmMaintenance.cpp +++ b/frm/frmMaintenance.cpp @@ -64,13 +64,23 @@ frmMaintenance::frmMaintenance(frmMain *form, pgObject *obj) : ExecutionDialog(f #ifndef __WXGTK__ txtMessages->SetMaxLength(0L); #endif - + bool iscomprss = false; if (object->GetMetaType() == PGM_INDEX || object->GetMetaType() == PGM_PRIMARYKEY || object->GetMetaType() == PGM_UNIQUE) { rbxAction->SetSelection(2); rbxAction->Enable(0, false); rbxAction->Enable(1, false); + if (object->GetDatabase()->connection()->GetIsPgProEnt()) { + wxString ratio = object->GetConnection()->ExecuteScalar("select left((cfs_fragmentation("+object->GetOidStr()+")*100)::text,5)::text"); + iscomprss = !(ratio == "NaN"); + } } + if (object->GetMetaType() == PGM_TABLE) { + pgTable* t = (pgTable *)object; + iscomprss = !(t->GetRatio() == ""); + + } + rbxAction->Enable(4, iscomprss); wxCommandEvent ev; OnAction(ev); } @@ -218,6 +228,17 @@ wxString frmMaintenance::GetSql() } } } + case 4: + { + sql = wxT("set cfs_gc_threshold = 0;select "); + sql += "cfs_gc_relation(" + object->GetOidStr() + ")"; + if (object->GetMetaType() == PGM_TABLE) { + //sql += object->GetQuotedFullIdentifier(); + wxString strindex= object->GetConnection()->ExecuteScalar("select string_agg('cfs_gc_relation('||indexrelid::text||')',',') from pg_index i where indrelid=" + object->GetOidStr() + " and cfs_fragmentation(indexrelid) between 0.01 and 1;"); + if (strindex.Len() > 0) sql += ","+strindex; + } + + } } return sql; diff --git a/pgAdmin3.vcxproj.user b/pgAdmin3.vcxproj.user index 437c493..78f1da1 100644 --- a/pgAdmin3.vcxproj.user +++ b/pgAdmin3.vcxproj.user @@ -13,4 +13,14 @@ -s mi -q WindowsLocalDebugger + + + + WindowsLocalDebugger + + + + + WindowsLocalDebugger + \ No newline at end of file diff --git a/ui/frmMaintenance.xrc b/ui/frmMaintenance.xrc index 2b71bd9..5c72606 100644 --- a/ui/frmMaintenance.xrc +++ b/ui/frmMaintenance.xrc @@ -27,6 +27,7 @@ ANALYZE REINDEX CLUSTER + COMPRESS 0