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

fast way to query data?

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

    fast way to query data?

    I am not sure if this is the best way, but I have used an array for some of my routine to check for existance of record, in such away, i have to use "index" and filter at the same time. My databse can be as big as 50,000 records.
    it is getting very slow to perform basic query.

    I use the following:
    DIM inputp as p
    DIM NRECS AS N

    INPUTP=table.open("REQUEST_HEADER",file_ro_shared)
    INPUTP.INDEX_PRIMARY_PUT("repair_job")

    query.description="GET LIST OF ALL REPAIR JOB"
    query.order="REQ_HEADER"
    Query.filter="REP_BY_ID=ALLTRIM(VAR-"CIDD)"
    ' HERE I SPECIFICALLY WANT RECORD BELONG TO EQUAL TO VAR-"CIDD, USUALLY RESULTING TO AOUT 10 TO 20 RECORDS, OUT OF THE 50,000
    query.options="M" 'force alpha to generate a new query list

    ndx=inputp.query_create()
    nrecs=ndx.records_get()

    DIM CAT_ARRAY(NRECS) AS C
    DIM I AS N
    DIM J AS N

    J=NRECS

    INPUTP.CLOSE()

    SELECT
    CASE J"0
    GOTO AA
    CASE J=0
    GOTO NO_ACTION
    END
    CASE J"0
    GOTO NO_ACTION
    END

    END SELECT
    END

    AA:
    BROWSE1.DISABLE()
    HIDE_BANNER.PUSH()
    sys_send_keys("{F5}")
    range.flags = RANGE_INDEX .or. RANGE_FILTER .or. RANGE_DESCENDING
    range.index_handle = index_handle_get(db_current(), "REPAIR_JOB")
    range.filter = "REP_BY_ID = ALLTRIM(VAR-"CIDD) " '.AND. REQ_STATUS = 'ASSIGN'"
    range_add(db_current(), " ", " ")

    SLEEP(1/2)
    sys_send_keys("{F5}")
    BANNER.TEXT = ALLTRIM(STR(J))+" RECORDS FOUND"

    SHOW_BANNER.PUSH()
    CHECK.PUSH()

    END

    NO_ACTION:
    SHOW_BANNER.PUSH()
    CHECK.PUSH()
    END

    ALL ABOVE WORK VERY WELL, EXCEPT I SUSPECT THE ARRAY ROUTINE TEND TO BE SLOW, AS IT GOES THROUGH THE ENTIRE 50,000 AND THEN THE RANGE INSIDE THE INDEX DOES THIS AGAIN.

    THE REAL REASON TO MAKING SURE THAT THE FILTER RECORD EXIST, BEFORE ATTEMPTING TO PERFORM THE RANGE INDEX FILTER,
    ELSE THIS WOULD SLOW DOWN DO DO FUNNY THING TO MY APPLICATION, IN SUCH AWAY THAT EMPTY RECORD FORCE ALPHA TO SEARCH FOREVER???

    YOUR ASSISTATNCE IS GREATLY APPRECIATED

    KEN JIA

    #2
    RE: fast way to query data?

    Ken,

    I've read your script several times and still don't understand your question.

    The array you declare is never populated so it's hard for me to see that it's slowing things down.

    The script runs two separate queries. I'm not sure why.

    If you simply need to know if a particular record is present you can check using the exist() function instead of running a query against the entire table simply to find out if the number of records in the query list is greater than zero. Maybe exist() will speed things up for you.

    -- tom

    p.s. Unless you're visually impaired, using all cap letters in your messages is harder to read, and is often interpreted as SHOUTING.

    Comment


      #3
      RE: fast way to query data?

      It appears that your browse is the same table you are querying. If so:

      t=table.get("request_header")
      query.filter="rep_by_id=var-"cidd"
      query.options=""
      query.order="req_header"
      idx=t.query_create()
      if idx.records_get() " 0
      browse1.fetch_first()
      else
      idx.drop()
      ui_msg_box("Sorry","No records found.")
      end
      end if
      Cole Custom Programming - Terrell, Texas
      972 524 8714
      [email protected]

      ____________________
      "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

      Comment


        #4
        RE: fast way to query data?

        Martin,

        Thank you for your reply, the idea of using "Range" and "Index" in place of the query that i often use.
        Is to achieve a speedy result.

        Such performance had given me excellent result.
        However, I dicovered situation, when "no record" actually found within the range/index run. The following events usually disaster and seems like going forever to find it.
        Thus brought me the idea to first check for existance of such records before attempting to perform range index.

        I use "array" a great deal, it is slow, but never failed on me and always get me, versus others seems to have leakage, as in the multi user case, when new record added in real time by other user do not seems to get included, while the array was happy to included new records for me.

        So, I was stupid enough to use array and in hope that it works everytime, but it gets really slow for sure

        Comment


          #5
          RE: fast way to query data?

          Kenn, if you have the field indexed that you are searching on (basing the query on,) the code I gave you is as fast as it gets - it uses LQO - Lightening Query Optimization. If there are no records, it tells you so.
          Cole Custom Programming - Terrell, Texas
          972 524 8714
          [email protected]

          ____________________
          "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

          Comment


            #6
            RE: fast way to query data?

            Hi Martin.

            Thanks you for the reply, just have the chance to tackle these "speed" requirment.

            Such codes work well, but suppooses that the "filter"
            is far more complecated, such as:

            ******************************************
            query.filter="rep_by_id=var-"cidd .and. req_type "" 'rx' .and. req_type "" 'wo' "

            *******************************************



            t=table.get("request_header")
            query.filter="rep_by_id=var-"cidd .and. req_type "" 'rx' .and. req_type "" 'wo' "
            query.options=""
            query.order="req_header"
            idx=t.query_create()
            if idx.records_get() " 0
            browse1.fetch_first()
            else
            idx.drop()
            ui_msg_box("Sorry","No records found.")
            end
            end if

            Question One:

            If i would like to take advantage of the Ligthning speed query, do I need to create an INDEX that exactly matching the query filter? This one really confused me.

            Question Two:

            If this is the ultimate speed we can get out, then in the future when the file grow toward 80,000 records. i am going to have a problem with longer delay.
            Currently I am on 33,000 records and it is acceptable,
            but in fear of future slow processing.

            Is there a way to insert "Index" routine for example right from the beginning say,We have an index on "rep_by_id" and just fetch for "rep_by_id = var-"cidd"

            Then apply Query after indexing to look for Req_type = "Wo" etc.

            I appreciate your comment on my questions above,.

            Thanks

            Ken Tjia

            Comment


              #7
              RE: fast way to query data?

              I will admit that I only vaguely understand the complexities of lightening query optimization - but as I understand it, if you have an index on each of the fields that are included in the query that it will use LQO.

              but one thing is for sure, querying a table that is already open and part of your form's set will be quicker than the approach you were taking.

              I would also suggest that you search the documentation and the phorum for info on LQO.

              But remember that speed is also an aspect of your LAN, how many users are on, etc.

              good luck
              Cole Custom Programming - Terrell, Texas
              972 524 8714
              [email protected]

              ____________________
              "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

              Comment


                #8
                RE: fast way to query data?

                if you have an index on the field, as I understand it, the query will use the index (which is what LQO is, as I understand it,) so there would be no speed advantage using an index.
                Cole Custom Programming - Terrell, Texas
                972 524 8714
                [email protected]

                ____________________
                "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                Comment


                  #9
                  RE: fast way to query data?

                  I would create an index on the rep_by_id field being careful to define it the same way you pass your variable to the query filter expression. -- tom

                  Comment


                    #10
                    RE: fast way to query data?

                    HI Tom,

                    Are you suggesting, to include all those filter(s) into the actual index, I have done some in this fashion.
                    But do not know, if "lightning" actually striking hi.

                    I truly do not know what is being considered "Lightning Query" versus regular. I have a feeling I am already reach the ultimate and is in lighting.

                    Bill suggested that I try using " in between", I also believe as you described, just create an index sorting for
                    "Rep_by_id" and then hopefully the filter will pick the rest up and piggy back on the lightning based on this single index.

                    I am wondering if I apply "Range/Index" isn't this suppossed to be faster the lightning? I have done few test, but ran into trouble when there is no record on file, the fetching or finding record just keep going and going in some cases.

                    Ken Tjia

                    Comment


                      #11
                      RE: fast way to query data?

                      "pre"
                      Lightning Query Optimization

                      Lightning Query Optimization is a feature that Alpha Five activates to increase the speed at which queries are run. By using information contained in the indexes you have created, Alpha Five can dramatically speed up queries.

                      To take advantage of this time-saving feature, both the query you design and the pre-existing indexes must be compatible with Lightning Query Optimization. The following sections explain this compatibility.

                      Building Compatible Indexes

                      For Lightning Query Optimization to use a pre-existing index, the index must:

                      Use at least one of the same fields used in the query.

                      The data type of the data in the index key must match the data type of the field you are searching.

                      Use an order expression that contains either a single field, or two fields concatenated using the plus operator (+), such as in the expression Lname+Fname.

                      Not use the Unique Only option

                      Not use a filter expression

                      Building Compatible Queries

                      For a Query to work with Lightning Query Optimization, at least one of the condition expressions in the query must compare a field used in one of your indexes with a constant. For example, State = "MA", is suitable, provided you have a pre-existing index which sorts records using the State field.

                      The condition expression must use operators that are compatible with Lightning Query Optimization. These include:

                      Equals (=)

                      Exactly equals (==)

                      Greater than or equal to ("=)

                      Greater than (")

                      Less than or equal to ("=)

                      Less than (")

                      Not equal to ("")

                      BETWEEN(..)

                      SMATCH() - see note below

                      Wildcards (* and ?) - see note below

                      .NOT.

                      .AND.

                      .OR.

                      Note: The SMATCH() function and the wildcards * and ? can only be used with Lightning Query Optimization if they appear at the end of the expression. For example, a search for McC* can be optimized since the wildcard operator appears at the end, while a search for *stein cannot be optimized, since the wildcard operator begins at the beginning.

                      Partial Compatibility

                      In some cases, only part of your query�s selection expression can be used with Lightning Query Optimization. In this case, Alpha Five applies the optimization algorithm to the compatible part, and uses Alpha Five�s standard query algorithm to evaluate the rest.

                      For example, you have a table of customers for which you have created an index that sorts records by the field City. You then create a query which uses the following selection expression:

                      (CITY = "BOSTON").AND.("Commonwealth" $ ADDRESS1)


                      Because the second half of the expression uses an operator that is not compatible with Lightning Query Optimization and a field which is not used in a pre-existing index (ADDRESS1), Alpha Five applies Lightning Query Optimization to only the first part of the expression.

                      Furthermore, in cases where the selection expression evaluates to TRUE for most of the records in the table or set, Alpha Five will analyze the query and might determine that the standard query algorithm is more suitable. In this case, Lightning Query Optimization is not used.

                      See Also

                      SMATCH(), BETWEEN()

                      "/pre"
                      Cole Custom Programming - Terrell, Texas
                      972 524 8714
                      [email protected]

                      ____________________
                      "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                      Comment

                      Working...
                      X