From e791339e86f8a42802a279c23c3884d26644b3c8 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 27 Jan 2009 19:32:20 +0000 Subject: [PATCH] Try a pragmatic workaround for bug #761 (Large tables crash TVirtualTree) and bug #950 (Decrease memory usage for grid results). Makes the data grid hard limited to a maximum of 100,000 rows/nodes (means ~6M memory consumption just for the tree nodes). It seems reasonable to do this as on large tables you normally create a filter to find specific rows rather than scrolling and looking the rows up by hand. The grid is now able again to display superlarge tables without losing too much memory for data of few interest. However, I hope there's no complaint the other way around for why we don't display all rows instead. --- components/heidisql/include/const.inc | 3 +++ source/main.pas | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/components/heidisql/include/const.inc b/components/heidisql/include/const.inc index b13795f1..9a61bf73 100644 --- a/components/heidisql/include/const.inc +++ b/components/heidisql/include/const.inc @@ -292,6 +292,9 @@ const // Data grid: How many rows to fetch at a time. GRIDMAXROWS: Cardinal = 500; + // Data grid: How many rows to display in total + GRIDMAXTOTALROWS = 100000; + // How many milliseconds to wait before showing a 'waiting for database' sign. QUERYWAITTIME: Integer = 2500; diff --git a/source/main.pas b/source/main.pas index b37205d7..4845fcb0 100644 --- a/source/main.pas +++ b/source/main.pas @@ -762,7 +762,7 @@ type function GetActiveData: PGridResult; procedure WaitForQueryCompletion(WaitForm: TfrmQueryProgress; query: TMySqlQuery; ForceDialog: Boolean); function RunThreadedQuery(AQuery: WideString; ForceDialog: Boolean): TMysqlQuery; - procedure DisplayRowCountStats; + procedure DisplayRowCountStats(MatchingRows: Int64); procedure insertFunction(Sender: TObject); function GetActiveDatabase: WideString; function GetSelectedTable: WideString; @@ -3426,6 +3426,7 @@ var rx : TRegExpr; ColType : String; ColExists, ShowIt : Boolean; + MatchingRows : Int64; procedure InitColumn(name: WideString; ColType: String; Visible: Boolean); var @@ -3645,7 +3646,10 @@ begin sl_query.Add(select_from); // Apply custom WHERE filter if DataGridCurrentFilter <> '' then sl_query.Add('WHERE ' + DataGridCurrentFilter); - count := StrToInt(GetVar(sl_query.Text)); + MatchingRows := StrToInt(GetVar(sl_query.Text)); + count := MatchingRows; + if count > GRIDMAXTOTALROWS then + count := GRIDMAXTOTALROWS; except on E:Exception do begin // Most likely we have a wrong filter-clause when this happens @@ -3681,7 +3685,7 @@ begin DataGrid.OffsetXY := Point(0, 0); // Scroll to top left FreeAndNil(PrevTableColWidths); // Throw away remembered, manually resized column widths end; - DisplayRowCountStats; + DisplayRowCountStats(MatchingRows); dataselected := true; pcChange(self); @@ -3704,9 +3708,8 @@ end; Calculate + display total rowcount and found rows matching to filter in data-tab } -procedure TMainForm.DisplayRowCountStats; +procedure TMainForm.DisplayRowCountStats(MatchingRows: Int64); var - rows_matching : Int64; // rows matching to where-filter rows_total : Int64; // total rowcount IsFiltered, IsInnodb: Boolean; ds: TDataSet; @@ -3740,13 +3743,14 @@ begin lblDataTop.Caption := lblDataTop.Caption + ' [View]'; end; - rows_matching := DataGrid.RootNodeCount; + if( MatchingRows <> rows_total ) and IsFiltered then + lblDataTop.Caption := lblDataTop.Caption + ', ' + FormatNumber(MatchingRows) + ' matching to filter'; - if( rows_matching <> rows_total ) and IsFiltered then - lblDataTop.Caption := lblDataTop.Caption + ', ' + FormatNumber(rows_matching) + ' matching to filter'; - - if ( rows_matching >= rows_total ) and IsFiltered then + if ( MatchingRows >= rows_total ) and IsFiltered then lblDataTop.Caption := lblDataTop.Caption + ', filter matches all rows'; + + if MatchingRows > DataGrid.RootNodeCount then + lblDataTop.Caption := lblDataTop.Caption + ', limited to '+FormatNumber(DataGrid.RootNodeCount); end;