Results 1 to 14 of 14

Thread: QSql*Model are very slow

  1. #1
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSql*Model are very slow

    Hi all.
    I have rather big database (20000 records with 17 columns each).
    I use QSqlTableModel to display that base. However, when i try to scroll using scroll bar, my treeView lags (for about 1-2 seconds). Seems it lags when first time calling data() method to retrieve data from database. After fields are cached to view, i can scroll without any lags. How can i fix lagging for first call or at least precache data to view?
    P.S.: same lags when using QueryModel
    P.P.S.: also i have lag when model does fetchMore(), but it can be fixed by fetching all model.

  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: QSql*Model are very slow

    The only viable solution is to create a custom model that will fetch rows manually using a worker thread.
    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. #3
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    Well, even after fetching model i have lags when accessing elements for the first time. So thread on fetching will not help i think.

  4. #4
    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: QSql*Model are very slow

    It will help.
    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.


  5. #5
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    Well, after some tests it appears that loop
    Qt Code:
    1. while (model->canFetchMore())
    2. model->fetchMore();
    To copy to clipboard, switch view to plain text mode 
    takes very little time.
    However, showing treeview with model that is already fetched takes about 7-10 seconds. So, threading fetching won't help me, isn't it?

  6. #6
    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: QSql*Model are very slow

    It will help. If you do it wisely, of course.
    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.


  7. #7
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: QSql*Model are very slow

    why are you using a qtreeview instead of a qtableview?

    anyway...
    I don't understand your "lag"....

    Just right now I'm working with a query with 15000 records... (qsqlquerymodel + qtableview) and it's pretty fast.

    I think that you have another problem.

    (¿are you using a subclassed view or model?? )

  8. #8
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    The problem was in QTreeView. Using QTableView has no problems (lags are very little on sorting, about 0.3 sec, which is acceptable and no lags on scrolling). Thanks all.

  9. #9
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    Not to create new thread.
    Is it correct that my own table model will always be faster than sql model when showing all data/sorting it?
    And what about filtering with ProxyModel - will it be faster or slower than filtering with sql query?

  10. #10
    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: QSql*Model are very slow

    It depends. If the database is not optimized in some special way for sorting in a particular order, doing it locally will probably be faster.
    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.


  11. #11
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    It is optimised. I choose myself the format of database. I only need to take decicion - to use sql database and classes for it or implement everything myself (storing in memory, sorting, filtering, editing).

  12. #12
    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: QSql*Model are very slow

    Quote Originally Posted by ABBAPOH View Post
    It is optimised.
    And based on what do you say that? You can't possibly know that upfront unless you implemented the database engine yourself.
    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.


  13. #13
    Join Date
    Aug 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSql*Model are very slow

    I meant i created indexes in sql table and not try to sort not indexed columns))
    however yes, sqlite driver implementation can be rather slow, however i hope it is not.

    I tested sorting methods with different model implementations (SqlTableModel, SqlQueryModel + Proxy, custom model with data in memory + Proxy for sorting). Seems true, however i thought sql will be faster
    Sorting... time elapsed: 150 ms - OwnModel + Proxy model
    Sorting... time elapsed: 60 ms - OwnModel + Proxy model reverse
    Sorting... time elapsed: 421 ms - SqlTableModel + fetchall
    Sorting... time elapsed: 391 ms - SqlTableModel reverse + fetchall
    Sorting... time elapsed: 1076 ms - SqlTableModel not indexed column + fetchall
    Sorting... time elapsed: 236 ms - SqlQueryModel fetched + Proxy model
    Sorting... time elapsed: 99 ms - reverse

  14. #14
    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: QSql*Model are very slow

    Sql might be faster only if you request data in the order that it is stored in the engine. That's what I meant by being optimized for sorting in some particular order.
    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.


Similar Threads

  1. Q Table View + Relational Model VERY SLOW
    By arimaniac in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 17:43
  2. Using auto_increment in QSql
    By SykeS in forum Newbie
    Replies: 3
    Last Post: 21st May 2010, 08:13
  3. QSql Model-View: How to keep view in sync with model
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 00:31
  4. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 19:14
  5. [model/view] slow refresh on big table
    By lauranger in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2008, 22:40

Tags for this Thread

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.