Results 1 to 10 of 10

Thread: QSqlQuery and bad performance!

  1. #1
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlQuery and bad performance!

    hello every body;
    the QSqlQuery have a bad perofrmance when i use it with large tables.
    I have a table with more than 31964 record and i exec the following query
    SELECT field from table ORDER BY id.
    when i use QSqlQuery::next it takes time to move to the next record.
    and also when i use QSqlQuery::Last it takes longger time and increase the application used memory in RAM incredibly from 27 MB to 143 MB.
    is there a solution or i should use the sqlite headers to do this job?
    Thank you,

  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: QSqlQuery and bad performance!

    Well, you are retrieving 32k records into your application, it has to take time. Did you create an index on the `id` field in your table?
    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
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery and bad performance!

    yes i created an index but the database still slow.
    but i want to ask if i created an index will i still use the database through the qsqlquery and it handles the index automatically because i did not find any thing handles indexes?

  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: QSqlQuery and bad performance!

    Quote Originally Posted by mismael85 View Post
    yes i created an index but the database still slow.
    Can we see the schema of the table?

    but i want to ask if i created an index will i still use the database through the qsqlquery and it handles the index automatically because i did not find any thing handles indexes?
    It's the database engine that handles the index, not Qt. Which automatically means you'll get similar overhead when accessing the database from sqlite console.
    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
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery and bad performance!

    Can we see the schema of the table?
    CREATE TABLE `b11430`
    (
    `id` INT,
    `nass` TEXT,
    `part` INT,
    `page` INT
    )
    It's the database engine that handles the index, not Qt. Which automatically means you'll get similar overhead when accessing the database from sqlite console.
    so if i used the following query "SELECT * from table where id = 1" the qsqlquery will use the index to get the record???

  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: QSqlQuery and bad performance!

    Quote Originally Posted by mismael85 View Post
    CREATE TABLE `b11430`
    (
    `id` INT,
    `nass` TEXT,
    `part` INT,
    `page` INT
    )
    There is no index here.

    so if i used the following query "SELECT * from table where id = 1" the qsqlquery will use the index to get the record???
    If there was an index, yes. But it seems you didn't create one.
    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
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery and bad performance!

    i created an index but the query still slow and here are the schema
    Qt Code:
    1. CREATE TABLE b11430
    2. -- This table created by SQLite2008 Pro Enterprise Manager
    3. -- Osen Kusnadi - http://www.osenxpsuite.net
    4. -- Created date: 2010-09-24 19:47:33
    5. (
    6. id INTEGER,
    7. nass TEXT,
    8. part INTEGER,
    9. page INTEGER
    10. );
    11. CREATE UNIQUE INDEX idx ON b11430(id);
    To copy to clipboard, switch view to plain text mode 
    is there a solution?

  8. #8
    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: QSqlQuery and bad performance!

    Does it get any faster if you omit the "order by" clause?
    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.


  9. #9
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery and bad performance!

    No it didn't get any faster.
    do you think that if i used the sqlite directly it will be faster?

  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: QSqlQuery and bad performance!

    Quote Originally Posted by mismael85 View Post
    No it didn't get any faster.
    So by saying that it's slow, could you be more specific? How slow it is? Also, what happens if you use a database which has only about half the number of rows of your original db?

    do you think that if i used the sqlite directly it will be faster?
    I already answered that question.
    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. QSqlQuery
    By yasher in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2010, 14:25
  2. QSqlQuery in PyQt4
    By wirasto in forum Newbie
    Replies: 5
    Last Post: 11th January 2010, 08:25
  3. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 12:57
  4. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:35
  5. next() method of QSqlQuery
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 5th May 2007, 17:44

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.