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.

This commit is contained in:
Ansgar Becker
2009-01-27 19:32:20 +00:00
parent 24b1ca16a9
commit e791339e86
2 changed files with 17 additions and 10 deletions

View File

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

View File

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