I have a Firebird database with 3 million records. My FetchOptions
are RowsetSize := 1000
with FetchAll
disabled. I work on localhost.
I have no problem browsing page by page, but when I click on "goto last record" button in the DBNavigator
, it throws "Out of memory" exception.
If I set UniDirectional
property to True
, there is no problem. However, moving to the last record causes application to freeze for 30-40 seconds.
What is the problem and the solution ?
The problem is that your approach really consumes all available memory and you are notified properly by getting the "out of memory" error. All records are fetched from the server and kept in memory. OS can't allocate more to your application.
What to do? Just avoid to load millions of records. Your users in any case will not be able to traverse/browse/inspect each record from that a huge dataset.
Options to consider:
The solution is to use TFDTable dataset instead of default one TFDQuery. TFDTable dataset supports Live Data Window Mode. In this mode dataset is bidirectional so it can be used with visual components like for example TDBGrid. The difference in comparison with TFDQuery is that old records are discarded. At every time instant dataset keeps in memory only 2 * FetchOptions.RowsetSize records (default value 2 * 50 = 100 records), a window into the table data. When the application navigates through the table data, FireDAC automatically scrolls or positions the Live Data Window to the required position. This offers the following benefits:
In LDW mode, the Filter property value is substituted as is into the WHERE phrase. By design, LDW mode always applies the ORDER BY phrase to the SELECT commands. The key requirement for the correct LDW work, are:
Although FireDAC minimizes the number of generated and executed SQL commands in LDW mode, it still produces a heavier DB load than TFDQuery. So, application developers should carefully choose when to use TFDTable and LDW mode.
Setting the LDW Mode
The LDW mode is used when all the following conditions are met:
Otherwise, the standard mode is used.
More information can be found in Embarcadero documentation: http://docwiki.embarcadero.com/RADStudio/Rio/en/Browsing_Tables_(FireDAC)#Live_Data_Window_Mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With