Presentation is loading. Please wait.

Presentation is loading. Please wait.

Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes.

Similar presentations


Presentation on theme: "Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes."— Presentation transcript:

1 Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes

2 Semantec Ltd. Agenda Overview Types Storage Selecting an index strategy

3 Semantec Ltd. Overview Create Indexes when selecting a small percentage of rows from a table (less than 2-4%) Indexes are logically and physically independent of the data in the associate table. Required CREATE ANY INDEX system privilege for creating index.

4 Semantec Ltd. Indexing schemes B-tree indexes B-tree cluster indexes Reverse key indexes Bitmap indexes Hash cluster indexes

5 Semantec Ltd. Types Unique and non unique indexes Composite indexes Function-based indexes Application domain indexes

6 Semantec Ltd. Unique and nonunique indexes Oracle recommends that you do not explicitly define unique indexes on tables. Oracle automatically creates index to enforce UNIQUE and PRIMARY KEY integrity constraints.

7 Semantec Ltd. Composite index Example Vend_idPart_NoUnit_cost 101010-440.25 101010-441.50 10124574.95 101210-440.27 122008-3001.19 126212-45765.12 126212-45823.99 CREATE INDEX Vend_idx1 ON Vendor (Vend_id,Part_No); CREATE INDEX Vend_idx2 ON Vendor (Part_No,Vend_id);

8 Semantec Ltd. Composite index Guidelines for creating Create on keys that are frequently used together in WHERE clause conditions combined with AND operators. If several queries select the same set of keys based on one or more key values, then create a composite index containing all of these keys. Consider the guidelines associated with the general performance advantages and trade- offs of all type of indexes.

9 Semantec Ltd. Composite index Guidelines for ordering Create the index so the keys used in WHERE clauses make up a leading portion. Create the index so that the more frequently selected keys make up a leading portion. If all keys are used in WHERE clauses equally often, then ordering these keys from most selective to least selective. If all keys are used in the WHERE clauses equally often but the data is physically ordered on one of the keys, then place that key first in the composite index.

10 Semantec Ltd. Internal structure of indexes B-tree indexes B-tree cluster indexes Reverse key indexes Bitmap indexes Index-organized tables

11 Semantec Ltd. B-tree indexes Storage

12 Semantec Ltd. B-tree indexes Advantages All leaf blocks of the tree are at the same depth. B-tree indexes automatically stay balanced. All blocks of the B-tree are three-quarters full on the average. B-trees provide excellent retrieval performance for a wide range of queries, including exact match and range searches. Inserts, updates, and deletes are efficient, maintaining key order for fast retrieval. B-tree performance is good for both small and large tables, and does not degrade as the size of a table grows.

13 Semantec Ltd. Reverse key indexes Creating a reverse key index, compared to a standard index, reverses the bytes of each column indexed (except the rowid) while keeping the column order. Example: CREATE INDEX i ON t (a,b,c) REVERSE; ALTER INDEX i REBUILD NOREVERSE;

14 Semantec Ltd. Bitmap indexes Example CUSTO MER# MARITAL_ STATUS REGIONGENDERINCOME_ LEVEL 101SingleEastMale1 102MarriedCentralFemale2 103MarriedWestFemale3 104DivorcedCentralFemale1 105MarriedWestMale2 106SingleCentralMale2 Table Customer_data

15 Semantec Ltd. Bitmap indexes Example CREATE BITMAP INDEX ON Customer_data(MARITAL_STATUS, REGION, GENDER); SELECT COUNT(*) FROM Customer_data WHERE MARITAL_STATUS = ’Married’ AND REGION IN (’Central’,’West’);

16 Semantec Ltd. Bitmap indexes Example REGION = ‘East’ REGION = ‘Central’ REGION = ‘West’ 100 010 001 010 001 010

17 Semantec Ltd. REGION = ‘Central’ 0 1 0 1 0 1 REGION = ‘West’ 0 1 0 1 0 Bitmap indexes Example Status = ‘married’ 0 1 0 1 0 011010011010 011111011111 011010011010 AND OR = = AND

18 Semantec Ltd. Bitmap indexes Benefits Reduced response time for large classes of queries Asubstantial reduction of space usage compared to other indexing techniques Dramatic performance gains even on very low end hardware Very efficient parallel DML and loads

19 Semantec Ltd. Function-based indexes Advantages Increase the number of situations where the optimizer can perform a range scan instead of a full table scan. Precompute the value of a computationally intensive function and store it in the index. Create indexes on object columns and REF columns. Create more powerful sorts.

20 Semantec Ltd. Function-based indexes Restrictions Used only by cost-based optimization. A PL/SQL function, used in the index expression must be declared as DETERMINISTIC. Function-based indexes cannot be built on LOB columns, nested tables, or varrays. Expressions used in a function-based index should reference only columns in a row in the table. Hence, these expressions cannot contain any aggregate functions. You must have the initialization parameters COMPATIBLE set to 8.1.0.0.0 or higher, QUERY_REWRITE_ENABLED=TRUE, and QUERY_REWRITE_INTEGRITY=TRUSTED.

21 Semantec Ltd. Function-based indexes Restrictions You must analyze the table or index before the index is used. Bitmap optimizations cannot used descending indexes. Function-based indexes are not used when OR- expansion is done. The index function cannot be marked NOT NULL. To avoid a full table scan, you must ensure that the query cannot fetch null values. Function-based indexes that return VARCHAR2 or RAW data types from a PL/SQL function are not permitted due to length restrictions.

22 Semantec Ltd. Function-based indexes Example CREATE INDEX Idx ON Emp_tab(UPPER(Ename)); SELECT * FROM Emp_tab WHERE UPPER(Ename) like :KEYCOL;

23 Semantec Ltd. Function-based indexes Example CREATE INDEX Idx ON Fbi_tab (A+B*(C-1),A,B); SELECT a FROM Fbi_tab WHERE A+B*(C-1) < 100;

24 Semantec Ltd. Index-organized tables Primary key uniquely identifies a row; primary key must be specified Primary key based access Logical rowid in ROWID pseudocolumn allows building secondary indexes UNIQUE constraint not allowed but triggers are allowed Cannot be stored in a cluster Can contain LOB columns but not LONG columns Distribution and replication not supported

25 Semantec Ltd. Application domain indexes Indextype schema object Domain index (an application-specific index) Application specific operators

26 Semantec Ltd. Selecting an index strategy Creating indexes Alter indexes Dropping indexes

27 Semantec Ltd. Determine whether an index is good Create index, Analyze index, Use EXPLAIN PLAN on your query to see if the optimizer uses it. Is it expensive to maintain? Compare optimizer costs with and without index.

28 Semantec Ltd. Re-creating Indexes Use the ALTER INDEX... REBUILD statement to reorganize or compact an existing index or to change its storage characteristics. The REBUILD statement uses the existing index as the basis for the new one. ALTER INDEX... REBUILD is usually faster than dropping and re-creating an index. It reads all the index blocks using multiblock I/O then discards the branch blocks. A further advantage of this approach is that the old index is still available for queries while the rebuild is in progress.

29 Semantec Ltd. Writing Statements that Avoid Using Indexes You can use the NO_INDEX hint to give the CBO maximum flexibility while disallowing the use of a certain index. You can use the FULL hint to force the optimizer to choose a full table scan instead of an index scan. You can use the INDEX, INDEX_COMBINE, or AND_EQUAL hints to force the optimizer to use one index or a set of listed indexes instead of another.

30 2001, Semantec Ltd. Creating tables with constraints and indexes 1. Create the tables with the constraints. NOT NULL constraints may be unnamed and should be created enabled and validated. All other constraints should be named and should be "created disabled". 2. Load old data into the tables. 3. Create all indexes. 4. Enable novalidate all constraints. Do this to primary keys before foreign keys. 5. Allow users to query and modify data. 6. With a separate ALTER TABLE statement for each constraint, validate all constraints.


Download ppt "Semantec Ltd. Oracle Performance Tuning Boyan Pavlov Indexes Indexes."

Similar presentations


Ads by Google