home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / DBDEMO.ZIP / DEMOFLS.ZIP / STAT_DYN.TXT < prev   
Text File  |  1991-07-01  |  2KB  |  44 lines

  1.         Static vs. Dynamic SQL
  2.  
  3.  
  4. This program shows the performance difference between static
  5. and dynamic SQL.  The query has been specially chosen to be
  6. complex (lots of clauses) but short (only one row is FETCHed)
  7.  
  8. In the static case the CURSOR is declared explicitly by writing
  9. the whole SQL statement after EXEC SQL.  In the dynamic
  10. version, the same query is first copied into a string variable
  11. and then PREPARED.  It is assumed (maybe unrealistically) that
  12. all the column names are known, otherwise an SQLDA has to be
  13. used making it more complex.
  14.  
  15. If the complete SQL query is known beforehand, it is usually
  16. more efficient to use static SQL. For queries known only at
  17. run time (e.g. the number of columns or the table name has to be
  18. user defined), dynamic SQL is required.
  19.  
  20. At its most complex form, nothing is known about the query
  21. before hand, so the query, table names, and the columns to
  22. be extracted have to be determined at run time using SQLDA,
  23. PREPARE and DESCRIBE.
  24.  
  25. Use of same cursor for Static and Dynamic is allowed.
  26.  
  27. ┌───────────────┬───────────────────────┬──────────────────────────┐
  28. │   Item        │    Static             │ Dynamic                  │
  29. ├───────────────┼───────────────────────┼──────────────────────────┤
  30. │ Preparation   │  Implicit at SQLPREP  │  Explicit at Runtime     │
  31. ├───────────────┼───────────────────────┼──────────────────────────┤
  32. │ Persistence   │  Until rebound        │ Until COMMIT or ROLLBACK │
  33. ├───────────────┼───────────────────────┼──────────────────────────┤
  34. │ Authorization │  Binder               │  Executor                │
  35. ├───────────────┼───────────────────────┼──────────────────────────┤
  36. │ Otimization   │  Present at SQLPREP   │  Current                 │
  37. ├───────────────┼───────────────────────┼──────────────────────────┤
  38. │ Input/Output  │ Host var(except FETCH)│ Host var or SQLDA        │
  39. └───────────────┴───────────────────────┴──────────────────────────┘
  40.  
  41. CONCEPTS:
  42.  
  43.    Access plan and its preparation, dynamic SQL, PREPARE, DESCRIBE,
  44.    SQLDA (for more advanced dynamic queries).