Skip to content

Commit

Permalink
Merge pull request mariuz#331 from arvanus/master
Browse files Browse the repository at this point in the history
Improve SQL statistics
  • Loading branch information
arvanus authored Oct 10, 2023
2 parents d62df7e + 41249aa commit efd8b62
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/gui/CommandIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum {
// SQL Query
Query_Execute,
Query_Show_plan,
Query_Show_Statistics,
Query_Execute_selection,
Query_Execute_from_cursor,
Query_Commit,
Expand Down
22 changes: 21 additions & 1 deletion src/gui/ExecuteSqlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ ExecuteSqlFrame::ExecuteSqlFrame(wxWindow* WXUNUSED(parent), int id,
transactionIsolationLevelM = static_cast<IBPP::TIL>(config().get("transactionIsolationLevel", 0));
transactionLockResolutionM = config().get("transactionLockResolution", true) ? IBPP::lrWait : IBPP::lrNoWait;
transactionAccessModeM = config().get("transactionAccessMode", false) ? IBPP::amRead : IBPP::amWrite;
showStatisticsM = config().get("SQLEditorShowStats", true);

timerBlobEditorM.SetOwner(this, TIMER_ID_UPDATE_BLOB);

Expand Down Expand Up @@ -730,6 +731,8 @@ void ExecuteSqlFrame::buildMainMenu(CommandManager& cm)
cm.getMainMenuItemText(_("&Execute"), Cmds::Query_Execute));
statementMenu->Append(Cmds::Query_Show_plan,
cm.getMainMenuItemText(_("Show execution &plan"), Cmds::Query_Show_plan));
statementMenu->AppendCheckItem(Cmds::Query_Show_Statistics,
cm.getMainMenuItemText(_("Display detailed query statistics"), Cmds::Query_Show_Statistics));
statementMenu->Append(Cmds::Query_Execute_selection,
cm.getMainMenuItemText(_("Execute &selection"), Cmds::Query_Execute_selection));
statementMenu->Append(Cmds::Query_Execute_from_cursor,
Expand Down Expand Up @@ -950,6 +953,8 @@ BEGIN_EVENT_TABLE(ExecuteSqlFrame, wxFrame)

EVT_MENU(Cmds::Query_Execute, ExecuteSqlFrame::OnMenuExecute)
EVT_MENU(Cmds::Query_Show_plan, ExecuteSqlFrame::OnMenuShowPlan)
EVT_MENU(Cmds::Query_Show_Statistics, ExecuteSqlFrame::OnMenuShowStatistics)
EVT_UPDATE_UI(Cmds::Query_Show_Statistics, ExecuteSqlFrame::OnMenuUpdateShowStatistics)
EVT_MENU(Cmds::Query_Execute_selection, ExecuteSqlFrame::OnMenuExecuteSelection)
EVT_MENU(Cmds::Query_Execute_from_cursor, ExecuteSqlFrame::OnMenuExecuteFromCursor)
EVT_UPDATE_UI(Cmds::Query_Execute, ExecuteSqlFrame::OnMenuUpdateWhenExecutePossible)
Expand Down Expand Up @@ -1619,6 +1624,16 @@ void ExecuteSqlFrame::OnMenuShowPlan(wxCommandEvent& WXUNUSED(event))
prepareAndExecute(true);
}

void ExecuteSqlFrame::OnMenuShowStatistics(wxCommandEvent& event)
{
showStatisticsM = event.IsChecked();
}

void ExecuteSqlFrame::OnMenuUpdateShowStatistics(wxUpdateUIEvent& event)
{
event.Check(showStatisticsM);
}

void ExecuteSqlFrame::OnMenuExecuteFromCursor(wxCommandEvent& WXUNUSED(event))
{
clearLogBeforeExecution();
Expand Down Expand Up @@ -2244,6 +2259,7 @@ wxString IBPPtype2string(Database *db, IBPP::SDT t, int subtype, int size,
case IBPP::sdLargeint: return "BIGINT";
case IBPP::sdFloat: return "FLOAT";
case IBPP::sdDouble: return "DOUBLE PRECISION";
case IBPP::sdBoolean: return "BOOLEAN";
case IBPP::sdTimeTz: return "TIME WITH TIMEZONE";
case IBPP::sdTimestampTz: return "TIMESTAMP WITH TIMEZONE";
case IBPP::sdInt128: return "INT128";
Expand Down Expand Up @@ -2272,6 +2288,10 @@ void ExecuteSqlFrame::compareCounts(IBPP::DatabaseCounts& one,
str_log += wxString::Format(_("%d updates. "), r1.updates - r2.updates);
if (r1.deletes > r2.deletes)
str_log += wxString::Format(_("%d deletes. "), r1.deletes - r2.deletes);
if (r1.readIndex > r2.readIndex)
str_log += wxString::Format(_("%d reads index. "), r1.readIndex - r2.readIndex);
if (r1.readSequence > r2.readSequence)
str_log += wxString::Format(_("%d reads sequence. "), r1.readSequence - r2.readSequence);
if (!str_log.IsEmpty())
{
wxString relName;
Expand Down Expand Up @@ -2386,7 +2406,7 @@ bool ExecuteSqlFrame::execute(wxString sql, const wxString& terminator,
del1 = 0, ridx1 = 0, rseq1 = 0, mem1 = 0;
int fetch2, mark2, read2, write2, ins2, upd2, del2, ridx2, rseq2, mem2;
IBPP::DatabaseCounts counts1, counts2;
bool doShowStats = config().get("SQLEditorShowStats", true);
bool doShowStats = showStatisticsM;
if (!prepareOnly && doShowStats)
{
databaseM->getIBPPDatabase()->
Expand Down
3 changes: 3 additions & 0 deletions src/gui/ExecuteSqlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ExecuteSqlFrame: public BaseFrame, public Observer
IBPP::TIL transactionIsolationLevelM;
IBPP::TLR transactionLockResolutionM;
IBPP::TAM transactionAccessModeM;
bool showStatisticsM;
void inTransaction(bool started); // changes controls (enable/disable)
bool commitTransaction();
bool rollbackTransaction();
Expand Down Expand Up @@ -210,6 +211,8 @@ class ExecuteSqlFrame: public BaseFrame, public Observer

void OnMenuExecute(wxCommandEvent& event);
void OnMenuShowPlan(wxCommandEvent& event);
void OnMenuShowStatistics(wxCommandEvent& event);
void OnMenuUpdateShowStatistics(wxUpdateUIEvent& event);
void OnMenuExecuteSelection(wxCommandEvent& event);
void OnMenuExecuteFromCursor(wxCommandEvent& event);
void OnMenuCommit(wxCommandEvent& event);
Expand Down
4 changes: 4 additions & 0 deletions src/ibpp/_rb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ void RB::GetDetailedCounts(IBPP::DatabaseCounts& counts, char token)
(*it).second.updates += value;
if (token == isc_info_delete_count)
(*it).second.deletes += value;
if (token == isc_info_read_idx_count)
(*it).second.readIndex += value;
if (token == isc_info_read_seq_count)
(*it).second.readSequence += value;
p += 6;
len -= 6;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ibpp/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ void DatabaseImpl::DetailedCounts(IBPP::DatabaseCounts& counts)
char items[] = {isc_info_insert_count,
isc_info_update_count,
isc_info_delete_count,
isc_info_read_idx_count,
isc_info_read_seq_count,
isc_info_end};
IBS status;
RB result(1024);
Expand All @@ -365,6 +367,8 @@ void DatabaseImpl::DetailedCounts(IBPP::DatabaseCounts& counts)
result.GetDetailedCounts(counts, isc_info_insert_count);
result.GetDetailedCounts(counts, isc_info_update_count);
result.GetDetailedCounts(counts, isc_info_delete_count);
result.GetDetailedCounts(counts, isc_info_read_idx_count);
result.GetDetailedCounts(counts, isc_info_read_seq_count);
}

void DatabaseImpl::Users(std::vector<std::string>& users)
Expand Down
4 changes: 3 additions & 1 deletion src/ibpp/ibpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,12 @@ namespace IBPP
class CountInfo
{
public:
CountInfo(): inserts(0), updates(0), deletes(0) {}
CountInfo(): inserts(0), updates(0), deletes(0), readIndex(0), readSequence(0) {}
int inserts;
int updates;
int deletes;
int readIndex;
int readSequence;
};
typedef std::map<int, CountInfo> DatabaseCounts; // int = relation ID

Expand Down

0 comments on commit efd8b62

Please sign in to comment.