+ All Categories
Home > Documents > Forgotten Features

Forgotten Features

Date post: 07-Apr-2018
Category:
Upload: rohit-kumar
View: 227 times
Download: 0 times
Share this document with a friend

of 94

Transcript
  • 8/4/2019 Forgotten Features

    1/94

    1

    ForgottenFeatures

    Julian Dyke

    Independent ConsultantWeb Version

    juliandyke.com2005 Julian Dyke

  • 8/4/2019 Forgotten Features

    2/94

    2005 Julian Dyke juliandyke.com2

    Agenda

    Introduction Forgotten Features

    Tracing and Auditing

    Testing and Benchmarking

    Administration

    Execution Plans

    Tables

    Indexes

    SQL

    PL/SQL Conclusion

  • 8/4/2019 Forgotten Features

    3/94

    2005 Julian Dyke juliandyke.com3

    Criteria for an Oracle feature Easy to understand

    Easy to implement

    Works in first release

    Documented in first release

    Compatible with other features

    Improves Productivity or Manageability Saves resources / money

    Intellectually stimulating

  • 8/4/2019 Forgotten Features

    4/94

    2005 Julian Dyke juliandyke.com4

    Tracing

    andAuditing

  • 8/4/2019 Forgotten Features

    5/94

    2005 Julian Dyke juliandyke.com5

    TRACEFILE_IDENTIFIER Initialisation Parameter

    Introduced in Oracle 8.1.7

    tracefile_identifier = ''

    e.g. in Oracle 9.2 if a trace file is called

    ss92001_ora_1760.trc

    ss92001_ora_1760_test.trc

    then the statement

    will change the file name to

    ALTER SESSIONSET tracefile_identifier = 'test';

  • 8/4/2019 Forgotten Features

    6/94

    2005 Julian Dyke juliandyke.com6

    DBMS_SYSTEM.KSDWRT DBMS_SYSTEM

    undocumented package installed in all databases

    owned by SYS

    To write messages to trace files and/or alert log use

    DBMS_SYSTEM.KSDWRT(

    DEST NUMBER, -- 1 = Trace File, 2 = Alert Log, 3 = BothTST VARCHAR2 -- Message

    );

    For example

    BEGINDBMS_SYSTEM.KSDWRT (1, Output to trace file);DBMS_SYSTEM.KSDWRT (2, Output to alert log);DBMS_SYSTEM.KSDWRT (3, Output to both);

    END;/

  • 8/4/2019 Forgotten Features

    7/942005 Julian Dyke juliandyke.com7

    BITAND Initially undocumented built-in function

    Performs a bit-wise AND between two operatorsSELECT BITAND (42,1) FROM dual;

    Can be used as basis for OR and XOR functions

    CREATE OR REPLACE FUNCTION bitor (x NUMBER, y NUMBER)

    RETURN NUMBER ISBEGINRETURN x + y - BITAND (x,y);

    END;/

    CREATE OR REPLACE FUNCTION bitxor (x NUMBER, y NUMBER)

    RETURN NUMBER ISBEGINRETURN BITOR (x,y) - BITAND (x,y);

    END;/

    Beware of overflows

  • 8/4/2019 Forgotten Features

    8/942005 Julian Dyke juliandyke.com8

    Hexadecimal Format Masks Introduced in Oracle 8.1.5

    Convert decimal numbers to and from hexadecimal To convert from decimal to hex

    SELECT TO_CHAR (1048576,XXXXXXXX) FROM dual;

    returns 100000

    To convert from hex to decimal

    SELECT TO_NUMBER (100000,XXXXXXXX) FROM dual;

    returns 1048576

  • 8/4/2019 Forgotten Features

    9/94

  • 8/4/2019 Forgotten Features

    10/942005 Julian Dyke juliandyke.com10

    DBMS_MONITOR Introduced in Oracle 10.1

    To enable trace in another session useDBMS_MONITOR.SESSION_TRACE_ENABLE(

    SESSION_ID NUMBER, -- SIDSERIAL_NUM NUMBER, -- Serial NumberWAITS BOOLEAN, -- Include Waits

    BINDS BOOLEAN -- Include Binds);

    To disable trace in another session useDBMS_MONITOR.SESSION_TRACE_DISABLE(

    SESSION_ID NUMBER, -- SIDSERIAL_NUM NUMBER -- Serial Number

    );

    Waits (event 10046 level 8) are enabled by default

    Binds (event 10046 level 4) are disabled by default

  • 8/4/2019 Forgotten Features

    11/942005 Julian Dyke juliandyke.com11

    DBMS_MONITOR Can be enabled at database level in Oracle 10.2

    To enable trace for all database sessions use

    DBMS_MONITOR.DATABASE_TRACE_ENABLE(

    WAITS BOOLEAN, -- Include WaitsBINDS BOOLEAN -- Include BindsINSTANCE_NAME VARCHAR2 -- Instance Name

    );

    To disable trace for all database sessions use

    DBMS_MONITOR.DATABASE_TRACE_DISABLE(

    INSTANCE_NAME VARCHAR2 -- Instance Name);

  • 8/4/2019 Forgotten Features

    12/942005 Julian Dyke juliandyke.com12

    Autonomous Transactions Introduced in Oracle 8.1.5

    Recursive transaction started by main transaction

    Can commit or rollback independently of main transaction

    Committed data unaffected if main transaction rolls back

    Often used for auditing

    CREATE OR REPLACE TRIGGER trigger1

    BEFORE INSERT ON table1 FOR EACH ROWDECLARE

    PRAGMA AUTONOMOUS_TRANSACTION;BEGIN

    INSERT INTO log1 VALUES (:new.col1,:new.col2,SYSDATE);COMMIT;

    END;/

  • 8/4/2019 Forgotten Features

    13/942005 Julian Dyke juliandyke.com13

    SYS Auditing In Oracle 9.2 and above, operations performed by the SYS

    user can be audited.

    To enable SYS auditing set AUDIT_SYS_OPERATIONSparameter to TRUE

    Auditing information will be written to text file in directoryspecified by AUDIT_DUMP_DEST parameter

    Default directory is $ORACLE_HOME/rdbms/audit

    Filename is ora_.aud where pid is the operating systemprocess ID

  • 8/4/2019 Forgotten Features

    14/942005 Julian Dyke juliandyke.com14

    Testing

    andBenchmarking

  • 8/4/2019 Forgotten Features

    15/942005 Julian Dyke juliandyke.com15

    Fixed Date Initialization Parameter

    Useful for deterministic testing In Oracle 8.0 and above can be set dynamically using

    ALTER SYSTEM

    To set date only use

    FIXED_DATE = DD-MON-YY

    Sets time to 00:00:00

    To set date and time use

    FIXED_DATE = YYYY-MM-DD-HH24:MI:SS

  • 8/4/2019 Forgotten Features

    16/94

    2005 Julian Dyke juliandyke.com16

    Random Functions To guarantee consistent tests, random functions should

    return deterministic results

    DBMS_RANDOM package

    Seed can be specified using DBMS_RANDOM.SEEDprocedure

    SAMPLE clause

    Can be made deterministic by enabling event 10193

    Level specifies seed

    ALTER SESSION SET EVENTS10193 trace name context forever, level 42;

  • 8/4/2019 Forgotten Features

    17/94

    2005 Julian Dyke juliandyke.com17

    Checkpoints and Logfiles To force a checkpoint

    ALTER SYSTEM CHECKPOINT;

    To force a log file switch

    To force a log file switch and archive the log file

    ALTER SYSTEM SWITCH LOGFILE;

    Useful when dumping log files

    ALTER SYSTEM ARCHIVE LOG CURRENT;

    Useful for testing archive log creation with

    Physical standby database

    Logical standby database

  • 8/4/2019 Forgotten Features

    18/94

    2005 Julian Dyke juliandyke.com18

    Flushing the Shared Pool Introduced in Oracle 8.0

    Flushes all unpinned objects from library cache

    ALTER SYSTEM FLUSH SHARED_POOL;

    Useful for deterministic testing but

    After issuing this statement

    All unpinned cursors need reparsing

    All unpinned packages need recompilation

  • 8/4/2019 Forgotten Features

    19/94

    2005 Julian Dyke juliandyke.com19

    Flushing the Buffer Cache Introduced in Oracle 10.1

    Flushes all unpinned buffers from the buffer cacheALTER SYSTEM FLUSH BUFFER_CACHE;

    In Oracle 9.0.1 and above the following command has the

    same effectALTER SESSION SET EVENTSIMMEDIATE TRACE NAME FLUSH_CACHE;

    Useful for deterministic testing but

    After issuing this statement

    Warm up the cache before testing workloads

  • 8/4/2019 Forgotten Features

    20/94

    2005 Julian Dyke juliandyke.com20

    PerformanceTuning

  • 8/4/2019 Forgotten Features

    21/94

    2005 Julian Dyke juliandyke.com21

    V$SQL_PLAN Introduced in Oracle 9.0.1

    Shows actual execution plan in memory

    Enhanced in Oracle 9.2 to include

    Access Predicates (Joins)

    Filter Predicates

    Related views include

    V$SQL_PLAN_WORKAREA

    V$SQL_PLAN_STATISTICS V$SQL_PLAN_STATISTICS_ALL

  • 8/4/2019 Forgotten Features

    22/94

    2005 Julian Dyke juliandyke.com22

    V$SQL_PLAN

    ADDRESS RAW(4)

    HASH_VALUE NUMBERCHILD_NUMBER NUMBEROPERATION VARCHAR2(30)OPTIONS VARCHAR2(30)OBJECT_NODE VARCHAR2(10)OBJECT# NUMBER

    OBJECT_OWNER VARCHAR2(30)OBJECT_NAME VARCHAR2(64)OPTIMIZER VARCHAR2(20)ID NUMBERPARENT_ID NUMBERDEPTH NUMBERPOSITION NUMBER

    COST NUMBERCARDINALITY NUMBER

    BYTES NUMBEROTHER_TAG VARCHAR(35)PARTITION_START VARCHAR2(5)PARTITION_STOP VARCHAR2(5)PARTITION_ID NUMBEROTHER VARCHAR2(4000)DISTRIBUTION VARCHAR2(20)CPU_COST NUMBERIO_COST NUMBERTEMP_SPACE NUMBERACCESS_PREDICATES VARCHAR2(4000)

    FILTER_PREDICATES VARCHAR2(4000)PROJECTION VARCHAR2(4000)TIME NUMBERQBLOCK_NAME VARCHAR2(31)REMARKS VARCHAR2(4000)

  • 8/4/2019 Forgotten Features

    23/94

    2005 Julian Dyke juliandyke.com23

    Optimizer Environment Variables In Oracle 10.1 and above, optimizer environment variables are

    externalized at :

    instance level - V$SYS_OPTIMIZER_ENV

    session level - V$SES_OPTIMIZER_ENV

    statement level - V$SQL_OPTIMIZER_ENV

    Use the values in these views when determining whyexecution plans differ

  • 8/4/2019 Forgotten Features

    24/94

    2005 Julian Dyke juliandyke.com24

    Optimizer Environment Variables Optimizer Environment Variable values reported by the

    dynamic performance views include:

    active_instance_count parallel_dml_mode

    bitmap_merge_area_size parallel_execution_enabled

    cpu_count parallel_query_mode

    cursor_sharing parallel_threads_per_cpu

    db_file_multiblock_read_count pga_aggregate_target

    hash_area_size query_rewrite_enabled

    optimizer_dynamic_sampling query_rewrite_integrity

    optimizer_features_enable skip_unusable_indexes

    optimizer_index_caching sort_area_retained_size

    optimizer_index_cost_adj sort_area_size

    optimizer_mode star_transformation_enabled

    optimizer_mode_hinted statistics_level

    parallel_ddl_mode workarea_size_policy

  • 8/4/2019 Forgotten Features

    25/94

    2005 Julian Dyke juliandyke.com25

    DBMS_XPLAN Introduced in Oracle 9.2

    Formats PLAN_TABLE contents generated by EXPLAIN PLAN

    SELECT * FROM TABLE (dbms_xplan.display);

    DISPLAY function parameters include

    TABLE_NAME name of plan table

    STATEMENT_ID statement ID in plan table FORMAT as below

    Value Description

    BASIC Operation ID, object name and operation/option only

    TYPICAL (Default) Most relevant information including partitionpruning, parallelism and predicates where appropriate

    ALL As TYPICAL plus parallel execution server statements

    SERIAL As TYPICAL without parallel execution server statements

  • 8/4/2019 Forgotten Features

    26/94

    2005 Julian Dyke juliandyke.com26

    DBMS_XPLAN For example explain a query

    EXPLAIN PLAN FORSET STATEMENT_ID = 'STATEMENT1' FORSELECT t1.c2, t2.c2FROM t1, t2WHERE t1.c1 = t2.c1AND t1.c2 = 10;

    SELECT * FROMTABLE(

    dbms_xplan.display ('PLAN_TABLE','STATEMENT1'));

    The plan table can be queried using

  • 8/4/2019 Forgotten Features

    27/94

    2005 Julian Dyke juliandyke.com27

    DBMS_XPLAN Example output with predicates

    Id Operation Name Rows Bytes Cost

    0 SELECT STATEMENT 10 590 66

    * 1 HASH JOIN 10 590 66

    * 2 TABLE ACCESS FULL T1 10 60 58

    3 TABLE ACCESS FULL T2 1000 53000 7

    Predicate Information (identified by operation id):

    1 - access("T1"."C1"="T2"."C1")2 - filter("T1"."C2"=10)

  • 8/4/2019 Forgotten Features

    28/94

  • 8/4/2019 Forgotten Features

    29/94

    2005 Julian Dyke juliandyke.com29

    DBMS_XPLAN Example output for parallel execution

    Id Operation Name Rows Bytes Cost TQ IN-OUT PQ Distrib

    0 SELECT STATEMENT 10 590 79

    1 MERGE JOIN 10 590 79 78,02 P->S QC(RANDOM)

    2 SORT JOIN 10 60 33 78,02 PCWP

    * 3 TABLE ACCESS FULL T1 10 60 29 78,01 P->P HASH* 4 SORT JOIN 1000 53000 47 78,02 PCWP

    5 TABLE ACCESS FULL T2 1000 53000 7 78,00 S->P HASH

    Predicate Information (identified by operation id):

    3 - filter("T1"."C2"=10)4 - access("T1"."C1"="T2"."C1")

    filter("T1"."C1"="T2"."C1")

  • 8/4/2019 Forgotten Features

    30/94

    2005 Julian Dyke juliandyke.com30

    DBMS_XPLAN Partition pruning information can also be included e.g. for a

    range partitioned table

    EXPLAIN PLAN FORSELECT c2 FROM t1

    WHERE c1 >= 150 AND c1 < 250;

    CREATE TABLE t1 (c1 NUMBER,c2 NUMBER,c3 CHAR(50))PARTITION BY RANGE (c1)(

    PARTITION p1 VALUES LESS THAN (100),PARTITION p2 VALUES LESS THAN (200),

    PARTITION p3 VALUES LESS THAN (300),PARTITION p4 VALUES LESS THAN (400));

    SELECT * FROM TABLE (dbms_xplan.display);

  • 8/4/2019 Forgotten Features

    31/94

    2005 Julian Dyke juliandyke.com31

    DBMS_XPLAN Example output for partition pruning

    Id Operation Name Rows Bytes Cost PStart PStop

    0 SELECT STATEMENT 1 26 2

    1 PARTITION RANGE ITERATOR 2 3

    * 2 TABLE ACCESS FULL T1 1 26 2 2 3

    Predicate Information (identified by operation id):

    2 - filter("T1"."C1">=150 AND "T1"."C1"

  • 8/4/2019 Forgotten Features

    32/94

    2005 Julian Dyke juliandyke.com32

    DBMS_XPLAN In Oracle 10.1 and above

    New DISPLAY_CURSOR function

    By default displays plan for last statement executed insession

    SQL> SELECT COUNT(*) FROM t1;

    SQL > SELECT * FROM TABLE (dbms_xplan.display_cursor);

    Id Operation Name Rows Cost (%CPU) Time

    0 SELECT STATEMENT 160 (100)

    1 SORT AGGREGATE 1

    2 TABLE ACCESS FULL T1 51809 160 (2) 00:00:02

  • 8/4/2019 Forgotten Features

    33/94

    2005 Julian Dyke juliandyke.com33

    V$SESSION_WAIT_HISTORY Introduced in Oracle 10.1

    SID NUMBERSEQ# NUMBEREVENT NUMBEREVENT VARCHAR2(64)P1TEXT VARCHAR2(64)P1 NUMBERP2TEXT VARCHAR2(64)P2 NUMBERP3TEXT VARCHAR2(64)P3 NUMBERWAIT_TIME NUMBERWAIT_COUNT NUMBER

    Externalises last 10 wait events for each session

    Similar information to V$SESSION_WAIT but much moreuser friendly

  • 8/4/2019 Forgotten Features

    34/94

    2005 Julian Dyke juliandyke.com34

    Administration

  • 8/4/2019 Forgotten Features

    35/94

    2005 Julian Dyke juliandyke.com35

    Kill Session For example to kill a session for user US01

    Identify the SID and serial number

    SELECT sid, serial#FROM v$sessionWHERE username = US01;

    Kill the session using

    ALTER SYSTEM KILL SESSION ,;

    For example

    ALTER SYSTEM KILL SESSION 133,523;

    Next command issued by killed session will return error

    ORA-00028: your session has been killed

  • 8/4/2019 Forgotten Features

    36/94

    2005 Julian Dyke juliandyke.com36

    Renaming Database Objects To rename a table:

    RENAME oldname TO newname;

    In Oracle 9.2 and above to rename a columnALTER TABLE t1 RENAME COLUMN oldname TO newname;

    ALTER TABLE t1 RENAME CONSTRAINT oldname TO newname;

    In Oracle 10.1 and above to rename a tablespace

    ALTER TABLESPACE oldname RENAME TO newname;

    In Oracle 9.2 and above to rename a constraint

    To rename an index

    ALTER INDEX oldname RENAME TO newname;

  • 8/4/2019 Forgotten Features

    37/94

    2005 Julian Dyke juliandyke.com37

    Dropping Columns Introduced in 8.1.5

    Columns can be dropped from a table using the ALTERTABLE statement

    Columns can be

    marked unused immediately and deleted at a later time deleted immediately

    If the delete operation fails at any point it can be restartedfrom the point of failure

  • 8/4/2019 Forgotten Features

    38/94

    2005 Julian Dyke juliandyke.com38

    Dropping Columns To drop a column immediately use

    ALTER TABLE table1 DROP COLUMN column2;

    Columns can also be marked unused immediatelyand subsequently dropped

    To mark a column unused use

    ALTER TABLE table1 SET UNUSED COLUMN column2;

    ALTER TABLE table1 DROP UNUSED COLUMNS;

    To drop all unused columns from a table use

  • 8/4/2019 Forgotten Features

    39/94

    2005 Julian Dyke juliandyke.com39

    Dropping Columns If instance is shutdown while column is being dropped, drop

    column statement can be continued when instance restarted

    ALTER TABLE table1 DROP COLUMNS CONTINUE;

    DBA_PARTIAL_DROP_TABS describes partially dropped columns

    DBA_UNUSED_COL_TABS describes columns marked unused,but not yet dropped

  • 8/4/2019 Forgotten Features

    40/94

    2005 Julian Dyke juliandyke.com40

    Default Tablespaces In Oracle 9.0.1 and above a default temporary tablespace can

    be defined

    ALTER DATABASEDEFAULT TEMPORARY TABLESPACE ;

    In Oracle 10.1 and above a default permanent tablespace canbe defined

    ALTER DATABASEDEFAULT TABLESPACE ;

  • 8/4/2019 Forgotten Features

    41/94

    2005 Julian Dyke juliandyke.com41

    Resumable Statements Oracle 9.0.1 and above long running operations encountering

    out of space errors can be resumed

    Resumable operations include

    Queries

    DML Statements

    SQL*Loader operations Import operations

    DDL statements

    Out of space errors include

    Tablespace full

    Maximum number of extents reached for object

    Tablespace quota exceeded for a user

  • 8/4/2019 Forgotten Features

    42/94

    2005 Julian Dyke juliandyke.com42

    Resumable Statements When resumable space allocation is enabled

    Operation suspends if an out of space error occurs

    Details of the error are written to DBA_RESUMABLE

    DBA can optionally be alerted

    DBA can either

    fix the error

    abort the operation Operation automatically resumes execution when error is

    fixed

    If a further error is detected, operation will suspend again

  • 8/4/2019 Forgotten Features

    43/94

    2005 Julian Dyke juliandyke.com43

    Resumable Statements1 Resumable space allocation is enabled

    ALTER SESSION ENABLE RESUMABLENAME Batch Update TIMEOUT 3600;

    2 Resumable operation starts

    INSERT INTO t2SELECT * FROM t1;

    3 Out of space error occurs

    ORA-01653: unable to extend table US01.T2 by 210 in tablespaceTS99

    4 Error is written to alert log

  • 8/4/2019 Forgotten Features

    44/94

    2005 Julian Dyke juliandyke.com44

    Resumable Statements

    5 (Optional) DBA is notified by message generated by

    AFTER SUSPEND trigger

    6 DBA queries DBA_RESUMABLE view for details ofsuspended operation

    7 DBA fixes error condition e.g.

    ALTER TABLESPACE TS99ADD DATAFILE SIZE ;

    8 Suspended operation resumes automatically

    9 Operation completes successfully

  • 8/4/2019 Forgotten Features

    45/94

    2005 Julian Dyke juliandyke.com45

    Resumable Statements In Oracle 10.1 and above resumable statements can be

    enabled at instance level

    ALTER SYSTEMSET resumable_timeout = ;

    Resumable statements can be disabled at instance level using

    ALTER SYSTEMSET resumable_timeout = 0;

    Resumable statements can be enabled at session level using

    ALTER SESSIONSET resumable_timeout = ;

    Resumable statements can be disabled at session level using

    ALTER SESSIONSET resumable_timeout = 0;

  • 8/4/2019 Forgotten Features

    46/94

    2005 Julian Dyke juliandyke.com46

    Automatic Datafile Deletion In Oracle 9.0.1 and above, DROP TABLESPACE has been

    extended to optionally delete its datafiles

    DROP TABLESPACE tablespace_nameINCLUDING CONTENTS AND DATAFILES;

    The DROP TABLESPACE command automatically deletesOracle Managed Files

  • 8/4/2019 Forgotten Features

    47/94

    2005 Julian Dyke juliandyke.com47

    Database Level Backups In Oracle 10.1 and above to enable/disable backup mode for

    all tablespaces in single statement use:

    Useful with three-way mirror or snapshot backups

    ALTER DATABASE BEGIN BACKUP;ALTER DATABASE END BACKUP;

    In Oracle 9.2 to disable backup mode for all tablespacesfollowing a database restart use:

    ALTER DATABASE END BACKUP;

  • 8/4/2019 Forgotten Features

    48/94

    2005 Julian Dyke juliandyke.com48

    Tables

  • 8/4/2019 Forgotten Features

    49/94

    2005 Julian Dyke juliandyke.com49

    Row Movement

    In Oracle 8.0 updating the partition key columns in a rangepartitioned table fails if it would cause the row to be migrated toanother partition

    ORA-14402: updating partition key column would cause a partition change

    In Oracle 8.1.5 and above row movement can be enabled a row may be migrated to another partition if its partition key

    columns are updated

    By default row movement is disabled

  • 8/4/2019 Forgotten Features

    50/94

    2005 Julian Dyke juliandyke.com50

    Row Movement

    ALTER TABLE table1 ENABLE ROW MOVEMENT;ALTER TABLE table1 DISABLE ROW MOVEMENT;

    Row movement can be enabled when the partitioned table iscreated e.g.

    CREATE TABLE table1(

    column1 NUMBER,column2 NUMBER

    )PARTITION BY .ENABLE ROW MOVEMENT;

    Row movement can be also be enabled and disabled from anexisting table e.g.

  • 8/4/2019 Forgotten Features

    51/94

    2005 Julian Dyke juliandyke.com51

    External Tables External tables

    read-only tables

    definition is stored in data dictionary

    data is stored outside the database in operating system flatfiles

    can be queried using SQL

    can be queried in parallel can be included in DML statement subqueries

    No DML operations are allowed on external table

    No indexes can be created on external table

    E l T bl

  • 8/4/2019 Forgotten Features

    52/94

    2005 Julian Dyke juliandyke.com52

    External Tables Example

    CREATE DIRECTORY ext_dir AS '/v01/external';

    CREATE TABLE transactions(

    account NUMBER,value NUMBER

    )ORGANIZATION EXTERNAL(

    TYPE ORACLE_LOADERDEFAULT DIRECTORY ext_dirACCESS PARAMETERS(

    RECORDS DELIMITED BY NEWLINEFIELDS TERMINATED BY ,

    )LOCATION (transactions.csv)

    );

    E l T bl

  • 8/4/2019 Forgotten Features

    53/94

    2005 Julian Dyke juliandyke.com53

    External Tables The following tests were based on a 1,000,000 row flat file.

    Each row contained 74 bytes of data and 4 bytes of separators

    Tests were performed in NOARCHIVING and ARCHIVINGmodes

    Description Time in seconds

    NoArchiving Archiving

    Use SQL*Loader with CONVENTIONAL path load toINSERT rows

    318 322

    Use SQL*Loader with DIRECT load to INSERT rows 28 285

    Use CREATE TABLE AS SELECT to copy data from

    external table to internal table

    20 290

    Use CREATE TABLE AS SELECT to copy data frominternal table to internal table

    15 283

    D S C i

  • 8/4/2019 Forgotten Features

    54/94

    2005 Julian Dyke juliandyke.com54

    Data Segment Compression Introduced in Oracle 9.2

    Data is compressed when it is written to a block decompressed when it is read from the block

    Compression is applied at block level

    Blocks will only be compressed if data is sufficiently large to fill the block rows have low enough cardinality

    Columns can be reordered within each block to achieveoptimal compression ratios

    A segment may contain compressed and uncompressedblocks

    D t S t C i

  • 8/4/2019 Forgotten Features

    55/94

    2005 Julian Dyke juliandyke.com55

    Data Segment Compression Compression can be specified for new tables

    CREATE TABLE t1 (c01 NUMBER,c02 VARCHAR2(30)) COMPRESS;

    Compression can also be specified for existing tables

    ALTER TABLE t2 COMPRESS;

    Existing tables can be compressed using

    ALTER TABLE t3 MOVE COMPRESS;

    Compression can also be specified for

    range and list partitioned tables

    materialized views nested tables

    D t S t C i

  • 8/4/2019 Forgotten Features

    56/94

    2005 Julian Dyke juliandyke.com56

    Data Segment Compression Only works with direct path inserts

    For example

    CREATE TABLE AS SELECT

    INSERT /*+ APPEND */

    ALTER TABLE MOVE

    Materialized View Refresh SQL*Loader

    Online Reorganization

    Does not work with INSERT /*+ NOAPPEND */

    UPDATE

    DELETE

    D t S t C i

  • 8/4/2019 Forgotten Features

    57/94

    2005 Julian Dyke juliandyke.com57

    Data Segment Compression

    1993Ayrton Senna4

    1996Olivier PanisLigier

    19943 2

    19953 2

    19971 2

    20024 0

    20011 220004 0

    19991 2

    19984 Mika Hakkinen

    SymbolTable

    RowData

    2 David Coulthard0

    3 Ferrari1

    5 Michael Schumacher2Benetton3 2

    4 4 McLaren

    Year Driver Team

    1993 Ayrton Senna McLaren

    1994 Michael Schumacher Benetton

    1995 Michael Schumacher Benetton

    1996 Olivier Panis Ligier

    1997 Michael Schumacher Ferrari

    1998 Mika Hakkinen McLaren

    1999 Michael Schumacher Ferrari

    2000 David Coulthard McLaren

    2001 Michael Schumacher Ferrari

    2002 David Coulthard McLaren

    Monaco Grand PrixWinners 1993-2002

    D t S t C i

  • 8/4/2019 Forgotten Features

    58/94

    2005 Julian Dyke juliandyke.com58

    Data Segment Compression Compression ratios vary with

    number of rows

    number of columns

    cardinality of rows

    For example loading SALES table from sales history demoschema

    $ORACLE_HOME/demo/schema/sales_history

    BlockSize

    UncompressedSize (Blocks)

    CompressedSize (Blocks)

    Ratio %

    2048 18777 13433 71.5

    4096 8983 6106 68.0

    8192 4398 2850 64.7

    16384 2179 1353 62.0

    Table contains 1016271 rows

    D t S t C i

  • 8/4/2019 Forgotten Features

    59/94

    2005 Julian Dyke juliandyke.com59

    Data Segment Compression Test1 Loading the SALES table from a flat file into an empty

    table

    Compressed Blocks ElapsedTIme (Secs)

    CPU Time(Secs)

    No 4398 31.77 4.13

    Yes 2850 71.08 43.86

    Test2 Selecting one column from all rows in the compressedtable

    SELECT SUM (quantity_sold) FROM sales;

    Compressed Blocks ElapsedTIme (Secs) CPU Time(Secs)

    No 4398 3.41 2.77

    Yes 2850 3.78 3.53

  • 8/4/2019 Forgotten Features

    60/94

    2005 Julian Dyke juliandyke.com60

    Indexes

    Inde Leaf Compression

  • 8/4/2019 Forgotten Features

    61/94

    2005 Julian Dyke juliandyke.com61

    Index Leaf Compression Introduced in Oracle 8.1.5

    Compresses leading columns in index

    Must be specified when index is created or rebuilt

    CREATE INDEX i1 ON t1 (c1, c2, c3) COMPRESS 2;

    ALTER INDEX i1 REBUILD ONLINE COMPRESS 1;

    Benefits

    Reduces number of blocks to hold index

    Reduction in physical I/O for scans

    Improved cache efficiency

    Potential reduction in index height

    CBO more likely to use index

    Index Leaf Compression

  • 8/4/2019 Forgotten Features

    62/94

    2005 Julian Dyke juliandyke.com62

    Index Leaf Compression

    Country City

    France Paris

    Germany Berlin

    Germany Frankfurt

    Germany Munich

    Italy Milan

    Italy Rome

    Suffix Slot Array

    Prefix Slot Array

    1600 120013001400 9001000

    15001700 11001 4 6

    1700

    1500

    1400

    1300

    1200

    1100

    1600

    1000

    900

    France

    Paris

    Germany

    Berlin

    Frankfurt

    Munich

    ItalyMilan

    Rome

    Prefix Row

    Prefix Row

    Prefix Row

    Suffix Row

    Suffix Row

    Suffix Row

    Suffix Row

    Suffix Row

    Suffix RowCREATE INDEX i1ON TABLE t1 (country, city)COMPRESS 1;

    Index Leaf Compression

  • 8/4/2019 Forgotten Features

    63/94

    2005 Julian Dyke juliandyke.com63

    Index Leaf Compression Number and size of prefixed rows can be verified using

    Useful INDEX_STATS columns include

    PRE_ROWS

    Number of prefix rows PRE_ROWS_LEN

    Sum of lengths of all prefix rows

    OPT_CMPR_COUNT

    Optimal key compression length

    OPT_CMPR_PCTSAVE

    Space saved by implementing optimal key length

    ANALYZE INDEX i1 VALIDATE STRUCTURE;SELECT * FROM index_stats;

    Index Leaf Compression

  • 8/4/2019 Forgotten Features

    64/94

    2005 Julian Dyke juliandyke.com64

    Index Leaf Compression Can also be used with IOTs

    CREATE TABLE t1(

    c1 NUMBER,c2 NUMBER,c3 NUMBER,c4 NUMBERCONSTRAINT pk1 PRIMARY KEY (c1,c2,c3)

    )ORGANIZATION INDEXCOMPRESS 2;

    ALTER TABLE t1 MOVE COMPRESS 1;

    To rebuild existing IOT

    Index Rebuild Online

  • 8/4/2019 Forgotten Features

    65/94

    2005 Julian Dyke juliandyke.com65

    Index Rebuild Online

    Introduced in 8.1.5

    create or rebuild index whilst allowing concurrent DMLoperations

    Works with

    B*tree indexes (non-partitioned and partitioned) 8.1.5

    IOTs (non-partitioned and partitioned) 8.1.5

    Reverse key indexes 9.0.1

    Function-based indexes 9.0.1

    Compressed indexes 9.0.1

    IOT Secondary indexes 9.0.1

    Index Rebuild Online

  • 8/4/2019 Forgotten Features

    66/94

    2005 Julian Dyke juliandyke.com66

    Index Rebuild Online To build an index online use

    ALTER INDEX index1 REBUILD ONLINE;

    Can be executed in parallel

    Three phases

    prepare phase index created

    data dictionary updated

    build phase

    index populated

    changes written to journal tablemerge phase

    rows in journal table are merged

    ANALYZE INDEX ONLINE

  • 8/4/2019 Forgotten Features

    67/94

    2005 Julian Dyke juliandyke.com67

    ANALYZE INDEX ONLINE Prior to Oracle 9.0.1, index structure can be analyzed using

    ANALYZE INDEX index_nameVALIDATE STRUCTURE;

    No DML possible against index while it is being analyzed

    In Oracle 9.0.1 and above indexes can be analyzed online

    ANALYZE INDEX index_nameVALIDATE STRUCTURE ONLINE;

    DML statements unaffected

    Index Monitoring

  • 8/4/2019 Forgotten Features

    68/94

    2005 Julian Dyke juliandyke.com68

    Index Monitoring In Oracle 9.0.1 indexes can be monitored to determine if they

    are being used

    If index monitoring is enabled for an index, then Oracleupdates a table in the data dictionary when that index isincluded in an execution plan by the parser

    Indexes are only monitored at parse time

    Only SELECT statements and subqueries monitored

    Also works for bitmap indexes

    Index Monitoring

  • 8/4/2019 Forgotten Features

    69/94

    2005 Julian Dyke juliandyke.com69

    Index Monitoring

    SELECT index_name,monitoringFROM v$object_usage;

    This example assumes the following definitions

    ALTER INDEX index1 MONITORING USAGE;ALTER INDEX index2 MONITORING USAGE;

    CREATE TABLE table1 (col1 NUMBER, col2 NUMBER);CREATE INDEX index1 ON table1 (col1);CREATE INDEX index2 ON table1 (col2);

    Enable index monitoring using

    To check which indexes are being monitored use

    INDEX_NAME MONITORING

    INDEX1 YES

    INDEX2 YES

    Index Monitoring

  • 8/4/2019 Forgotten Features

    70/94

    2005 Julian Dyke juliandyke.com70

    Index Monitoring Execute all possible statements against the table

    SELECT index_name,usedFROM v$object_usage;

    ALTER INDEX index1 NOMONITORING USAGE;ALTER INDEX index2 NOMONITORING USAGE;

    SELECT /*+ INDEX (table1 index1) */ * FROM table1WHERE col1 = 0;

    Check which indexes have been used using

    Disable index monitoring using

    INDEX_NAME USED

    INDEX1 YES

    INDEX2 NO

    Create Index NOSORT

  • 8/4/2019 Forgotten Features

    71/94

    2005 Julian Dyke juliandyke.com71

    Create Index NOSORT Specify the NOSORT option to avoid sorting index columns

    when creating an index

    CREATE INDEX index1 ON table1 (column1) NOSORT

    If columns are not in sorted order then index creation will failwith the following error:

    ORA-01409: NOSORT option may not be used;rows are not in ascending order

    Create Index Compute Statistics

  • 8/4/2019 Forgotten Features

    72/94

    2005 Julian Dyke juliandyke.com72

    Create Index Compute Statistics Introduced in Oracle 8.1.5

    To compute statistics when creating an index use:

    CREATE INDEX index1 ON table1 (column1) COMPUTE STATISTICS;

    Statistics will be computed (not estimated)

    If the index is composite, statistics only generated for leadingcolumn

    If the index is non-partitioned, table, column and indexstatistics are gathered

    If the index is partitioned only index statistics are gathered

    To compute statistics when rebuilding an index use:

    ALTER INDEX index1 REBUILD COMPUTE STATISTICS;

    Global Index Maintenance

  • 8/4/2019 Forgotten Features

    73/94

    2005 Julian Dyke juliandyke.com73

    Global Index Maintenance In Oracle 9.0.1 and above UPDATE GLOBAL INDEXES can be

    specified for DDL statements on partitioned tables

    Global indexes remain available during the operation

    Updates to the global index are logged

    UPDATE GLOBAL INDEXES can be used with the following

    partition DDL statements

    ALTER TABLE table1DROP PARTITION table1_p1UPDATE GLOBAL INDEXES;

    ADD SPLIT

    DROP MERGE

    MOVE EXCHANGE

    TRUNCATE COALESCE

    For example

  • 8/4/2019 Forgotten Features

    74/94

    2005 Julian Dyke juliandyke.com74

    Undo

    andRedo

    Global Temporary Tables

  • 8/4/2019 Forgotten Features

    75/94

    2005 Julian Dyke juliandyke.com75

    Global Temporary Tables Introduced in Oracle 8.1.5

    Defined in data dictionary definition available to all sessions

    Data

    only visible to current session

    retained for duration of current transaction or session stored in users sort space

    can overflow to sort segment in users temporary

    tablespace

    Indexes

    can be created against global temporary tables

    same scope and duration

    Global Temporary Tables

  • 8/4/2019 Forgotten Features

    76/94

    2005 Julian Dyke juliandyke.com76

    Global Temporary Tables

    Can define triggers and views

    Views cannot join permanent and temporary tables

    Benefits

    Reduction in DDL

    Reduction in amount of redo generated

    DML statements against global temporary tables

    Generate undo

    Generate redo for undo

    Do not generate redo for block changes

    Global Temporary Tables

  • 8/4/2019 Forgotten Features

    77/94

    2005 Julian Dyke juliandyke.com77

    Global Temporary Tables ON COMMIT DELETE ROWS

    rows are only visible to the current transaction

    CREATE GLOBAL TEMPORARY TABLE temp1 (column1 NUMBER)ON COMMIT DELETE ROWS;

    INSERT INTO temp1 VALUES (1);

    SELECT * FROM temp1;Column11

    COMMIT;

    SELECT * FROM temp1;

    No rows returned

    Global Temporary Tables

  • 8/4/2019 Forgotten Features

    78/94

    2005 Julian Dyke juliandyke.com78

    Global Temporary Tables ON COMMIT PRESERVE ROWS

    rows are visible throughout current session

    CREATE GLOBAL TEMPORARY TABLE temp2 (column1 NUMBER)ON COMMIT PRESERVE ROWS;

    INSERT INTO temp2 VALUES (1);

    SELECT * FROM temp2;

    Column11

    COMMIT;

    SELECT * FROM temp2;

    Column11

    Guaranteed Undo Retention

  • 8/4/2019 Forgotten Features

    79/94

    2005 Julian Dyke juliandyke.com79

    Guaranteed Undo Retention Introduced in Oracle 10.1

    To specify that unexpired undo should be preserved in all

    undo segments even if this makes current operationsrequiring undo space fail use

    Only applies to undo tablespaces

    Useful while flashback queries are running

    To specify default behaviour use

    ALTER TABLESPACE tablespace_nameRETENTION GUARANTEE;

    ALTER TABLESPACE tablespace_nameRETENTION NOGUARANTEE;

    Enabling NOLOGGING

  • 8/4/2019 Forgotten Features

    80/94

    2005 Julian Dyke juliandyke.com80

    Enabling NOLOGGING UNRECOVERABLE clause introduced in Oracle 7.3

    NOLOGGING clause introduced in Oracle 8.0

    Enabled at object level

    ALTER TABLE table NOLOGGING ;

    Can be used by

    SQL*Loader direct loads CREATE TABLE direct loads

    CREATE INDEX direct loads

    INSERT /*+ APPEND */

    INSERT LOB NOCACHE

    Writes reduced redo

    Cannot be recovered

    CREATE INDEX index1 ON table1(column1) NOLOGGING;

    Disabling NOLOGGING

  • 8/4/2019 Forgotten Features

    81/94

    2005 Julian Dyke juliandyke.com81

    Disabling NOLOGGING If NOLOGGING option is specified

    Limited redo is written

    Changes cannot be recovered

    Changes cannot be transported to standby database

    In Oracle 9.2 and above NOLOGGING can be disabled

    At database levelALTER DATABASE FORCE LOGGING ;ALTER DATABASE NO FORCE LOGGING;

    ALTER TABLESPACE tablespace_name FORCE LOGGING ;ALTER TABLESPACE tablespace_name NO FORCE LOGGING;

    At tablespace level

  • 8/4/2019 Forgotten Features

    82/94

    2005 Julian Dyke juliandyke.com82

    PL/SQL

    Native Dynamic SQL

  • 8/4/2019 Forgotten Features

    83/94

    2005 Julian Dyke juliandyke.com83

    Native Dynamic SQL Prior to Oracle 8.1.5 PL/SQL DDL statements were executed

    using DBMS_SQL package

    DECLAREl_cursor INTEGER;l_result INTEGER;

    BEGINl_cursor := DBMS_SQL.OPEN_CURSOR;

    DBMS_SQL.PARSE (l_cursor,ALTER SYSTEM SWITCH LOGFILE,DBMS_SQL.V7);

    l_result := DBMS_SQL.EXECUTE (l_cursor);

    DBMS_SQL.CLOSE_CURSOR (l_cursor);END;

    Native Dynamic SQL

  • 8/4/2019 Forgotten Features

    84/94

    2005 Julian Dyke juliandyke.com84

    Native Dynamic SQL

    In Oracle 8.1.5 and above EXECUTE IMMEDIATE can execute DDLstatements

    EXECUTE IMMEDIATE 'INSERT INTO tab1 (c1,c2) VALUES (1,10)';EXECUTE IMMEDIATE 'UPDATE tab1 SET c1 = 4 WHERE c2 = 10';EXECUTE IMMEDIATE 'DELETE FROM tab1 WHERE c2 = 10';

    EXECUTE IMMEDIATE can also execute DML statements

    EXECUTE IMMEDIATE 'CREATE TABLE tab1 (c1 NUMBER)';EXECUTE IMMEDIATE 'ALTER TABLE tab1 ADD (c2 NUMBER)';EXECUTE IMMEDIATE DROP TABLE tab1;

    Native Dynamic SQL

  • 8/4/2019 Forgotten Features

    85/94

    2005 Julian Dyke juliandyke.com85

    Native Dynamic SQL EXECUTE IMMEDIATE can also be used for SELECT

    statements

    INTO clause is used to define fetch variables

    For example

    DECLAREl_c1 NUMBER;l_str VARCHAR2(1000);

    BEGINl_str := 'SELECT c0l1 FROM tab1 WHERE c2 = 20';

    EXECUTE IMMEDIATE l_str INTO l_c1;

    DBMS_OUTPUT.PUT_LINE ('Result is || l_c1);END;

    Native Dynamic SQL

  • 8/4/2019 Forgotten Features

    86/94

    2005 Julian Dyke juliandyke.com86

    Native Dynamic SQL EXECUTE IMMEDIATE can also use bind variables

    USING clause is used to specify bind variable positions

    For example

    DECLARE

    l_c1 NUMBER;l_str VARCHAR2(1000);

    BEGINl_str := 'SELECT c1 FROM t1 WHERE c2 = :p1';

    EXECUTE IMMEDIATE l_str INTO l_c0l1 USING 10;DBMS_OUTPUT.PUT_LINE ('Result is '||l_c1);

    EXECUTE IMMEDIATE l_str INTO l_c0l1 USING 30;DBMS_OUTPUT.PUT_LINE ('Result is '||l_c1);

    END;

    Bulk Collect

  • 8/4/2019 Forgotten Features

    87/94

    2005 Julian Dyke juliandyke.com87

    Bulk Collect Introduced in Oracle 8.1.5

    Returns result set in single operation

    Can be used with

    SELECT INTO

    FETCH INTO RETURNING INTO

    Bulk Collect - Example

  • 8/4/2019 Forgotten Features

    88/94

    2005 Julian Dyke juliandyke.com88

    Bulk Collect ExampleDECLARE -- 100000 row table

    l_c3 NUMBER;CURSOR c1 IS SELECT c3 FROM t1;

    BEGINOPEN c1;LOOP

    FETCH c1 INTO l_c3; -- 3.052 secondsEXIT WHEN c1%NOTFOUND;

    END LOOP;CLOSE c1;

    END;DECLARE -- 100000 row table

    TYPE NUMTYPE IS TABLE OF NUMBER(6) INDEX BY BINARY_INTEGER;l_c3 NUMTYPE;CURSOR c1 IS SELECT c3 FROM t1;

    BEGINOPEN c1;

    LOOPFETCH c1 BULK COLLECT INTO l_c3; -- 0.119 secondsEXIT WHEN c1%NOTFOUND;

    END LOOP;CLOSE c1;

    END;

    Bulk Collect Limit Clause

  • 8/4/2019 Forgotten Features

    89/94

    2005 Julian Dyke juliandyke.com89

    Bulk Collect Limit Clause Bulk collect performance improves as optimum result set size

    is approached

    Thereafter bulk collect performance degrades as result setgrows

    In Oracle 8.1.6 and above the number of rows returned byFETCH INTO can be restricted using the LIMIT clause

    FETCH c1 BULK COLLECT INTO l_c3 LIMIT 1000;

    FORALL

  • 8/4/2019 Forgotten Features

    90/94

    2005 Julian Dyke juliandyke.com90

    O Introduced in Oracle 8.1.5

    Sends INSERT, UPDATE or DELETE statements in batches

    Can only repeat single DML statement

    Works with PL/SQL collections including TABLE, VARRAY,NESTED TABLE etc.

    Much faster than equivalent for-loop

    Limited functionality

    FORALL Example

  • 8/4/2019 Forgotten Features

    91/94

    2005 Julian Dyke juliandyke.com91

    pDECLARE

    TYPE NUMTYPE IS TABLE OF NUMBER(6) INDEX BY BINARY_INTEGER;TYPE NAMETYPE IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;l_c1 NUMTYPE;l_c2 NAMETYPE;l_c3 NUMTYPE;

    BEGINFOR i IN 1..100000 LOOP

    l_c1(i) := i;l_c2(i) := LPAD (TO_CHAR (i),30,0);l_c3(i) := MOD (i, 100);

    END LOOP;

    FOR i IN 1..100000 LOOP -- FOR Loop 28 secondsINSERT INTO t1 VALUES (l_c1 (i), l_c2 (i), l_c3(i));

    END LOOP;

    FORALL f IN 1..100000 LOOP -- FORALL Loop 4 secondsINSERT INTO t1 VALUES (l_c1 (i), l_c2 (i), l_c3(i));

    END;

    FORALL Performance

  • 8/4/2019 Forgotten Features

    92/94

    2005 Julian Dyke juliandyke.com92

    Performance of FORALL statement degrades for very largetables

    Rows FOR FORALL

    100000 28 4

    1000000 240 360

    Times in seconds

    Conclusion

  • 8/4/2019 Forgotten Features

    93/94

    2005 Julian Dyke juliandyke.com93

    Every release contains many new features and enhancementsthat are not highlighted in the marketing material

    Oracle assumes all customers will move on to new versionswhen they are released

    Study the New Features documentation when you upgrade

    Thank you for your interest

  • 8/4/2019 Forgotten Features

    94/94

    y y

    For more information and to provide feedbackplease contact me

    My e-mail address is:

    [email protected]

    My website address is:

    www.juliandyke.com


Recommended