John Lotacs
John Lotacs

Reputation: 1254

QSqlQuery using hundreds of MB of memory

I'm using a QSqlQuery object to do a linear walk of a 10million row SQL table with a very complex 6 column primary key in sorted order. Because of the key(which I CAN NOT change), breaking upmy query SELECT * FROM table1 with < or > with LIMIT causes a huge number of issues with the algorithm I'm using.

My problem arising is as follows, for whatever reason QSqlQuery seems to be caching the entire result set in memory until it hits a bad alloc and kills the application. So I may read some couple hundred rows, seek() over a couple hundred thousand, and by this point QSqlQuery is using 300mb of memory and my application dies. I read the docs and it seems the only thing that can be done is to use setForwardOnly(), however I often have a need for previous()(which is why breaking up the query with LIMIT is a PITA)

Is there no way to cap the cache for QSqlQuery?

Upvotes: 0

Views: 607

Answers (1)

MSalters
MSalters

Reputation: 179809

Why don't you store previous yourself? There's a QContiguousCache which seems ideal for this.

Upvotes: 1

Related Questions