Beruflich Dokumente
Kultur Dokumente
Implementation
Feature Native compilation of PL/SQL Manipulating records faster by up to 5x Inter -package calls faster by up to 1.5x Inter-package Utl_Tcp native implementation Common SQL parser Perf 3 3 3 3 3 3 Funct Use
Language features
Feature Table functions Cursor expressions Multilevel collections Exception handling in bulk binding DML operations Bulk binding in native dynamic SQL CASE statements and CASE expressions 3 Perf 3 3 3 Funct 3 3 3 3 Use 3 3 3 3 3 3
y searched variety
y searched variety
CASE_NOT_FOUND exception
begin p:=0; q:=0; r:=0; case when p = 1 then Action1; when r = 2 then Action2; when q > 1 then Action3; end case; exception when case_not_found then Show ('Exception: case_not_found' ); end;
Supplied packages
Feature Utl_Http enhanced Utl_ Raw enhanced Utl_Raw Utl_File enhanced Nineteen new packages Perf 3 Funct 3 3 3 3 Use
Utl_Http enhancements
y Used to send HTTP request and handle the reply mechanically especially in B2B applications y Oracle9i adds
POST method arbitarily long request Authentication Access to return status code RAW reply cookie support
y I.e. provides full support for the semantics that can be expressed via HTTP y Full functionality for character set conversion for request and reply
Background
y Pre-Oracle9i, compilation of PL/SQL source code always results in bytecode which is stored in the database and interpreted at run-time by a virtual machine implemented within ORACLE
Whats new?
y In Oracle9i PL/SQL source code may optionally be compiled into native object code which is linked into ORACLE
Developer choice
alter session set plsql_compiler_flags = 'NATIVE' /* or 'INTERPRETED' */;
y sets the compilation mode for subsequently compiled PL/SQL library units
Oracle recommends
y All PL/SQL library units that are called from a given natively compiled top-level unit should also be compiled natively there is a cost for the context switch when a library unit compiled in native mode invokes one compiled in interpreted mode y Recommendation includes the Oracle-supplied library units (by default these are compiled in interpreted mode)
Oracle9i in Action
y 170 Systems, Inc have been an Oracle Partner for eleven years and participated in the Beta Program for the Oracle9i Database with particular interest in PL/SQL Native Compilation y They have now certified their 170 MarkView Document Management and Imaging System against Oracle9i y They have updated the install scripts to optionally turn on Native Compilation
170 MarkView
y Large-scale multi-user, multi-access system y Customers include
British Telecommunications E*TRADE Group the Apollo Group the University of Pennsylvania
y Very large numbers of documents, images, concurrent users, and high transaction rates y Performance and scalability especially important
170 MarkView
y Business logic, including preparation of data for presentation, is implemented in the database in PL/SQL y Involves complex logic and intensive string processing supported by stacks and lists of values modeled as PL/SQL collections.
170 Systems
y Have observed a performance increase of up to 40% for computationally intensive routines and no performance degradation
usability feature y Defines a generic weak cursor once and for all
y Works pre-Oracle9i y Performance boost because reduces context switching between PL/SQL and SQL engines
y Works pre-Oracle9i
New in Oracle9i
y This is just one example of bulk binding working with native dynamic SQL y The combination now works in all situations Defining
SELECT
In-binding
FORALL USING
Out-binding
y Since theres only one SQL statement (we had two in the explicit approach) the CBO has a better chance
Outer loop
y Fetch the cursor into the ref cursor target and then fetch it (bulk) into its target
open depts; loop fetch depts into v_dname, emps; exit when depts%notfound; Show ( v_dname ); fetch emps bulk collect into v_ename;
Inner loop
y Process the bulk fetched results
for j in v_ename.first..v_ename.last loop Show ( v_ename(j) ); end loop;
Cursor terminology
y A cursor variable (i.e. a variable of type REF CURSOR) points to an actual cursor y It may be used as a formal parameter to a PL/SQL procedure or function y A cursor expression defines an actual cursor and is legal in a SQL statement y So youd expect to write
Func ( cursor ( select c from t ) )
A cursor expression can be an actual parameter to a PL/SQL function in a top level SQL statement
Hold that thought
number, varchar2(20) );
y Nice, but the response characterstics are not what were used to with a rowsource
Note:
y The pipelined and pipe row keywords can only be used together as shown y A pipelined table function can be invoked only in the FROM list of a SELECT clause y We can now use a simpler syntax
select * from table ( Func() );
y We can now use package-level types for the row and for the table
Remember
y A cursor expression can be an actual parameter to a PL/SQL function in a top level SQL statement y So a table function may now be defined with an input parameter of type REF CURSOR and invoked with a cursor expression as the actual parameter
function Func_2 ( p_cur in sys_refcursor ) return Pkg.my_tab pipelined is v_in_row Pkg.my_in_row; v_out_row Pkg.my_row; begin loop fetch p_cur into v_in_row; exit when p_cur%notfound;
< compute out-row(s) from in-row(s) >
pipe row ( v_out_row ); end loop; close p_cur; return; end Func_2;
Were consuming in-rows, Transforming them procedurally to out-rows with an arbitrarily complex M:N algorithm, and piping out-rows as soon as theyre ready
Think about it
y We now have a very powerful generic transformation technique y It starts with the results from a SELECT and transforms them into something you can SELECT from y Sounds familiar? y Note: dont forget, the table function can have ordinary input parameters
Daisy-chaining
y We can plug any number of transformations back-to-back y Each can perform an arbitrarily complex transformation y The starting point could be an Oracle table y Or it could be a table function that accesses external data via Utl_File or via the call-out framework
y Parallelization
PARALLEL_ENABLE syntax
function Func_2 ( p_cur in sys_refcursor ) return Pkg.my_tab pipelined parallel_enable ( partition p_cur by any ) is...
y Must have an input REF CURSOR parameter to drive the partitioning y ANY is the simple, special case results dont depend on the order of processing
Caution
y If you use ANY and your assertion is wrong, the results will be unpredictable y The developer must design the algorithm so that the results dont depend on the degree of parallelism
CLUSTER BY
function Func_3 ( p_cur in Pkg.cur_t ) return Pkg.my_tab pipelined parallel_enable ( partition p_cur by hash (n) ) cluster p_cur by (n) is...
y The algorithm requires that all rows for a given value of n come together to a single slave y but doesnt care about the order
ORDER BY
function Func_4 ( p_cur in Pkg.cur_t ) return Pkg.my_tab pipelined parallel_enable ( partition p_cur by range (n) ) order p_cur by ( n, m ) is...
y Not only must all rows for a given value of n come together to a single slave y but also they must be ordered by n, m
Before
t1 oltp
stage1
t2
stage2
t3 data warehouse
pipelined 3
parallelized 3
Comparison
y y y y y y Sun Ultra-Enterprise 4500 3 GB RAM, 10 CPUs of 168 MHz 1,000,000 row source table 1 row in to 7 rows out pivot transform Oracle8i PL/SQL cursor loop with 7 INSERTs Oracle9i table function with 7 PIPE ROWs
Performance and Scalability in DSS Environment with Oracle9i, Neil Thombre, Oracle Corp OOW paper #822 also on otn.oracle.com/deploy/performance/
Oracle8i 87 min
7.5 x
Q U E S T I O N S A N S W E R S