Very slow QSqlQuery select
-
Good afternoon,
I`m trying to read BLOB from database but QSqlQuery reads it very slowly. The bigger the BLOB , longer the reading. For example, reading of BLOB 50Mb will take about 30 mins, for 200Mb it is 3-4 hours (after 3-4 hours application will throw bad_alloc and crash).
What am I doing wrong? It seems like QSqlQuery is always trying to reallocate new memory segment for BLOB, and at the end there is no free 200Mb block of memory.The code (driver QODBC, database Informix):
QSqlDatabase db = QSqlDatabase::addDatabase(SettingsDialog::analysisDatabase().driverName, "test_db"); db.setHostName(SettingsDialog::analysisDatabase().hostName); db.setDatabaseName(SettingsDialog::analysisDatabase().databaseName); db.setPort(SettingsDialog::analysisDatabase().port); db.setUserName(SettingsDialog::analysisDatabase().username); db.setPassword(SettingsDialog::analysisDatabase().password); if (!db.open()) qDebug() << QObject::tr("Не удалось установить соединение с БД:\n") << db.lastError().text(); QString sql = "SELECT t.data FROM blob_data t WHERE id = 773788"; QSqlQuery query(db); query.setForwardOnly(true); if (query.exec(sql)) { query.next(); qDebug() << "NEXT DONE"; qDebug() << "SIZE = " << query.value(0).toByteArray().size(); } else qDebug() << query.lastError().text();
Program reaches the line
qDebug() << "NEXT DONE";
amost immediatelly, but it takes a lot of time to reach the next line
-
Good afternoon,
I`m trying to read BLOB from database but QSqlQuery reads it very slowly. The bigger the BLOB , longer the reading. For example, reading of BLOB 50Mb will take about 30 mins, for 200Mb it is 3-4 hours (after 3-4 hours application will throw bad_alloc and crash).
What am I doing wrong? It seems like QSqlQuery is always trying to reallocate new memory segment for BLOB, and at the end there is no free 200Mb block of memory.The code (driver QODBC, database Informix):
QSqlDatabase db = QSqlDatabase::addDatabase(SettingsDialog::analysisDatabase().driverName, "test_db"); db.setHostName(SettingsDialog::analysisDatabase().hostName); db.setDatabaseName(SettingsDialog::analysisDatabase().databaseName); db.setPort(SettingsDialog::analysisDatabase().port); db.setUserName(SettingsDialog::analysisDatabase().username); db.setPassword(SettingsDialog::analysisDatabase().password); if (!db.open()) qDebug() << QObject::tr("Не удалось установить соединение с БД:\n") << db.lastError().text(); QString sql = "SELECT t.data FROM blob_data t WHERE id = 773788"; QSqlQuery query(db); query.setForwardOnly(true); if (query.exec(sql)) { query.next(); qDebug() << "NEXT DONE"; qDebug() << "SIZE = " << query.value(0).toByteArray().size(); } else qDebug() << query.lastError().text();
Program reaches the line
qDebug() << "NEXT DONE";
amost immediatelly, but it takes a lot of time to reach the next line
-
It is test database, there are only 83 sessions right now. I have tried to select 200Mb blob from Delphi and it took couple of minutes.
It was not my decision to store such huge BLOBs in database. -
Hi,
Did you check that you are using similar connection parameters for both your Dephi and C++ application ?