You are on page 1of 29

<Insert Picture Here>

11g new performance features for Developers


A Knowledge Transfer session
Nikos Plevris, Principal Service Delivery Manager , November 2009

New performance features for Developers


Agenda
• SQL and PL/SQL performance improvement and scalability
• New and Enhanced
• Functionality
• Structures
• Objects
• The Developer’s approach

New performance features for Developers


Automatic “Native” PL/SQL Compilation
• Previous releases: PL/SQL interpreted to C code,  20% improved performance
then compiled by 3rd party compiler or DLL loader  With native PL/SQL compilation:

• 11g: PL/SQL source code is directly translated to The Whetstone Benchmark shows
that real native compilation is
the DLL for the server, bypassing the file system two-and-a-half times faster than

directories by doing the linking and loading itself. C native compilation.

• Initialization parameter: plsql_code_type


• [NATIVE | INTERPRETED]
• Dynamic change:
• alter system | alter session
• alter procedure <PROC> compile
plsql_code_type=native;
• DBA_PLSQL_OBJECT_SETTINGS view

New performance features for Developers


Adaptive Cursor Sharing1
• Parameter cursor_sharing := [EXACT|
SIMILAR|FORCE]
• Bind peeking – Optimizer evolves execution
plan during first hard parse of bind variables
• 11g adaptive cursor sharing – Optimizer
generates multiple execution plans for a
statement that uses bind variables

New performance features for Developers


Adaptive Cursor Sharing2
• Allows for intelligent cursor sharing for
statements that use bind variables
• Is used to compromise between cursor sharing
and optimization
• Has the following benefits:
• Automatically detects when different executions
would benefit from different plans
• The optimizer avoids expensive table scans and
index searches based on selectivity criteria thus
speeding up data retrieval
• Automated mechanism that cannot be turned
off

New performance features for Developers


Adaptive Cursor Sharing3 - Architecture

New performance features for Developers


Adaptive Cursor Sharing4 – Dictionary Views

New performance features for Developers


Adaptive Cursor Sharing Demo

New performance features for Developers


SQL Query Result Cache1
 200% improved performance for
• Cache the result of a query or query block for read-intensive workload
future use (SQL query and PL/SQL function  Part of SGA shared pool

results) (~1% of shared_pool_size up to 75%)


or
• Cache is used across sessions and statements (0.25% of memory_target) or
(0.50% of sga_target)
unless it is stale
• Benefits:
• Scalability
• Reduction of memory usage and I/O
• Good candidate statements:
• Access many rows
• Return few rows

New performance features for Developers


Setting Up SQL Query Result Cache2
 Three new init parameters
• At the instance level using parameter  result_cache_mode
RESULT_CACHE_MODE. Values are:  result_cache_max_size
 result_cache_max_result
• AUTO: The optimizer decides to cache based  Dynamic parameters:
on repetitive executions ALTER SYSTEM SET

• MANUAL: Use hint result_cache result_cache_mode = ‘AUTO’;

• FORCE: All results are stored in the cache


• At table level:

New performance features for Developers


Setting Up SQL query result cache3
 Using the hint
• At the session level:
• ALTER SESSION SET result_cache_mode=FORCE;
• At the statement level – Queries, subqueries
and inline views:
• Hints result_cache_mode and
no_result_cache
 PL/SQL code

New performance features for Developers


Administer SQL query result cache4
• Use DBMS_RESULT_CACHE package:

• View SQL Query cache dictionary information:

New performance features for Developers


Result Query Cache Demo

New performance features for Developers


Considerations on query result cache5
• The result cache is disabled for queries
containing:

• Result cache does not release memory:

• Bind variables:

New performance features for Developers


CREATE TABLE seq_table
(sequencing_id NUMBER);

Sequences in PLSQL CREATE SEQUENCE sequencing_s1;

-- In Oracle 10g you would use a


sequence value in a PL/SQL block
as follows:
• Sequence calls directly into statements without DECLARE
first querying them from the dual pseudotable sequence_value NUMBER;
BEGIN
• In 11g, the usage of the pseudocolumns SELECT sequencing_s1.nextval
CURRVAL and NEXTVAL make writing INTO sequence_value FROM
dual;
PL/SQL source code easier and improve run- INSERT INTO seq_table
time performance and scalability. VALUES (sequence_value);
COMMIT;
• The usage of sequence_name.CURRVAL and END;
sequence_name.NEXTVAL can be utilized /

whenever a number expression is used. --While this syntax still works in


Oracle 11g, you can now simplify
it by using:
BEGIN
INSERT INTO seq_table
VALUES
(sequencing_s1.nextval);
COMMIT;
END;
/

New performance features for Developers


Next-Generation LOBs create table secure_docs
( document_id number not null
• 11g provides two storage implementations primary key,

for LOB columns: name varchar2(255) not null,

• BASICFILE = Pre-Oracle 11g CLOBs, BLOBs edba_knowledgebase_category_id


number not null,
• SECUREFILE = New LOB storage mime_type varchar2(128),
implementation
doc_size number,
• Prerequisites dad_charset varchar2(128),
• automatic segment space management last_updated date,
(compatible 11.0.0.0.0) content_type varchar2(128),
• Benefits blob_content blob)
• Faster LOB Retrieval tablespace tools
• ODP.NET now makes fewer round trips to the lob (blob_content) store as
database server to retrieve LOB information. securefile (
ODP.NET LOB retrieval performance is now faster
• Queries in SQL*Plus now support BLOB columns. tablespace tools enable storage in
row chunk 8192 pctversion 10
• Reduce space consumption nocache logging)

• Enhanced Security

New performance features for Developers


CREATE [OR REPLACE] TRIGGER
trigger_name

Compound trigger 1 FOR {INSERT | UPDATE | UPDATE OF column1


[, column2 [, column(n+1)]] | DELETE}
ON table_name
COMPOUND TRIGGER
[declaration_statement;]
• Easier to program one trigger to fire at various timing
points instead of multiple simple triggers each fires BEFORE STATEMENT IS
[declaration_statement;]
at single timing point. BEGIN

• Has a section for each of the BEFORE execution_statement;


END BEFORE STATEMENT;
STATEMENT, BEFORE EACH ROW, AFTER EACH
BEFORE EACH ROW IS
ROW, and AFTER STATEMENT timing points. [declaration_statement;]

• Improved usability for the PL/SQL programmer and BEGIN


execution_statement;
improved runtime performance and scalability: END BEFORE EACH ROW;

• accumulate rows destined for a second table so that AFTER EACH ROW IS
you can periodically bulk-insert them [declaration_statement;]
BEGIN
• To avoid the mutating-table error (ORA-04091) execution_statement;
END AFTER EACH ROW;
• Can be defined on either a table or a view
• Only DML statements trigger compound triggers AFTER STATEMENT IS
[declaration_statement;]
BEGIN
execution_statement;
END AFTER STATEMENT;
END [trigger_name];
/

New performance features for Developers


CREATE [OR REPLACE] TRIGGER
trigger_name

Compound trigger 2 FOR {INSERT | UPDATE | UPDATE OF column1


[, column2 [, column(n+1)]] | DELETE}
ON table_name
COMPOUND TRIGGER
[declaration_statement;]
• They DO NOT fire when:
• the DML statement doesn’t change any rows AND BEFORE STATEMENT IS
[declaration_statement;]
• the trigger hasn’t implemented at least a BEFORE BEGIN
STATEMENT or AFTER STATEMENT block. execution_statement;
END BEFORE STATEMENT;
• The declaration section executes before any timing-point
sections execute. Variables and subprograms declared BEFORE EACH ROW IS
[declaration_statement;]
in this section have firing-statement duration. BEGIN
• Support filtering actions : execution_statement;
END BEFORE EACH ROW;
• Instead of the WHEN clause, use the UPDATE OF
column name filter as a governing event in updates. AFTER EACH ROW IS
[declaration_statement;]
• Implement EXCEPTION blocks in any of the subordinate BEGIN
timing point blocks execution_statement;
END AFTER EACH ROW;
• The :new and :old pseudo-records can be used in the
row-level statement blocks AFTER STATEMENT IS
[declaration_statement;]
• Requires at least one timing-point block. BEGIN
execution_statement;
END AFTER STATEMENT;
END [trigger_name];
/

New performance features for Developers


Compound Trigger Demo

New performance features for Developers


Additional PL/SQL
enhancements
• Native dynamic SQL now supports statements bigger
than 32K characters by allowing a CLOB argument
• Increased in functionality of string functions:
REGEXP_INSTR, REGEXP_SUBSTR, REGEXP_COUNT
• CONTINUE statement
• Minimum need to recompile dependent PL/SQL
packages or view after an online table redefinition.
ONLY if logically affected

New performance features for Developers


Online Index creation-rebuild and
Invisible indexes
• Online index creation and rebuild prior to this The SHARED EXCLUSIVE locking strategy
release (like 10g) required a DML-blocking applies to:
exclusive lock at the beginning and end of the
rebuild for a short period of time. This meant that • create index online
there would be two points at which DML activity • rebuild index online
• create materialized view log
came to a halt.
• This DML-blocking lock is no longer required,
Invisible index:
making these online index operations fully • CREATE index <idx_name> invisible
transparent. • ALTER index <idx_name> invisible;
• DBA_INDEXES.visibility column
• Invisible index – Not being visible to the cost
optimizer during execution plans Use hint to force index use
• test the usefulness of a new index without affecting • Select /*+index ( <table>
execution plans <idx> */ FROM ..

• Temporary purposes
At the instance level – Init parameter
optimizer_use_invisible_indexes = FALSE

New performance features for Developers


Partitioning Enhancements1
• Extended Composite Partitioning CREATE TABLE list_hash_tab (
id NUMBER,
• Range-Hash (available since 8i) code VARCHAR2(10),
description VARCHAR2(50),
• Range-List (available since 9i) created_date DATE
• Range-Range )
PARTITION BY LIST (code)
• List-Range SUBPARTITION BY HASH (id)
• List-Hash (
PARTITION part_aa values ('AA')
• List-List (
• Extended composite partitioning allows data to SUBPARTITION part_aa_01,
SUBPARTITION part_aa_02
be partitioned along two dimensions ),
partition part_bb values ('BB')
(
SUBPARTITION part_bb_01,
SUBPARTITION part_bb_02
)
);

New performance features for Developers


Extended Composite Partitioning Demo

New performance features for Developers


Partitioning Enhancements2
• Interval Partitioning CREATE TABLE interval_tab (
id NUMBER,
• automate the creation of range partitions by code VARCHAR2(10),
creating partitions on demand description VARCHAR2(50),
created_date DATE
• Considerations: )
PARTITION BY RANGE (created_date)
• Restricted to a single partition key that must be
INTERVAL
a numerical or date range (NUMTOYMINTERVAL(1,'MONTH'))
• At least one partition must be defined when the (
PARTITION part_01 values LESS
table is created THAN
• A MAXVALUE partition cannot be defined for (TO_DATE('01-NOV-2007','DD-MON-YYYY'))
an interval partitioned table );

• NULL values are not allowed in the partition


column

New performance features for Developers


Interval Partitioning Demo

New performance features for Developers


Partitioning Enhancements3
CREATE TABLE system_partitioned_tab
(
• System Partitioning id NUMBER,
• Allows large tables to be broken down into code VARCHAR2(10),
description VARCHAR2(50),
smaller partitions created_date DATE
• There are no partitioning keys, system partitions )
have no bounds for ranges or lists PARTITION BY SYSTEM
(
• Explicitly specify the rows to the target table PARTITION part_1,
partition using partition-aware syntax PARTITION part_2
);
• Benefits
• The application controls the data placement and INSERT INTO system_partitioned_tab
PARTITION (part_1) VALUES (1,
how it is retrieved 'ONE', 'One', SYSDATE);
• Db has no control over row placement – No
partition pruning DELETE FROM system_partitioned_tab
PARTITION (part_2) WHERE id = 1;

UPDATE system_partitioned_tab
PARTITION (part_1) SET code =
'TWO' WHERE id = 2;

New performance features for Developers


Partitioning Enhancements4
CREATE TABLE parent_tab (

• Reference Partitioning id
code
NUMBER NOT NULL,
VARCHAR2(10) NOT NULL,

• Relies on existing parent-child relationships and description VARCHAR2(50),


created_date DATE,
is enforced by an active primary key and foreign CONSTRAINT parent_tab_pk
key constraint PRIMARY KEY (id))
PARTITION BY RANGE (created_date)
• The child table automatically inherits the ( PARTITION part_2007 VALUES
partitioning key from the parent table without LESS THAN (TO_DATE('01-JAN-2008',

duplicating the key columns 'DD-MON-YYYY')),


PARTITION part_2008 VALUES
• Use the keywords PARTITION BY REFERENCE LESS THAN (TO_DATE('01-JAN-2009',
'DD-MON-YYYY')));
(foreign_key name) as part of your create table CREATE TABLE child_tab (
statement id NUMBER NOT NULL,
parent_tab_id NUMBER NOT NULL,
code VARCHAR2(10),
description VARCHAR2(50),
created_date DATE,
CONSTRAINT child_tab_pk PRIMARY KEY (id),
CONSTRAINT child_parent_tab_fk
FOREIGN KEY (parent_tab_id)
REFERENCES parent_tab (id))
PARTITION BY REFERENCE (child_parent_tab_fk

New performance features for Developers


The other approach: DBA ‘s view
SQL Details

Top Activity Monitoring Details

Session Details

New performance features for Developers


Q&A

QUESTIONS
&
ANSWERS

You might also like