SlideShare une entreprise Scribd logo
1  sur  30
Performance Tuning
Tuning: overview
•
•
•
•
•
•
•
•
•
•
•
•

Rewrite SQL (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 <iName> on
<tname> (<col_name>);
• 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 don’t 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 (don’t 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 < or > )
• 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.
• 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 involving
parallel processing and a huge 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 table’s 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.
Select emp_sal from emp where emp_id exists
(select emp_id from dept where deptname
like’mca’);
ROWID
• SELECT ROWID, …
INTO :EMP_ROWID, …
FROM EMP
WHERE EMP.EMP_NO = 56722
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

Contenu connexe

Tendances

Useful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesUseful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesMaria Colgan
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008paulguerin
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesDave Stokes
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBOvais Tariq
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Antonios Chatzipavlis
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)Michael Rys
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...Datavail
 
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Michael Rys
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introductionRiteshkiit
 
Oracle Course
Oracle CourseOracle Course
Oracle Courserspaike
 
ONE FOR ALL! Using Apache Calcite to make SQL smart
ONE FOR ALL! Using Apache Calcite to make SQL smartONE FOR ALL! Using Apache Calcite to make SQL smart
ONE FOR ALL! Using Apache Calcite to make SQL smartEvans Ye
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
Advance Hive, NoSQL Database (HBase) - Module 7
Advance Hive, NoSQL Database (HBase) - Module 7Advance Hive, NoSQL Database (HBase) - Module 7
Advance Hive, NoSQL Database (HBase) - Module 7Rohit Agrawal
 

Tendances (19)

Useful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesUseful PL/SQL Supplied Packages
Useful PL/SQL Supplied Packages
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
San diegophp
San diegophpSan diegophp
San diegophp
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL Queries
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
Part5 sql tune
Part5 sql tunePart5 sql tune
Part5 sql tune
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Cost-based Query Optimization
Cost-based Query Optimization Cost-based Query Optimization
Cost-based Query Optimization
 
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...
SQL Pass Summit Presentations from Datavail - Optimize SQL Server: Query Tuni...
 
Rdbms
RdbmsRdbms
Rdbms
 
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introduction
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
ONE FOR ALL! Using Apache Calcite to make SQL smart
ONE FOR ALL! Using Apache Calcite to make SQL smartONE FOR ALL! Using Apache Calcite to make SQL smart
ONE FOR ALL! Using Apache Calcite to make SQL smart
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Advance Hive, NoSQL Database (HBase) - Module 7
Advance Hive, NoSQL Database (HBase) - Module 7Advance Hive, NoSQL Database (HBase) - Module 7
Advance Hive, NoSQL Database (HBase) - Module 7
 

En vedette (12)

Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Dbms objective and subjective notes
Dbms objective and subjective notesDbms objective and subjective notes
Dbms objective and subjective notes
 
Rman offline backup
Rman offline backupRman offline backup
Rman offline backup
 
Rmanpres
RmanpresRmanpres
Rmanpres
 
5 backuprecoveryw imp
5 backuprecoveryw imp5 backuprecoveryw imp
5 backuprecoveryw imp
 
Oracle shutdown
Oracle shutdownOracle shutdown
Oracle shutdown
 
Data guard
Data guardData guard
Data guard
 
1 plsql introduction1
1 plsql introduction11 plsql introduction1
1 plsql introduction1
 
Dba in 2 days unit no 9
Dba in 2 days unit no 9Dba in 2 days unit no 9
Dba in 2 days unit no 9
 
Resize sga
Resize sgaResize sga
Resize sga
 
Store programs
Store programsStore programs
Store programs
 
Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema Gajjar
 

Similaire à Tunning overview

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAmazon Web Services
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2sqlserver.co.il
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Aaron Shilo
 
A tour of Amazon Redshift
A tour of Amazon RedshiftA tour of Amazon Redshift
A tour of Amazon RedshiftKel Graham
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Web Services
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQLSatoshi Nagayasu
 
30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practices30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practicesDavid Dhavan
 
Database Performance
Database PerformanceDatabase Performance
Database PerformanceBoris Hristov
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices documentAshwani Pandey
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationVolodymyr Rovetskiy
 
Data Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxData Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxTusharAgarwal49094
 
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best PracticesAmazon Web Services
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMahesh Salaria
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperPolish SQL Server User Group
 

Similaire à Tunning overview (20)

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
 
Lecture3.ppt
Lecture3.pptLecture3.ppt
Lecture3.ppt
 
A tour of Amazon Redshift
A tour of Amazon RedshiftA tour of Amazon Redshift
A tour of Amazon Redshift
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and Optimization
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practices30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practices
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices document
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentation
 
Data Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxData Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptx
 
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
 
Cassandra training
Cassandra trainingCassandra training
Cassandra training
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source Database
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
 

Plus de Hitesh Kumar Markam

Plus de Hitesh Kumar Markam (9)

Concepts of Distributed Computing & Cloud Computing
Concepts of Distributed Computing & Cloud Computing Concepts of Distributed Computing & Cloud Computing
Concepts of Distributed Computing & Cloud Computing
 
Log miner in oracle.ppt
Log miner in oracle.pptLog miner in oracle.ppt
Log miner in oracle.ppt
 
Pl sql
Pl sqlPl sql
Pl sql
 
Oracle archi ppt
Oracle archi pptOracle archi ppt
Oracle archi ppt
 
Lecture2 oracle ppt
Lecture2 oracle pptLecture2 oracle ppt
Lecture2 oracle ppt
 
Dba in 2 days
Dba in 2 daysDba in 2 days
Dba in 2 days
 
Creating database
Creating databaseCreating database
Creating database
 
javascript code for mysql database connection
javascript code for mysql database connectionjavascript code for mysql database connection
javascript code for mysql database connection
 
Advanced Planning And Optimization
Advanced Planning And OptimizationAdvanced Planning And Optimization
Advanced Planning And Optimization
 

Dernier

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Dernier (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Tunning overview

  • 2. Tuning: overview • • • • • • • • • • • • Rewrite SQL (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
  • 3. 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)
  • 4. Different Type of Indexes • • • • • B-Trees (traditional) indexes Hash-cluster Bitmap indexes Index-Organized Tables Reverse-Key Indexes
  • 5. Create Index command • Create index <iName> on <tname> (<col_name>); • Create index cidx on orders (cid);
  • 6. 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 ?
  • 7. 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.
  • 8. B-Tree (Balanced Tree) • Most popular type of index structure for any programming language or database. • When you don’t 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
  • 9. 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.
  • 10. Good Indexing (B-Tree) Candidates • Table must be reasonably large • Field is queried by frequently • Field has a high cardinality (don’t index by sex, where the cardinality is 2!!). • Badly balanced trees may inhibit performance. Destroying and re-creating index may improve performance.
  • 11. 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).
  • 12. Bitmap Index (cont.) • Syntax: Create Bitmap index …. • Bitmap index works better with equality tests = or in (not with < or > ) • 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
  • 13. 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;
  • 14. 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
  • 15. 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. • Index works best when there are few (and small) columns in your table other than the PK.
  • 16. Reverse Key Indexes • Key ‘1234’ becomes ‘4321’, etc. • Only efficient for few scenarios involving parallel processing and a huge amount of data. • By reversing key values, index blocks might be more evenly distributed reducing the likelihood of densely or sparsely populated indexes.
  • 17. 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.
  • 18. 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).
  • 19. 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.
  • 20. 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.
  • 21. Typical SQL operations (results of autotrace) • • • • • TABLE ACCESS FULL TABLE ACCESS BY ROWID INDEX RANGE SCAN INDEX UNIQUE SCAN NESTED LOOPS
  • 22. • 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.
  • 23. 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).
  • 24. 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.).
  • 25. INDEX UNIQUE SCAN Oracle will perform this operation when the table’s primary key or a unique key is part of the where clause. This is the most efficient way to search an index.
  • 26. 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.
  • 27. 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. Select emp_sal from emp where emp_id exists (select emp_id from dept where deptname like’mca’);
  • 28. ROWID • SELECT ROWID, … INTO :EMP_ROWID, … FROM EMP WHERE EMP.EMP_NO = 56722 FOR UPDATE; UPDATE EMP SET EMP.NAME = … WHERE ROWID = :EMP_ROWID;
  • 29. ROWID (cont.) • Fastest • Less Flexible • Are very useful for removing duplicates of rows
  • 30. 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