 |
|
Faster DML Triggers in Oracle 11g
Oracle 11g New Features Tips by Burleson
Consulting
July 8, 2008 |
Oracle 11g SQL
New Features Tips
Another transparent enhancement with Oracle 11g
is quicker triggers, reported to be up to 25% faster when row-level
triggers perform DML on other tables. While this improvement has
not been widely publicized by Oracle in the 11g release, it offers a
noticeable improvement in several business cases. For example, this
improvement might show substantial benefits in triggers used for
auditing.
To demonstrate the improvement, define a table
for sensitive information such as
credit_card:
create
table
credit_cards (
account_id number,
credit_card_number varchar2(30),
expiration_date date);
Next, create tables
audit_log and
audit_tables
for storing audit information:
create table
audit_log (
username varchar2(30),
table_name varchar2(30),
user_operation varchar2(30),
user_time date);
create table
audit_tables (
table_name varchar2(30),
last_updated_by varchar2(30),
last_update_time date);
Define a trigger on
credit_cards
that inserts a record into audit_log
and updates audit_tables
whenever an insert occurs:
CREATE OR
REPLACE TRIGGER credit_cards_tr1
BEFORE INSERT
ON VJ.CREDIT_CARDS
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO
AUDIT_LOG (USERNAME, TABLE_NAME, USER_OPERATION, USER_TIME)
VALUES
(USER , 'CREDIT_CARDS', 'INSERT - ' || :NEW.ACCOUNT_ID,
SYSDATE );
UPDATE
audit_tables
SET
last_updated_by = USER,
last_update_time = SYSDATE
WHERE
table_name = 'CREDIT_CARDS';
EXCEPTION
WHEN OTHERS THEN
RAISE;
END credit_cards_tr1;
/
After completing the setup, in Oracle 10.2, the
following PL/SQL block should be executed:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options
SQL> set timing on
SQL> DECLARE
2 i NUMBER := 1;
3 BEGIN
4 LOOP
5 insert into
6 credit_cards
7 VALUES (i, '1234123412341234', '01-JAN-2009');
8 COMMIT;
9 i := i+1;
10 EXIT WHEN i>10000;
11 END LOOP;
12 END;
13 /
PL/SQL procedure successfully
completed.
Elapsed: 00:00:04.57
Following the same steps on Oracle 11.1, the
result is:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, OLAP, Data Mining and Real Application
Testing options
SQL> set timing on
SQL> DECLARE
2 i NUMBER := 1;
3 BEGIN
4 LOOP
5 insert into
6 credit_cards
7 VALUES (i, '1234123412341234', '01-JAN-2009');
8 COMMIT;
9 i := i+1;
10 EXIT WHEN i>10000;
11 END LOOP;
12 END;
13 /
PL/SQL procedure successfully
completed.
Elapsed: 00:00:04.00
The improvement in trigger execution times
appears to be more prevalent as the trigger performs DML on a larger
number of tables. This enhancement should prove to be useful in
many situations where triggers perform DML on other tables, such
as:
Through partitioning and index enhancements,
Oracle 11g offers many new tools to simplify the tasks of Remote DBAs and
developer staffs.
This includes:
-
a new partitioning feature, Interval
Partitioning to create new partitions
-
System partitioning allowing application level
control in tables or indexes
-
Reference partitioning in Oracle 11g that
allows the partitioning of two related tables to be partitioned
based on a referential constraint
-
Support for partitioning tables using a
partitioning key on virtual columns
-
New composite partitioning strategies
-
Partition pruning utilizing bloom filtering
To compliment the new partitioning enhancements
in Oracle 11g, ILM has also been enhanced allowing easier data
movements.
This chapter also includes new index
enhancements and features in 11g:
-
Invisible indexes useful in many diverse
situations
-
Extended features of compressed tables for all
DML operations
-
Improved direct path inserts through directly
accessing NFS V3 servers, using an internal Direct NFS Client with
the Oracle Database kernel.
-
Another part of the new Oracle 11g enhancements
is Database Resident Connection Pooling (DRCP) which supports
server-side connection pooling.
-
OCI in 11g then expands use of memory caching
to improve query performance.
-
Furthermore, a virtual column, an expression
based on existing columns in the table, which in a table can
provide advantages in disk space utilization.
-
Additionally, binary XML has been added
as a new option for storage.
Oracle 11g also offers a new feature to improve
help requests from Oracle Support called Incident Package Service.
Furthermore, enabling read-only tables now utilizes easier
processes.
 |
This is an
excerpt from the new book
Oracle 11g New Features: Expert Guide to the Important
New Features by John Garmany, Steve Karam, Lutz Hartmann, V. J.
Jain, Brian Carr.
You can buy it direct from the publisher
for 30% off. |