Qt World Summit: Submit your Presentation

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");
        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);
        if (query.exec(sql)) {
            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

  • Lifetime Qt Champion

    @cherevon What database are you accessing? Is this database under heavy load? Are you accessing it over the network?
    In general I would not store big BLOBS in a database, but for sure it should not be that slow.

  • 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.

  • Lifetime Qt Champion

    @cherevon I mean what database solution do you use? Is it SQLite, MySQL, ...?

  • This post is deleted!

  • @jsulm Informix

  • Lifetime Qt Champion


    Did you check that you are using similar connection parameters for both your Dephi and C++ application ?