Oracle DBA Basics 2

download Oracle DBA Basics 2

of 19

Transcript of Oracle DBA Basics 2

  • 8/8/2019 Oracle DBA Basics 2

    1/19

    Overview of Oracle Database 10gOverview of Oracle Database 10g

    Srinivasan.KSrinivasan.K

    [email protected]

    1

  • 8/8/2019 Oracle DBA Basics 2

    2/19

    2

    Agenda

    Oracle Index

    Table Partitions

    Oracle Enterprise Manager

    Analysing SQLQueryplans

  • 8/8/2019 Oracle DBA Basics 2

    3/19

    3

    Oracle Index

    Whatisanindex ?

    An index is a performance-tuning method ofallowing faster retrieval of records.

    An index creates an entry for each value thatappears in the indexed columns.

    By default, Oracle creates B-tree indexes.

    TypesofIndex

    B-Tree index

    Bitmap index

  • 8/8/2019 Oracle DBA Basics 2

    4/19

    4

    Oracle Index

    B-Tree index

    B(inary)-Tree Indexes are used on HIGH CARDINALITYcolumns (i.e. columns which have relatively large numberofdistinct values) or on HIGH SELECTIVITY columns (i.e.columns having the capability to filter-out majority of therows when used in a WHERE clause).

    Examples of high SELECTIVITY columns are Primary keycolumns & columns having relatively less number ofduplicate values.

    For instance, if a table has 1, 00,000 records and one of itsindexed columns have 81,000 distinct values, and then theselectivity of the index is 0.81. Ideal selectivity for anindexed column is 1 (which is true in the case of primarykey indexes).

    '

  • 8/8/2019 Oracle DBA Basics 2

    5/19

    5

    Oracle Index

    Syntax :

    CREATE [UNIQUE] INDEX index_name ON table_name (column1,column2,.column_n);

    For example :

    CREATE INDEX supplier_idx ON supplier(supplier_name);

    Bitmap Index

    A bitmap index is a type of index that uses a string of bits toquickly locate rows in a table

    Bitmap indexes are normally used to index low cardinalitycolumns in a warehouse environment.

    Syntax :

    CREATE BITMAP INDEX on();

    cont'd

  • 8/8/2019 Oracle DBA Basics 2

    6/19

    6

    For example :

    CREATE BITMAP INDEX emp_bitmap_idx

    ON big_emp(sex);

    Table partitions

    Partitioning enables tables and indexes to besubdivided into smaller manageable pieces andthese each small piece is called a "partition".

    From an "Application Development" perspective,

    there is no difference between a partitioned and anon-partitioned table.

    The applicationneednot be modified to access apartitioned table if that application was initiallywritten on a non partitioned tables.

    Cont'd

    Table partitions

  • 8/8/2019 Oracle DBA Basics 2

    7/19

    7

    Table partitions

    Advantagesofusing Partitionsin Table

    Smaller and more manageable pieces ofdata (Partitions)

    Reduced recovery time

    Failure impact is less Faster access ofdata

    Very easy to use.

    TypesofPartitioning Methods:

    Range partitioning

    Hash partitioning

    List partitioning

    cont'd

  • 8/8/2019 Oracle DBA Basics 2

    8/19

    8

    Table partitions

    Range partitioning

    This type of partitioning is useful whendealing with datathat has logical ranges into which it can be distributed

    Range partitions requires scalarnumeric values.

    Performance is best when the data evenly distributesacross the range.

    Forexample :

    CREATE TABLE emp (

    empno NUMBER(4),

    ename VARCHAR2(30),

    sal NUMBER )

    PARTITION BY RANGE(empno) (

    partition e1valueslessthan (1000) tablespace ts1,

    partition e2 valueslessthan (2000) tablespace ts2,

    partition e3valueslessthan (MAXVALUE)tablespace ts3); comt'd

  • 8/8/2019 Oracle DBA Basics 2

    9/19

    9

    Table partitions

    Listpartitioning

    List partitioned is used when you require explicitcontrol over how rows map to partitions.

    Specify a list ofdiscrete values for the partitioning

    column in the description for each partition.List partitioning allows partitioning by non-scalardata.

    Forexample :

    CREATE TABLE myemp_work ( empno NUMBER PRIMARYKEY,

    ename VARCHAR2(30),

    salary NUMBER(8,2),

    deptno NUMBER)

    PARTITION BYLIST (deptno)

    ( PARTITION p10 VALUES (10),

    PARTITION p20 VALUES (20),

  • 8/8/2019 Oracle DBA Basics 2

    10/19

    10

    Table partitions

    Hashpartitioning

    Partitions is based on a hashing algorithm

    Evenly distributing data between the partitions.

    This is typically used where ranges aren't appropriate, i.e.

    customernumber, product ID

    Forexample :

    CREATE TABLE sales_hash

    (salesman_id NUMBER(5),

    salesman_name VARCHAR2(30),

    sales_amount NUMBER(10),week_no NUMBER(2))

    PARTITION BY HASH(salesman_id)

    PARTITIONS4

    STORE IN (data1,data2,data3,data4);

    The preceding statementcreatesatable sales_hash,whichishashpartitioned

    onsalesman_idfield. The tablespace namesare data1,data2,data3,anddata4. Cont'd

  • 8/8/2019 Oracle DBA Basics 2

    11/19

    11

    Oracle Enterprise Manager

    Oracle Enterprise Manager

    Perform administrative tasks such as creating schemaobjects (tablespaces, tables, and indexes).

    Managing user security, backing up and recovering your

    database, and importing and exporting data.

    View performance and status information about thedatabase instance.

    Installationsteps

    Loginasoracle userindbserver. Execute the below

    commands.$ emctlstopdbconsole

    $ emca-deconfig dbcontroldb-reposdrop

    $ emca-config dbcontroldb-reposcreate

    (or)

    $ emca-config dbcontroldb-reposrecreate

    cont'd

  • 8/8/2019 Oracle DBA Basics 2

    12/19

    12

  • 8/8/2019 Oracle DBA Basics 2

    13/19

    13

  • 8/8/2019 Oracle DBA Basics 2

    14/19

    14

    Analysing Query plans

    What is an explain plan ?

    The EXPLAIN PLAN statementdisplays executionplanschosenbythe Oracle optimizerforSELECT, UPDATE,

    INSERT,and DELETE statements.A statement's executionplanisthe sequence ofoperationsOracle performstorunthe statement.

    How to generate an explain plan ? sqlplus "/ assysdba"

    sql > @$ORACLE_HOME/sqlplus/admin/plustrce.sql

    sql > grant PLUSTRACE touser;

    sql > GRANT UNLIMITED TABLESPACE TOuser;

    sql > @?/rdbms/admin/utlxplan.sql

    sql > GRANT ALLON sys.plan_table TOpublic;

    sql > create publicsynonymplan_table forsys.plan_table;

    connuser/user

    setautotrace traceonly explain

    select * from emp;

  • 8/8/2019 Oracle DBA Basics 2

    15/19

  • 8/8/2019 Oracle DBA Basics 2

    16/19

    16

    Analysing Query plans

    Example 2

    EXPLAIN PLAN SET statement_id = 'example_plan2'FORSELECT full_name FROM per_all_people_f

    WHERE full_name LIKE 'Pe%';

    Plan---------------------------------------------

    SELECT STATEMENTTABLE ACCESSBY INDEX ROWID PER_ALL_PEOPLE_FINDEX RANGE SCAN PER_PEOPLE_F_N54

    Thisplanshows executionofaSELECT statement.* Index per_people_f_n54isusedinarange scanoperation.* The table per_all_people_fisaccessedthrough ROWID. ROWIDsareobtainedfromthe index inthe previousstepforkeysthatmeetthe WHEREclause criteria.Whenthe table isaccessed,anyadditionalWHERE clauseconditionsthatcouldnotbe evaluatedduring the range scan (because thecolumnispresentinthe table andnotinthe index)are also evaluated.

    * The SELECT statementreturnsrowssatisfying the WHERE clauseconditions (evaluatedinprevioussteps).

    '

  • 8/8/2019 Oracle DBA Basics 2

    17/19

    17

    Topics/References

    Oracle Index

    ttp://www.lorentzcenter.nl/

    ttp://www.techonthenet.com/

    Table Partitions

    ttp://www.oracle-dba-online.com/

    ttp://www.oracle-base.com/

    Oracle Enterprise Managerttp://download.oracle.com/

    Analysing SQLQueryplans

    ttp://www.oracle-base.com/

  • 8/8/2019 Oracle DBA Basics 2

    18/19

    18

    Q & A

  • 8/8/2019 Oracle DBA Basics 2

    19/19

    19

    THANKS