PDA

View Full Version : performance of Using QSqlQuery to access table containing blob coloumn



silentyears
18th February 2014, 14:25
Hi,
As subject, i use QSqlQuery to access tableA which contains column storing blob data as follows,


QSqlQuery query("SELECT * FROM tableA");
while (query.next()) {
i++;
}

The speed of query is too slow which need about 5s to execute whole "while" loop, is there any idea to improved it? How to deal with blob?
Thanks!

Lesiok
18th February 2014, 17:13
The Database must provide you with the entire contents of the table, although you are using for anything. Why are you surprised?
What is Yours real problem - what You want to do ?

silentyears
20th February 2014, 14:08
Hello,

I have a Oracle database with a large dataset, around 200000 rows.
These rows are selected from the database with a QSqlQuery like this:


QSqlQuery query("SELECT * FROM tableA");
while (query.next()) {
i++;
}

If one of the fields of tableA is blob type (the size of each blob is less than 5M), to get all the rows in a while loop need about 5 seconds. But if i do a query with the command which select all fields except the fileld of blob type, the speed becomes fast.
Why? What can i do to make the former as fast as the latter?
Thanks very much!

stampede
20th February 2014, 20:27
Why? What can i do to make the former as fast as the latter?
Because the BLOB is probably big and it requires a huge amount of processing power to query all these rows from database into memory. If you don't select it in your query, then database driver will not load BLOBs into memory, which allows it to complete faster.
If you need to do some kind of processing on these rows then display a progress dialog or something. What is your task anyway ? I doubt you will increment an integer in your final code, if you give us more details then maybe we can help to optimize your code.

silentyears
25th February 2014, 11:21
Because the BLOB is probably big and it requires a huge amount of processing power to query all these rows from database into memory. If you don't select it in your query, then database driver will not load BLOBs into memory, which allows it to complete faster.
If you need to do some kind of processing on these rows then display a progress dialog or something. What is your task anyway ? I doubt you will increment an integer in your final code, if you give us more details then maybe we can help to optimize your code.

Thank you first!
I just want to select all the rows as fast as possible ,how to make it with QSqlTableModel?