The Describe Overhead Avoiding the Describe Overhead

Optimizing PLSQL Performance 4-9

4.3.5.1 The Describe Overhead

In order to execute PLSQL procedures, mod_plsql needs to know about the datatype of the parameters being passed in and the required grants for access. Based on this information, mod_plsql binds each parameter either as an array or as a scalar. One way to know the procedure signature is to describe the procedure before executing it. However, this approach is not efficient because every procedure has to be described before execution. To avoid the describe overhead, mod_plsql looks at the number of parameters passed for each parameter name. It uses this information to assume the datatype of each variable. The logic is simply that if there is a single value being passed, then the parameter is a scalar, otherwise it is an array. This works for most cases but fails if there is an attempt to pass a single value for an array parameter or pass multiple values for a scalar. In such cases, the first attempt to execute the PLSQL procedure fails. mod_plsql issues a Describe call to get the signature of the PLSQL procedure and binds each parameter based on the information retrieved from the Describe operation. The procedure is re-executed and results are sent back. This Describe call occurs transparently to the procedure, but internally mod_plsql has encountered two extra round trips, one for the failed execute call and the other for the describe call.

4.3.5.2 Avoiding the Describe Overhead

You can avoid performance problems with the following: ■ Use flexible parameter passing. ■ Always ensure that you pass multiple values for arrays. For single values, you can pass dummy values that are ignored by the procedure. ■ Use the following workaround, which defines a two-parameter style procedure which defaults the unused variables. 1. Define a scalar equivalent of your procedure, which internally calls the original procedure. For example, the original package could be similar to the following example: CREATE OR REPLACE PACKAGE testpkg AS TYPE myArrayType is TABLE of VARCHAR232767 INDEX BY binary_ integer; PROCEDURE arrayproc arr myArrayType; END testpkg; 2. If you are making URL calls like pls...testpkg.arrayproc? arr= 1, change the specification to be similar to the following: CREATE OR REPLACE PACKAGE testpkg AS TYPE myArrayType is TABLE of VARCHAR2 32767 INDEX BY binary_integer; PROCEDURE arrayproc arr varchar2; PROCEDURE arrayproc arr myArrayType; END testpkg; 3. The procedure arrayproc should be similar to: CREATE OR REPLACE PACKAGE BODY testpkg AS PROCEDURE arrayproc arr varchar2 IS localArr myArrayType; BEGIN localArr 1 := arr; arrayproc localArr; END arrayproc; 4-10 Oracle Fusion Middleware Users Guide for mod_plsql

4.3.6 The Flexible Parameter Passing four-parameter Overhead