Results 1 to 2 of 2

Thread: QSqlTableModel select() / submitAll() very slow

  1. #1
    Join Date
    Aug 2013
    Location
    Campina, Romania
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlTableModel select() / submitAll() very slow

    Hi guys,

    I have a rather large table (over 3 million records) that has to be accessed remotely. It's part of an invoice and payment application.
    I use QSqlTableModel as model. For editing the records, I use DataWidgetMapper, and I also have a QTableView elsewhere for viewing all the records for a customer.

    The first issue: pModel->select() is extremely slow - if I load the table locally it freezes the GUI 20 seconds, but if I load the table remotely, it freezes the application for good.
    The edit strategy is OnManualSubmit.

    The second issue: when adding a new record I tried 2 ways:
    a) pModel->insertRecord(-1, &record) followed by pModel->submitAll(), because the record must be viewed immediately. Those operations take some time when appealed locally and almost 30 seconds when accessed remotely;
    b) QSqlQuery ->exec("Insert into table ... values (...)) followed by pModel->select() - this brings me to the first issue, the application is blocked when accessed remotely.

    Also, I've tried to surround insertRecord() / submitAll(), respectively pQuery->exec() / pModel->select() by transaction() / commit(), with no improvements.

    Is there any possible solution for those issues? The application must be very responsive, with no delays when adding or deleting a row.
    I'm using Qt 4.8.4 and PostgreSQL 9.2.4.

    Thank You in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlTableModel select() / submitAll() very slow

    You have to transfer only those rows that you need and those that have changed. I don't think you need to view all 3M rows at once, so teaching your model to use canFetchMore() and fetchMore() can give a rather significant improvement. The same goes with submiting changes to the remote model. Relying on QSqlTableModel that uses a generic SQL driver is not a good idea as different SQL drivers have different capabilities and can take a rather inefficient code path.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    mihaibu (4th August 2013)

Similar Threads

  1. submitALL, QSqlTableModel and QTableView
    By scott_hollen in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2011, 09:38
  2. Replies: 0
    Last Post: 8th July 2011, 12:28
  3. QSqlTableModel::select()
    By vladozar in forum Qt Programming
    Replies: 4
    Last Post: 29th April 2009, 17:51
  4. QSqlTableModel->submitAll()
    By maxel in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2008, 08:30
  5. QSqlTableModel submitAll access query
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 27th April 2007, 08:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.