Search code examples
delphimemorydelphi-2010ado

How does AdoQuery handle blobs?


I am testing some databases components such as SDAC and others and I found out something interesting:

When I execute a query with TADOQuery and this query has a lot of blob fields and I get all rows (fetchall) the memory of my application gets close to 1.8GB and everything works fine.

Using other components, the same query executed on the same database trows an Out of Memory exception because it exceeds 1.8GB of memory usage.

I know I should not return all those rows, i should use pagination and blablabla. But i am curious how can ADO manage to get all rows and other components cant.

I think that ADO is compressing the blobs in memory, but this is only a guess.

Does anyone knows why memory usage in ADO is so good?


Solution

  • I cannot say about SDAC, but will say about AnyDAC TADQuery:

    • if exclude fiBlobs from FetchOptions.Items, then AnyDAC will not fetch BLOB values immediately. But will defer fetching until the application will really need a BLOB value;
    • setting FormatOptions.InlineDataSize to more small value, will reduce memory usage on fetching large result set with multiple character fields;
    • specifying FormatOptions.MapRules, application may choose more compact data type representation.

    Also there are few other techniques, allowing to reduce memory usage when fetching large result sets. To use them properly a developer should know what kind of data will be returned. The price of some options usage may be a slightly reduced fetch performance.