2675082 Oracle Indexes

Embed Size (px)

Citation preview

  • 8/8/2019 2675082 Oracle Indexes

    1/3

  • 8/8/2019 2675082 Oracle Indexes

    2/3

    Value/Row 1 2 3 4 5 6 7 8 9 10 11 12 13 14

    Analyst 0 0 0 0 0 0 0 1 1 1 0 0 1 0

    Clerk 1 0 0 0 0 0 0 0 0 0 1 1 0 1

    Manager 0 0 0 1 0 1 1 0 0 0 0 0 0 0

    President 0 0 0 0 0 0 0 0 1 0 0 0 0 0

    Saleman 0 1 1 0 1 0 0 0 0 0 0 0 0 0

    Using the above table you can see that rows 1, 4, 6, 7, 11, 12 and 14 would represent a manager and clerk.

    Function Based Index

    Function-Based indexes give the ability to index computed columns and use theses indexes in a query, it allowsyou to have case insensitive searchs or sorts, search complex equations and to extends the SQL language byimplementing your own functions and operators and then searching on them. The main reason to use them are:

    They are easy to implement and provide immediate value They can be used to speed up existing applications without changing the application code or queries.

    There is some work that needs to be done before you can use Function-based indexes

    You must have the privilege QUERY REWRITE to create function-based indexes on tables in your ownschema

    You must have the privilege GLOBAL QUERY REWRITE to create function-based indexes on tables inyour own schema

    Function-based indexes only use the cost based optimiser (CBO) and never the rule base optimiser (RBO)

    Use SUBSTR to constrain return values from user written functions that return VARCHAR2 or RAWtypes. Optionally hide the SUBSTR in a view (preferred).

    For the optimiser to use function-based indexes, the following session or system variables must be set:o QUERY_REWRITE_ENABLED=TRUE (means allow optimiser to rewrite the query to use

    function-based index)o QUERY_REWRITE_INTEGRITY=TRUSTED (means that the optimiser should trust the code

    of the programmer)

    You can enable the above with the ALTER SESSION or at the system level via ALTER SYSTEM or by settingthem in in the init.ora file.

    Function-based indexes will affect the performance of inserts and updates, if you insert or update frequently thismay not be an option for you.

    Application Domain Indexes

    Application domain indexing gives the user the ability to supply new indexing technology. Most people willnever make use of it this particular API to build a new index type. The inetMedia set of functionality,implemented using the Application Domain indexing feature will provide indexing on text, XML documentsand images.

    Hint One

  • 8/8/2019 2675082 Oracle Indexes

    3/3

    if you believe that a child table is getting locked via an un-indexed foreign key and you would like to prove ityou can issue:

    alter table disable table lock;

    Now, any update or delete to the parent table that would cause the table lock will receive:

    ERROR at line1:ORA-00069: cannot accquire lock -- table locks disabled for

    Hint Two

    You will only see index blocks on the FREELIST when the index block is totally empty, only then can the block be reused. This is different to table blocks as table blocks can be on the FREELIST if they contain data.