Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

High Performance Plsql

4,913 views

Published on

High Performance PLSQL - presentation given at Oracle Open World 2009

Published in: Technology, Business
  • http://dbmanagement.info/Tutorials/PLSQL.htm
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

High Performance Plsql

  1. 1. High Performance PL/SQL<br />Guy Harrison<br />Director of Development, Melbourne<br />www.guyharrison.net<br />
  2. 2. Introductions <br />Buy Guy’s Book<br />Buy Quest Products <br />
  3. 3. http://www.motivatedphotos.com/?id=17760<br />
  4. 4.
  5. 5. Measuring PL/SQL performance<br />DBMS_PROFILER is the best way to find PL/SQL “hot spots”:<br />
  6. 6. Scripts at www.guyharrison.net<br />
  7. 7. Toad Profiler support<br />
  8. 8. SQL*Navigator profiler support<br />
  9. 9. 11g Hierarchical profiler<br />$ plshprof -output hprof demo1.trc<br />
  10. 10. Plshprof output <br />
  11. 11. DBMS_HPROF tables <br />Scripts at www.guyharrison.net<br />
  12. 12. When is PL/SQL faster?<br />PL/SQL routines most massively outperform other languages when network round trips are significant.<br />
  13. 13. Network traffic<br />Routines that process large numbers of rows and return simple aggregates are also candidates for a stored procedure approach<br />
  14. 14. Stored procedure alternative <br />
  15. 15. Network traffic example <br />
  16. 16. Aspects of PL/SQL performance <br />
  17. 17. PLSQL_OPTIMIZE_LEVEL<br />
  18. 18.
  19. 19. It’s usually the SQL <br />Most PL/SQL routines spend most of their time executing SELECT statements and DML<br />SQL tuning is a big topic but:<br />Measure SQL overhead of PL/SQL routines first<br />Ensure best possible optimizer statistics <br />Consider adequacy of indexing<br />Learn how to use DBMS_XPLAN, SQL Trace, etc <br />Exploit 10g/11g tuning facilities (if licensed)<br />Don’t issue SQL when you don’t need to<br />
  20. 20. SQL or PL/SQL?<br />Scripts at www.guyharrison.net<br />
  21. 21.
  22. 22.
  23. 23. Three ways of processing rows <br />Four<br />Memory Requirements<br />CPU & logical reads<br />
  24. 24. One at a time<br />
  25. 25. All at once <br />
  26. 26. In batches<br />
  27. 27. Array processing<br />Bulk collect without LIMIT<br />No bulk collect <br />(Prior to 10g or PLSQL_OPTIMIZE_LEVEL &lt;2)<br />
  28. 28. Array processing<br />PLSQL_OPTIMIZE_LEVEL&gt;1 causes transparent BULK COLLECT LIMIT 100<br />Bulk collect without LIMIT<br />No bulk collect <br />10g or higher with PLSQL_OPTIMIZE_LEVEL &gt;1<br />
  29. 29. BULK COLLECT worst case scenario <br />
  30. 30. Bind variables in Dynamic SQL <br />Using bind variables allows sharable SQL, reduces parse overhead and minimizes latch contention <br />Unlike other languages, PL/SQL uses bind variables transparently<br />EXCEPT when using Dynamic SQL:<br />
  31. 31. Using bind variables <br />
  32. 32. Bind variable performance <br />10,000 calls<br />
  33. 33. NOCOPY<br />The NOCOPY clause causes a parameter to be passed “by reference” rather than “by value” <br />
  34. 34. NOCOPY performance gains<br />4,000 row, 10 column “table”; 4000 lookups:<br />
  35. 35. Associative arrays <br />Traditionally, sequential scans of PLSQL tables are used for caching database table data:<br />
  36. 36. Associative arrays<br />Associative arrays allow for faster and simpler lookups:<br />
  37. 37. Associative array performance<br />10,000 random customer lookups with 55,000 customers<br />
  38. 38.
  39. 39. Reduce unnecessary Looping<br />Unnecessary loop iterations burn CPU<br />
  40. 40. Remove loop Invariant terms<br />Any term in a loop that does not vary should be extracted from the loop<br />PLSQL_OPTIMIZE_LEVEL&gt;1 does this automatically<br />
  41. 41. Loop invariant performance improvements<br />
  42. 42. Recursion (see: recursion)<br />Recursive routines often offer elegant solutions*.<br />However, deep recursion is memory-intensive and usually not scalable<br />*<br />* Known In Australia as “smart-ass solutions”<br />
  43. 43. Recursion memory overhead <br />
  44. 44.
  45. 45. Number crunching (1)<br />
  46. 46. Number crunching (2)<br />
  47. 47. 11g Function cache<br />Suits deterministic but expensive functions<br />Expensive table lookups on non-volatile tables<br />
  48. 48. Function cache performance <br />100 executions, random date ranges 1-30 days:<br />
  49. 49. In-lining<br />Manual in-lining<br />Modular design <br />
  50. 50. Automatic in-lining<br />PLSQL_OPTIMIZE_LEVEL = 3<br />OR:<br />
  51. 51. Ran out of time for...<br />Array insert using FORALL<br />Explicit vs. implicit cursors <br />RETURNING clause <br />Pipelined functions<br />Optimizing triggers<br />Short circuit evaluations<br />IF and CASE comparison ordering<br />
  52. 52. Thank You – Q&A<br />

×