Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Very slow QSqlQuery select
Forum Update on Monday, May 27th 2025

Very slow QSqlQuery select

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqlquerybadallocout of memoryblobqodbc
7 Posts 3 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cherevon
    wrote on last edited by A Former User
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • C cherevon

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cherevon
        wrote on last edited by
        #3

        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.

        jsulmJ 1 Reply Last reply
        0
        • C cherevon

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • C Offline
            C Offline
            cherevon
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • jsulmJ jsulm

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

              C Offline
              C Offline
              cherevon
              wrote on last edited by
              #6

              @jsulm Informix

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

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

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved