Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Five Tips to Get the Most Out of Your Indexing

6,300 views

Published on

This is one of the 15 minute "TED" style talk presented as part of the Database Symposium at the ODTUG Kscope18 conference. In this presentation @SQLMaria provides 5 useful tips for getting the most out of indexes in the Oracle Database

Published in: Technology
  • Be the first to comment

Five Tips to Get the Most Out of Your Indexing

  1. 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Five Tips to Get the Most out of Your Indexes 1 Maria Colgan Master Product Manager Oracle Database Server Technologies June 2018 JEFF @SQLMaria
  2. 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | B-Tree Indexes – Available since 5, they are the most common type of index – Goal: minimize time to find small amounts of data – Including function-based, Reverse Key Indexes, & IOTs – One to one mapping, little degradation in retrieval performance as underlying table grows Bitmap Indexes – Available since 7.3, designed for read-mostly workloads – Goal: Improve performance of ad-hoc analytic queries – A single bitmap key entry points to many rows – Multiple indexes can be used together to determine rowids – Bitmap Join indexes replaces need for two table join 2 Text Search Indexes – Available since 8i designed for text retrieval – Goal: Quickly identify large coherent documents – Can index documents of different formats such as MS Word, HTML or plain text – A single entry points to many documents Oracle Offers a Variety of Different Indexing Techniques Root Block leaf Blocks Branch Blocks
  3. 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Reverse Key Indexes • Reverse key indexes physically stores the bytes of the keys in reverse order – CREATE INDEX sales_prod_reverse_idx ON sales(prod_id) REVERSE; • Used to avoid “hot block syndrome” or buffer busy waits – On columns with monotonically increasing values – Eg: sequence populated fields or dates/timestamps • At a cost – Prevents some index range scans as 5 is not stored next to 6 • Equality predicates on non-unique index will use index range scan • Range predicates such as between, <, > etc. may not use index – Additional CPU evident mostly in single user mode, with multi-users you see less overall CPU because you are not spinning on a buffer wait Relieving Index contention
  4. 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Partially Useable Indexes • Enables the creation of local or global indexes on just a subset of partitions • Indexing only the stable partitions (little or no DML) minimizes the impact on ingest performance • Queries accessing data only within the indexed partitions will use the index • Queries that access data only in the non-indexed partitions will do full scan • Queries accessing partitions with and without indexes can take advantage of the query transformation called Table Expansion • Supported by definition on Partition views 4 Relieving Index contention
  5. 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Partially Useable Indexes CREATE TABLE sales(order_status char(6) not null, order_date…) INDEXING ON PARTITION BY LIST (order_status)( PARTITION p1 VALUES(‘OPEN’) INDEXING OFF, PARTITION p2 VALUES(‘CLOSED’)); 5 Relieving Index contention
  6. 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Table Expansion Transformation 6 P1: ORDER_STATUS=‘OPEN’ SELECT * FROM sales WHERE ORDER_DATE between‘2017-01-01’ and ‘2017-12-31’; P2: ORDER_STATUS=‘CLOSED’ P1: Best access path is full table scan SALES P2: Best access path is index scan Local index on ORDER_DATE IDX_SALES: ORDER_DATE
  7. 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Table Expansion Transformation ---------------------------------------------------------------------- | Id | Operation | Name | Pstart| Pstop | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | SORT AGGREGATE | | | | | 2 | VIEW | VW_TE_2 | | | | 3 | UNION-ALL | | | | | 4 | PARTITION RANGE SINGLE | | 1 | 1 | |* 5 | TABLE ACCESS FULL | SALES | 1 | 1 | | 6 | PARTITION RANGE SINGLE | | 2 | 2 | |* 7 | INDEX RANGE SCAN | IDX_SALES | 2 | 2 | ---------------------------------------------------------------------- 5 - access("ORDER_DATE“>=TO_DATE(' 2017-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ORDER_DATE"<=TO_DATE(' 2018-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) filter("ORDER_DATE“>=TO_DATE(' 2017-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ORDER_DATE"<=TO_DATE(' 2018-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) 7 - access("ORDER_DATE“>=TO_DATE(' 2017-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ORDER_DATE"<=TO_DATE(' 2018-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  8. 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Indexing Nulls • Bitmap indexes – always index nulls • B*Tree cluster indexes – always index nulls • B*Tree indexes do not if and only if the entire key is null (all columns) 8 CREATE INDEX i ON t(object_id,0); SELECT * FROM t WHERE object_id is NULL; ------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1445 | 149K| 96 (0)| 00:00:02 | | 1 | TABLE ACCESS BY INDEX ROWID| T | 1445 | 149K| 96 (0)| 00:00:02 | |* 2 | INDEX RANGE SCAN | I | 1445 | | 7 (0)| 00:00:01 | -------------------------------------------------------------------------------------
  9. 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 9 • How do I know which indexes are actually needed? • New DBA_INDEX_USAGE views provide usage histograms and access details for all indexes • Track index usage with no overhead Index Usage Statistics Public
  10. 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Index Usage Statistics 10Public Index entries with no statistics indicate indexes that currently are not being used These are potential candidates to be deleted
  11. 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | INVISIBLE Indexes • Ability to create and maintains an index that the optimizer is blind to – Optimizer can’t use an invisible index as an access method • Easy mechanism to begin the process of removing unused indexes 1. Mark the index invisible ALTER INDEX i INVISIBLE; 2. If no one misses it for a complete business cycle, its safe to drop it • Also useful to test out the benefit of a new index before publishing it 1. Create invisible index CREATE INDEX i ON t(x, object_id) INVISIBLE; 2. Set parameter OPTIMIZER_USE_INVISIBLE_INDEXES to true in 1 session to test ALTER SESSION SET optimizer_use_invisible_indexes=true;
  12. 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Indexes are a critical tool to help improve performance 12 Indexes ORACLE Use them wisely to greatly improve speed of data access ….. …Over use them and you will grind the system to a halt!

×