Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

MYSQL Query Performance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MYSQL Query Performance

    I am working on optimizing some queries.

    The following MYSQL query takes approximately 4.78 seconds in Navicat BUT 8.82 seconds in Alpha's SQL Query Genie. This speed difference is noticeable in all queries I have checked, particularly noticeable in longer running queries. What could account for this?

    Have others noticed this?

    SELECT appointments.chargeno, appointments.date, appointments.pracid, appointments.idnumber, appointments.prov, appointments.billprov, appointments.svcode, appointments.fee, appointments.units, appointments.i1exp, appointments.ptexp, appointments.dxcode, appointments.i1insconame, appointments.i2insconame, appointments.i3insconame, appointments.respname, appointments.charge, appointments.progno, appointments.i1bdate, appointments.i2bdate, appointments.i3bdate, appointments.ptbdate, patients.FULLNAME, patients.IDCOMBO, patients.REFERRER, patients.PTTYPE, left(appointments.i1insconame, 6) AS i1name, left(appointments.respname, 6) AS rname, left(patients.fullname, 12) AS fname, left(patients.referrer, 6) AS refname
    FROM appointments appointments
    INNER JOIN patients patients
    ON appointments.idnumber = patients.IDNUMBER
    WHERE appointments.charge = 'Y' AND appointments.date BETWEEN '2018-01-01' AND '2018-12-31' AND appointments.pracid = 'somepractice' AND appointments.prov BETWEEN 'aa' AND 'zz'
    ORDER BY appointments.date, patients.FULLNAME, appointments.prov
    Gary S. Traub, Ph.D.


    #2
    Re: MYSQL Query Performance

    Maybe it's the difference between portable SQL and native SQL within Alpha. There is a checkbox usually around somewhere to check off that your query is native or not. Under portable SQL there is additional overhead as Alpha needs to evaluate your query before executing it. When it's native there is no overhead. .....at least that is my general understanding.

    https://documentation.alphasoftware....able%20SQL.xml
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant​​

    Comment


      #3
      Re: MYSQL Query Performance

      I know I have seen that checkbox somewhere but I cannot find it.

      Hard to imagine though that this would take an additional 4 seconds - but, if I can find that checkbox I will try it.

      Thanks Mike!
      Gary S. Traub, Ph.D.

      Comment


        #4
        Re: MYSQL Query Performance

        If you run the Query in MySQL Workbench, does it run faster than Navicat? I'd guess the speed of the query decreases the closer you get to MySQL.

        Workbench will probably be fastest.
        Navicat probably has some work to do in order to get to MySQL but I'd bet Navicat is fairly well optimized since talking to databases is their business.
        Alpha is probably not that well optimized and probably does a lot more work before and after getting to the database. There's probably a lot more overhead in Alpha.

        If you run the query two or three times, are your results the same within Navicat and Alpha?

        Comment


          #5
          Re: MYSQL Query Performance

          Hi David,

          I ran the query several times in each scenario and here are the results:

          Workbench: 3 - 3.1"

          Navicat: 3.2-3.4"

          Alpha SQL Query Genie: 5.5-6"

          Same query but within an alpha grid: 7.5-8"

          By the way, the result set has 17,411 records and the appointments table has indexes on charge,date,pracid, and prov
          Gary S. Traub, Ph.D.

          Comment


            #6
            Re: MYSQL Query Performance

            Your test is actually testing much more than query speed. In all instances, the end product is a display of the result set, so the result set must be converted into some format to show the data. This may be a simple grid type display in Navicat or Workbench, or a far more complex display such as a web grid.

            Also, when you are testing in Navicat or Workbench, you already have a connection open, so the time to make the connection factors into the total time

            As test, I built a query with a complex INNER JOIN that returns just a count of records (1 value). This was tested on a remote data server not on my local network. The query did not have a WHERE clause and was run multiple times to get a repeatable baseline.
            Code:
            SELECT count(*) as kount from .......
            Running in Navicat, the query took .062 seconds to return a count of 196,074

            Running in xbasic and just timing the query and the code to get the kount using a high accuracy timer took .059 seconds to return 196,074
            Code:
            dim cn as sql::Connection
            dim SQL as c
            sql = <<%txt%
            SELECT count(*) as kount FROM ...
            %txt%
            dim kounter as n
            if cn.open("::name::PEP")
            	dim t1 as util::timer
            	cn.execute(sql)
            	kounter = cn.ResultSet.data("kount")
            	t1.stop()
            	cn.close()
            end if 
            ui_msg_box(""+kounter,str(t1.ElapsedMicroseconds*.000001,12,6))
            The xbasic method was tested with portable sql on and off (cn.PortableSQLEnabled = .F.) with no measurable difference in speed. Adding a WHERE clause slowed each query almost exactly the same amount of time.

            However, if the timer included the time to open and close the connection, the same query in Alpha Anywhere took .291 seconds, indicating significant time was expended just making a connection to the remote server. Again, portable on / off made no difference.

            Another test just did SELECT * and the xbasic just "walked" the resultSet to get a count
            Code:
            	while cn.ResultSet.nextRow()
            		kounter = kounter + 1
            	end while
            Navicat ran SELECT * and displayed the data in 16 - 30 seconds
            The xbasic ran in 18- 40 seconds to calculate the kount

            The test was run many times, and the variation between queries in a single environment was greater than the difference between the fastest runs from each environment.

            Another test changed the SELECT * by replacing the * with just 1 column.

            Navicat now showed 196,074 rows in 12.8 - 13.5 seconds, and the xbasic walked the result set and returned the same data stream (list of values in the columns) in 14.2 to 14.3 seconds

            When you run in a grid web component, you add another element as the grid runs 2 queries. The first gets a count of records, and the second gets the result set for the first number of rows in the grid. It also has to build the HTML to show the rows. In many grids, getting the count has a high overhead, especially with WHERE clauses with multiple conditions.

            The conclusions:
            • The actual query time is effectively the same in all environments
            • Portable SQL on / off has no measurable speed impact
            • Connection speed can be a significant factor
            • Most of the overall time to display is getting the result set and formatting it into some useful display layout
            • The time to format the result set (and run the query) varied based on the number of columns. Returning more columns such as with SELECT(*) was significantly slower.
            • Web grid components do 2 queries, which creates a longer total time

            All of this will vary considerably from one database to another and one query to another.

            Comment


              #7
              Re: MYSQL Query Performance

              "By the way, the result set has 17,411 records and the appointments table has indexes on charge,date,pracid, and prov "
              You should have indexes on all the fields in the where clause.
              Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

              Comment


                #8
                Re: MYSQL Query Performance

                Jerry,

                Thank you very much for the detailed explanation. Makes a lot of sense. BTW, though, would it then make sense to keep the sql connection open, if that is even possible?

                Frank,

                I do that usually, but in this case, for whatever reason, adding the index on prov actually slowed the navicat time by approx 1 second. Doesnt make sense I know but that is what happened. I will try it again.
                Gary S. Traub, Ph.D.

                Comment


                  #9
                  Re: MYSQL Query Performance

                  Originally posted by drgarytraub View Post
                  Hi David,

                  I ran the query several times in each scenario and here are the results:

                  Workbench: 3 - 3.1"

                  Navicat: 3.2-3.4"

                  Alpha SQL Query Genie: 5.5-6"

                  Same query but within an alpha grid: 7.5-8"

                  By the way, the result set has 17,411 records and the appointments table has indexes on charge,date,pracid, and prov
                  Those times fit exactly what I was expecting. The Grid is just old tech... so ignoring it's inefficiencies, the other times seem appropriate given that there is overhead within Alpha that you don't have with Workbench and Navicat. Do one more test with XBasic because there you get open the connection and then run the query... so you get to time just the query.

                  Comment


                    #10
                    Re: MYSQL Query Performance

                    Hi David,

                    I ran the script in an an a5w page. Opening the connection is very quick, much less than a second. The whole process including opening the connection and running the query takes approximately 3 seconds, just like workbench and navicat.

                    Given these observations, it seems that there is something about the query builder that slows things down (and the grid but I would expect that), and not alpha itself. Performance is actually quite similar. What are your thoughts on this?
                    Gary S. Traub, Ph.D.

                    Comment


                      #11
                      Re: MYSQL Query Performance

                      Are your times in the query builder the same if you run the same query twice? Is overhead diminished in the query builder with subsequent runs? Without getting Alpha to tell you exactly the query builder is doing, it'd be tough to find out what it's doing under the hood.

                      Overall, is the query builder something you need to be concerned about?

                      Comment


                        #12
                        Re: MYSQL Query Performance

                        No, not really.
                        Gary S. Traub, Ph.D.

                        Comment


                          #13
                          Re: MYSQL Query Performance

                          So what would be a expected window of time for:
                          1)Rendering a list based on a sql query
                          2)Performing a crud call back, and refreshing the list
                          My times are as high as 30 seconds. Tried many different connections doesn't significantly change this. My queries are joins, but I am only testing with a few hundred records.
                          Anything over 10 seconds is not practical in the mobile world. Anyone conquer this?

                          Comment


                            #14
                            Re: MYSQL Query Performance

                            That would depend on the actual query, number of fields, indexes, and then what else is going on in the grid or ux.

                            I have found that I can get performance time down to approx 3 or 4 seconds max (from complex queries with lots of data), and usually less
                            Gary S. Traub, Ph.D.

                            Comment


                              #15
                              Re: MYSQL Query Performance

                              A way to monitor the break down of how much time each task/event consumes would be handy, to just say it depends on this or that leaves only trial and (mostly) error. Maybe ultimately the answer is a further injection of Node into the mix?

                              Comment

                              Working...
                              X