4 Replies Latest reply: Jun 11, 2013 2:18 AM by Peyman Azimabadi RSS

    Peek OR Lookup?

    Peyman Azimabadi

      Hi all,

      i have a table and i need to read data from this table in my script, record by record and do some action.

      To reed data from this table i can use "peek" in a for loop, or use "Lookup" with a key field.

      Becuse my table hat too many recods, it's really slow.

       

      1. Any body has an idea which one is faster? PEEK or LOOKUP?

       

      2. Or somebody knows a better way to do that?

       

      p.s. i have tried to use join or mapping but in this case it's not the answer. i know such problems can be solved without use of record by record loops, but here it's not the case. i need exactly what i explained.

       

      Best Regards

      Peyman

        • Re: Peek OR Lookup?
          Abhijit Bansode

          You can write the actions you need to perform, in the preceeding load section.

          Also, can make use of ItrNo() with while loop to iterate each record.

           

          Regards,

          Abhijit

            • Re: Peek OR Lookup?
              Peyman Azimabadi

              Hi Abhijit,

              thanx for your answer.

              You are right, there are few ways that i can do the job.

              But my problem is time. i need to repeat the action for some 200,000 records and at the moment it takes 80 hours.

              My question is about performance and need to find out which methods runs faster.

               

              Best Regards

              Peyman

                • Re: Peek OR Lookup?
                  Abhijit Bansode

                  If possible, can you share/explain some more details on excatly what you want do in action part.

                   

                  However lookup and peek functions serves the similar function but used on different conditions:

                   

                  Lookup:

                  lookup is a mapping or a translation function: You could for instance have a product ID and you want to translate that into a specific product attribute. In other words – you never expect more than one value for the specific product ID. If there are several possible values in the lookup table, the lookup function will just take the first one found.If you do expect several values for each of the input values, you should not use a lookup function to solve the problem.

                  Lookup ('ProductCategory', 'ProductID', ProductID, 'ProductTable')

                  in above, Lookup() function will return the value of the field ProductCategory (first parameter) in the table ProductTable (fourth parameter) from the record where the field ProductID (second parameter) has the same value as the field ProductID in the order data table (third parameter).

                   

                  Peek:

                  The Peek() function is similar to the Lookup() function, but instead of addressing the other table using a field value, the peek function needs a row number.

                  Peek ('ProductCategory', -1, 'ProductTable')

                  Although the Peek() function is a lookup function, its use for solving similar problems is limited since you need the row number to get the desired value, and this is rarely the case.

                   

                  Hope it helps...

                   

                  Regards,

                  Abhijit

                    • Re: Peek OR Lookup?
                      Peyman Azimabadi

                      Hi Abhijit,

                      i know how the two methods work, i produce a key with RowNo() in my load and i can use it in a loop to fetch data record by record using "Lookup" or i can go over a loop from1 to NoOfRows('myTable').

                      my question is about performance. i need the fastest method that one can read data from a table in script.

                      no doubt QV needs to search and find records in both "Lookup" and "Peek". which runs faster?

                      Or is there any better method that can i do it faster?

                       

                      Best Regards

                      Peyman