Avoid Unnecessary Context Switches Options

codeling Posts: 1057 Points: 4443
Posted: Friday, June 23, 2017 10:25:10 AM

Oracle use two engine for execution of PL/SQL programs:

  1. PL/SQL Engine
  2. SQL Engine

During execution of PL/SQL program to execute all procedural statements (like if, for, assignments...) Oracle use PL/SQL engine and sends all SQL statements present in the code to the SQL engine. The SQL engine will parse and execute the query or DML statement and return the expected output back to the PL/SQL engine. This switch between the two engines is called context switching.

Which impose additional overhead like maintain the state of variables and stack on every switch..... means highly expensive. Specially the cursor loops are very expensive so instead of that one should use Bulk Bind and Bulk collect features which reduce context switching.

 

codeling Posts: 1057 Points: 4443
Posted: Friday, June 23, 2017 10:30:12 AM

Instead of fetching into simple variables or records fetch into a collection of scalars or a collection of records using BULK COLLECT INTO.

FORALL instructs the PL/SQL engine to bulk-bind input collections before sending them to the SQL engine.

Usually, using of the BULK COLLECT and FORALL statements can drastically improve the performance.

Users browsing this topic
Guest