Results 1 to 12 of 12

Thread: QT SQL advice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT SQL advice

    I just remembered the "Group By" sql argument.
    so I think I can just do:
    SELECT SUM(value) FROM database WHERE group=x AND (range > y AND range < z) GROUP BY id
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT SQL advice

    Quote Originally Posted by enricong View Post
    I just remembered the "Group By" sql argument.
    so I think I can just do:
    SELECT SUM(value) FROM database WHERE group=x AND (range > y AND range < z) GROUP BY id
    Of course but I think that it should looks like :
    Qt Code:
    1. SELECT id, SUM(value) FROM database WHERE group=x AND (range > y AND range < z) GROUP BY id
    To copy to clipboard, switch view to plain text mode 
    Without it you will not know what is the id of the sum.

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

    Default Re: QT SQL advice

    Could you please take your queries, launch an sqlite console against your database and execute each query prepending it with "EXPLAIN QUERY PLAN"? E.g. modify a "SELECT SUM(value) FROM database WHERE group=x AND (range > y AND range < z) GROUP BY id" to become "EXPLAIN QUERY PLAN SELECT SUM(value) FROM database WHERE group=x AND (range > y AND range < z) GROUP BY id". Paste the results here, please.
    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.


  4. #4
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT SQL advice

    Yes, I forgot the id when I typed up that message

    I get the following with explain:
    SCAN TABLE database
    USE TEMP B-TREE FOR GROUP BY


    This now runs in about 80ms so about 400X faster.
    Typically, I need to do this about 32 times. Over all the user is waiting about 10-15 seconds so its slowing down elsewhere.
    Ideally, I'd like an instant response but I think it's acceptable right now.
    Last edited by enricong; 5th November 2014 at 02:07.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

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

    Default Re: QT SQL advice

    If you get a table scan then you are missing an index on the field from WHERE clause (likely 'group' column in your case).
    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.


  6. #6
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT SQL advice

    I had a bug where I was creating the index. now its about 50% faster down to about 30-40ms from 80.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

Similar Threads

  1. need advice on gui thread
    By dpn in forum Qt Programming
    Replies: 8
    Last Post: 16th September 2013, 09:16
  2. General Advice
    By KillGabio in forum Newbie
    Replies: 6
    Last Post: 2nd February 2012, 03:15
  3. XML advice
    By stefan in forum Newbie
    Replies: 1
    Last Post: 24th December 2011, 14:12
  4. Advice for an Application
    By salmanmanekia in forum Newbie
    Replies: 1
    Last Post: 19th April 2010, 12:06
  5. Need Advice: Best IDE for Mac OSX
    By JimDaniel in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2008, 23:14

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
  •  
Qt is a trademark of The Qt Company.