Add CFS defragmentation for table or index.

В frmMaintenance добавлено выполнение принудительной дефрагментации сжатой таблицы
или индекса. При выборе сжатой таблицы, автоматически дефрагментируются её
сжатые индексы если их деврагметация более 1%.
This commit is contained in:
lsv 2021-01-06 16:59:23 +05:00
parent bb831e57f2
commit b1da480ca8
3 changed files with 33 additions and 1 deletions

View file

@ -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;

View file

@ -13,4 +13,14 @@
<LocalDebuggerCommandArguments>-s mi -q</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_(3.0)|x64'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_(3.0)|x64'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View file

@ -27,6 +27,7 @@
<item>ANALYZE</item>
<item>REINDEX</item>
<item>CLUSTER</item>
<item>COMPRESS</item>
</content>
<selection>0</selection>
<style>wxRA_SPECIFY_ROWS</style>