READ vs SQL SELECT, A Quick Performance Test

READ vs SQL SELECT

With no doubt, SQL is the advanced and efficient way for operations (Read, Write, Update or Delete) on Tables (or Files) on IBM i. 

With the use of Embedded SQL programming (SQLRPGLE), it is efficient to use SELECT to read the data from a table compared to using READ. 

Here is the result from a quick performance test between READ and SELECT to read One million records from a table.

Below are few points to consider about the test before we see the results. 
  • Created Physical File (using DDS) for the use in RPGLE with READ Operation. 
  • Created Table from SQL Session for the use in SQLRPGLE with SQL SELECT Operation.
  • Both the files has same number of fields, length and same number of records.
  • Both Programs are called from a new Interactive Session immediately after login.
Let's see the code used to create File/Table and Program. 

Physical File (PPTESTFILE):


Table (PTESTTABL):


Inserted one million records (same data) to both the files. And, Table is occupying less size compared to Physical File

Size of Physical File:

Record Length - 40, Total Records - 1,000,000, Size of Physical File - 64,008,192 Bytes


Size of Table:

Record Length - 40, Total Records - 1,000,000, Size of Physical File - 41,951,232 Bytes





Below is the code used for both READ & SELECT. 

for READ (PPREAD):


for SELECT (PPSQL):




Now, coming to the Results, Program with SELECT operation has run in in 30% (approx) less time than with READ (70% of READ).

Program with READ took about 9 seconds to read one million records. 


Program with SELECT took about 6 seconds to read one million records. 



So, It is efficient both in terms of Processing time and Storage to use SQL in place of READ wherever possible. 

Again, Is there a better way of doing this with SQL? Yes, Instead of Fetching one record every time, We can Fetch multiple records into Data Structure and loop through Data Structure for accessing the data. 

This has run > 60% faster than SQL SELECT example listed above. Click Here to see more details on this test.

Comments

  1. This is not a valid performance comparison. The RPG READ example reads the table by key, whereas the SQL SELECT example doesn't.

    You might try adding an ORDER BY clause to the SQL SELECT, or change the RPG READ to use BLOCK mode. Then show us the results.

    ReplyDelete
    Replies
    1. Hi Nathan,

      Thanks for Pointing. I have added ORDER BY clause to SQL SELECT and ran the test once again. Results are exactly same as it was with out ORDER BY.

      Updated the Results above.

      Thanks,
      Pradeep.

      Delete
  2. Replies
    1. Yes Manu, Test was done on V7R2.

      However, I am not anticipating many changes for any of the latest versions (V7R3 or V7R4).

      Thanks,
      Pradeep.

      Delete
  3. isn't the index stored separately from the table? If so, the table's size would need to include the index's size to be an equal comparison of storage.

    ReplyDelete
    Replies
    1. Hi,

      Table was created with Unique Key Constraint and No separate Index has been created.

      Thanks,
      Pradeep.

      Delete
  4. La prueba no es convincente, esos 3 segundos pueden indicar otra cosa, ahora tripliquen los datos a 3millones y revisen si el tiempo se triplicó, así si.

    ReplyDelete
    Replies
    1. Hi,

      I have run the test with 3 million records as suggested and the time difference is now about 17 seconds. Below is for your reference.

      CALL PPREAD
      DSPLY Start: 10.44.43 End: 10.45.13 Records: 3000000 //30 Seconds

      CALL PPSQL
      DSPLY Start: 10.46.22 End: 10.46.35 Records: 3000000 //13 Seconds

      CALL PPSQL1
      DSPLY Start: 10.47.18 End: 10.47.22 Records: 3000000 //4 Seconds

      Thanks,
      Pradeep.

      Delete

Post a Comment

Popular posts from this blog

What is the importance of User Open (USROPN) in RPGLE - IBM i

What is Deep Learning? Beyond the Basics of AI

What is Artificial Intelligence?