Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,

Slides:



Advertisements
Similar presentations
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Presented By Akin S Walter-Johnson Ms Principal PeerLabs, Inc
CpSc 3220 File and Database Processing Lecture 17 Indexed Files.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part C Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Hashing and Indexing John Ortiz.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part A Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
1 Overview of Storage and Indexing Yanlei Diao UMass Amherst Feb 13, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
1 Indexing Structures for Files. 2 Basic Concepts  Indexing mechanisms used to speed up access to desired data without having to scan entire.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
1 Physical Data Organization and Indexing Lecture 14.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
CS 8630 Database Administration, Dr. Guimaraes , Physical Design and Performance Class Will Start Momentarily… CS8630 Database Administration.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Database Management 9. course. Execution of queries.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
1 © Prentice Hall, 2002 Chapter 6: Physical Database Design and Performance Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott,
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Module 4 Database SQL Tuning Section 3 Application Performance.
Marwan Al-Namari Hassan Al-Mathami. Indexing What is Indexing? Indexing is a mechanisms. Why we need to use Indexing? We used indexing to speed up access.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
Indexing Database Management Systems. Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files File Organization 2.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata Performance Optimization.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Chap 5. Disk IO Distribution Chap 6. Index Architecture Written by Yong-soon Kwon Summerized By Sungchan IDS Lab
SCALING AND PERFORMANCE CS 260 Database Systems. Overview  Increasing capacity  Database performance  Database indexes B+ Tree Index Bitmap Index 
CS4432: Database Systems II
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Indexes 22 Index Table Key Row pointer … WHERE key = 22.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Practical Database Design and Tuning
Indexing Structures for Files and Physical Database Design
Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed.
CS522 Advanced database Systems
Record Storage, File Organization, and Indexes
CS 540 Database Management Systems
Indexing and hashing.
Database Management System
Choosing Access Path The basic methods.
COMP 430 Intro. to Database Systems
Database Management Systems (CS 564)
Database Performance Tuning and Query Optimization
Indexes … WHERE key = Table Index 22 Row pointer Key Indexes
File organization and Indexing
Chapter 11: Indexing and Hashing
Lecture 12 Lecture 12: Indexing.
Physical Database Design
Practical Database Design and Tuning
Indexing and Hashing Basic Concepts Ordered Indices
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Chapter 11 Database Performance Tuning and Query Optimization
Chapter 11: Indexing and Hashing
Presentation transcript:

Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views, Denormalization Export/Import (drop indexes): defragment Check Locks Separate data by category in proper tablespaces Partition Database Redundant Arrays of Inexpensive Disks (RAID) Redefining Client-Server Architecture Buy Hardware

When to Index Large tables A field that you query by frequently Field with high cardinality (not sex where card. Is only 2) Smaller Fields and Fixed length are preferred. (Obs:Most DBMSs automatically index PK)

Different Type of Indexes B-Trees (traditional) indexes Hash-cluster Bitmap indexes Index-Organized Tables Reverse-Key Indexes

Create Index command Create index on ( ); Create index cidx on orders (cid);

Why do we create an index ? (OLTP x Data Warehouse) A) To speed up query (SELECT) ? B) To speed up data entry (insert/update/delete) ? C) All of the above ?

Indexes (Defaults) Anytime a PK is created, an index is automatically created. Anytime when the type of index is not specificied, the type of index created is a B-Trees.

B-Tree (Balanced Tree) Most popular type of index structure for any programming language or database. When you dont know what to do, the best option is usually a B-Tree. They are flexible and perform well (not very well) in several scenarios. It is really the B+ tree or B* tree

B-Trees (continued) One node corresponds to one block/page (minimum disk I-O). Non-Leaf nodes(n keys, n+1 pointers) Leaf-Nodes (contain n entries, where each entry has an index and a pointer to a data block). Also, each node has a pointer to next node. All leaves are at the same height.

Good Indexing (B-Tree) Candidates Table must be reasonably large Field is queried by frequently Field has a high cardinality (dont index by sex, where the cardinality is 2!!). Badly balanced trees may inhibit performance. Destroying and re-creating index may improve performance.

Bitmap Index Bitmap indexes contain the key value and a bitmap listing the value of 0 or 1 (yes/no) for each row indicating whether the row contains that value or not. May be a good option for indexing fields that have low cardinality (opposite of B- trees).

Bitmap Index (cont.) Syntax: Create Bitmap index …. Bitmap index works better with equality tests = or in (not with ) Bitmap index maintenance can be expensive; an individual bit may not be locked; a single update locks a large portion of index. Bitmap indexes are best in read-only datawarehouse situations

Hash Indexing B-trees and Bitmap index keys are used to find rows requiring I/O to process index Hash gets rows with a key based algorithm Rows are stored based on a hashed value Index size should be known at index creation Example: –create index cidx on orders (cid) hashed;

Hash Index work best with Very-high cardinality columns Only equal (=) tests are used Index values do not change Number of rows are known ahead of time

Index-Organized Tables Table data is incorporated into the B-Tree using the PK as the index. Table data is always in order of PK. Many sorts can be avoided. Especially useful for lookup type tables Index works best when there are few (and small) columns in your table other than the PK.

Reverse Key Indexes Key 1234 becomes 4321, etc. Only efficient for few scenarios envolving parallel processing and a hughe amount of data. By reversing key values, index blocks might be more evenly distributed reducing the likelihood of densely or sparsely populated indexes.

Conclusions on Indexes For high-cardinality key values, B-Tree indexes are usually best. B-Trees work with all types of comparisons and gracefully shrink and grow as table changes. For low cardinality read-only environments, Bitmaps may be a good option.

Query Optimizer A query optimizer parsers your SQL/Query into a sequence of relational algebra operations, determining an execution plan. The query optimizer figures out the best execution plan based on rules of thumb and information provided in the Data Dictionary (System catalog).

Oracle Query Optimizer Up to version 6, Oracle Used a Rule Based Optimizer. After version 6, Oracle offered the Cost Based and the Rule Based Optimizer. The default is now the Cost Based Optimizer.

Query Optimizer To view how the query plan you must use either set autotrace on or explain plan. Set autotrace on is much simpler. Explain plan is a little bit more efficient, but more complicated.

Typical SQL operations (results of autotrace) TABLE ACCESS FULL TABLE ACCESS BY ROWID INDEX RANGE SCAN INDEX UNIQUE SCAN NESTED LOOPS

TABLE ACCESS FULL (full table scan): Oracle will look at every row in the table to find the requested information. This is usually the slowest way to access a table.

TABLE ACCESS BY ROWID Oracle will use the ROWID method to find a row in the table. ROWID is a special column detailing an exact Oracle block where the row can be found. This is the fastest way to access a table (faster than any index. Less flexible than any index).

INDEX RANGE SCAN Oracle will search an index for a range of values. Usually, this even occurs when a range or between operation is specified by the query or when only the leading columns in a composite index are specified by the where clause. Can perform well or poorly, based on the size of the range and the fragmentation of the index.).

INDEX UNIQUE SCAN Oracle will perform this operation when the tables primary key or a unique key is part of the where clause. This is the most efficient way to search an index.

NESTED LOOPS Indicates that a join operation is occurring. Can perform well or poorly, depending on performance on the index and table operations of the individual tables being joined.

Tuning SQL and PL/SQL Queries Sometimes, Same Query written more than 1000 ways. Generating more than 100 execution plans. Some firms have products that re-write correctly written SQL queries automatically.

ROWID SELECT ROWID, … INTO :EMP_ROWID, … FROM EMP WHERE EMP.EMP_NO = FOR UPDATE; UPDATE EMP SET EMP.NAME = … WHERE ROWID = :EMP_ROWID;

ROWID (cont.) Fastest Less Flexible Are very useful for removing duplicates of rows

SELECT STATEMENT Not exists in place of NOT IN Joins in place of Exists Avoid sub-selects Exists in place of distinct UNION in place of OR on an index column WHERE instead of ORDER BY