Skip to main content
Doug Averch
Inspiring
Jul 14, 2023 11:28 AM UTC

SELECT Optimization

Now and then I must look at how long processes are running. Our web applications should be all running in under 500 milliseconds even though there are a lot of records in the database. An important datatable loading program on our web form was taking upwards of 2 seconds to load. I tested it on our development machine and with the client's data and the same number of indexes (7) and found our SELECT times were about the same. The PICKUP.DATE and ORIGIN.TERM are all indexed fields. Obviously, the SELECT optimizer does not work like I think it does.

Here is the test code abbreviated that runs in 643 milliseconds

     TERMINAL.NO = "059" ; BEGIN.DATE = "06/24/2023" ; END.DATE = "06/30/2023"
     LINE = 'SELECT MOVE.LOADS' 
     LINE := ' WITH PICKUP.DATE GE "':BEGIN.DATE:'"'       
     LINE := ' AND WITH PICKUP.DATE LE "':END.DATE:'"'          
     LINE := ' AND WITH ORIGIN.TERM = "':TERMINAL.NO:'"'
     EXECUTE LINE CAPTURING OUTPUT
     LOOP WHILE READNEXT ID
        READ LD.ITEM FROM MOVE.LOADS,ID ELSE CONTINUE
     REPEAT

Here is the 7 times faster code that runs in 89 milliseconds

     TERMINAL.NO = "059" ; BEGIN.DATE = "06/24/2023" ; END.DATE = "06/30/2023"
     LINE = 'SELECT MOVE.LOADS' 
     LINE := ' WITH PICKUP.DATE GE "':BEGIN.DATE:'"'       
     LINE := ' AND WITH PICKUP.DATE LE "':END.DATE:'"' 
     EXECUTE LINE CAPTURING OUTPUT 
     LOOP WHILE READNEXT ID
        READ LD.ITEM FROM MOVE.LOADS,ID ELSE CONTINUE
        IF LD.ITEM<7> # TERMINAL.NO THEN CONTINUE
     REPEAT

Posted: 07-14-2023 11:27



------------------------------
Doug Averch
Owner
U2 Logic
------------------------------

    11 replies

    Doug Averch
    Inspiring
    Aug 7, 2023 5:47 PM UTC

    Hi,

    LIST.INDEX In Dict, says it does not found the definition of the field into the dict file, it's not a problem to run the index. 

    do you use a remote dict via 'USING' or 'DF' file ? 

    are you happy with the optimization ? 



    ------------------------------
    Manu Fernandes
    ------------------------------

    The index was corrupted. When I deleted the index and re-created the index the problem was solved.

    It seems to me you are looking at too many esoteric solutions.

    I am a partner like you but I try and keep my code, my GUI, and my solutions lean and mean.

    Posted: 08-07-2023 17:46



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------

    Doug Averch Owner https://www.u2logic.com/