SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
SQL Performance Tuning Hierarchy

1
Tip # 1: Write Sensible Queries
•

IDENTIFY SQL STATEMENTS THAT ARE TAKING A LONG TIME
TO EXECUTE & STATEMENTS THAT INVOLVE THE JOINING OF
A LARGE NUMBER OF BIG TABLES AND OUTER JOINS

•

CHECK TO SEE IF THERE ARE ANY INDEXES THAT MAY HELP
PERFORMANCE

•

TRY ADDING NEW INDEXES TO THE SYSTEM TO REDUCE
EXCESSIVE FULL TABLE SCANS

2
Tip # 2: Tuning Sub queries
•

THE MAIN QUERY WILL NOT PERFORM WELL IF THE SUBQUERIES CAN’T
PERFORM WELL THEMSELVES

•

PAY ATTENTION TO CORRELATED SUBQUERIES, AS THEY TEND TO BE
VERY COSTLY AND CPU- INSENTIVE.

3
Tip 3# :Limit the Number of Tables in a Join
•

BREAK THE SQL STATEMENT INTO SMALLER STATEMENTS AND WRITING A
PL/SQL BLOCK TO REDUCE DATABASE CALLS

•

USE THE DBMS_SHARED_POOL PACKAGE TO PIN A SQL OR PL/SQL
AREA

•

PINNING PREVENTS MEMORY FRAGMENTATION AND HELPS TO RESERVE
MEMORY FOR SPECIFIC PROGRAMS.

4
5

Tip 4# :Recursive Calls Should be Kept to a
Minimum
•

LARGE AMOUNT OF RECURSIVE SQL EXECUTED BY SYS COULD
INDICATE SPACE MANAGEMENT ACTIVITIES SUCH AS EXTENT
ALLOCATIONS TAKING PLACE. THIS IS NOT SCALABLE AND IMPACTS
USER RESPONSE TIME

•

THE ORACLE TRACE UTILITY TKPROF PROVIDES INFORMATION ABOUT
RECURSIVE CALLS, LIBRARY CACHE MISSES AND ALSO THE USERNAME
OF THE INDIVIDUAL WHO EXECUTED THE SQL STATEMENT

•

TKPROF-GENERATED STATISTICS CAN
TKPROF_TABLE TO BE QUERIED LATER

BE

STORED

IN

A

TABLE
Tip 5# :Improving Parse Speed
•

USE OF BIND VARIABLES ALLOWS YOU TO REPEATEDLY USE THE SAME
STATEMENTS WHILE CHANGING THE WHERE CLAUSE CRITERIA

•

THE PARSE PHASE FOR STATEMENTS CAN BE DECREASED BY EFFICIENT
USE OF ALIASING

6
Tip 6# :Alias Usage
•

IF AN ALIAS IS NOT PRESENT, THE ENGINE MUST RESOLVE WHICH TABLES
OWN THE SPECIFIED COLUMNS

•

A SHORT ALIAS IS PARSED MORE QUICKLY THAN A LONG TABLE NAME
OR ALIAS IF POSSIBLE REDUCE THE ALIAS TO A SINGLE LETTER
•

Bad Statement
•

•

SELECT first_name, last_name, country FROM employee, countries WHERE
country_id = id AND last_name = ‘HALL’;

Good Statement
•

SELECT e.first_name, e.last_name, c.country FROM employee e, countries c
WHERE e.country_id = c.id AND e.last_name = ‘HALL’;

7
Tip 7# :Driving Tables
•

THE STRUCTURE OF THE FROM AND WHERE CLAUSES OF DML
STATEMENTS CAN BE TAILORED TO IMPROVE THE PERFORMANCE

8
Tip 8# :Caching Tables
•

FOR SMALL, FREQUENTLY USED TABLES, PERFORMANCE MAY BE
IMPROVED BY CACHING TABLES

•

NORMALLY, WHEN FULL TABLE SCANS OCCUR, THE CACHED DATA IS
PLACED ON THE LEAST RECENTLY USED (LRU) END OF THE BUFFER
CACHE

•

IF THE TABLE IS CACHED (ALTER TABLE EMPLOYEES CACHE;), THE DATA
IS PLACED ON THE MOST RECENTLY USED (MRU) END OF THE BUFFER,
AND SO IT IS LESS LIKELY TO BE PAGED OUT BEFORE IT IS RE-QUERIED

•

CACHING TABLES MAY ALTER THE CBO’S PATH THROUGH THE DATA
AND SHOULD NOT BE USED WITHOUT CAREFUL CONSIDERATION

9
Tip 9# :Avoid Using Select * Clauses

10

•

DO NOT USE THE * FEATURE BECAUSE IT IS VERY INEFFICIENT

•

THE * HAS TO BE CONVERTED TO EACH COLUMN IN TURN

•

THE SQL PARSER HANDLES ALL THE FIELD REFERENCES BY OBTAINING
THE NAMES OF VALID COLUMNS FROM THE DATA DICTIONARY AND
SUBSTITUTES THEM ON THE COMMAND LINE, WHICH IS TIME
CONSUMING.
Tip 10# :Exists vs. In
•

•
•
•

THE EXISTS FUNCTION SEARCHES FOR THE PRESENCE OF A SINGLE ROW
THAT MEETS THE STATED CRITERIA, AS OPPOSED TO THE IN STATEMENT THAT
LOOKS FOR ALL OCCURRENCES
PRODUCT - 1000 ROWS
ITEMS - 1000 ROWS
(A)
•

•

SELECT p.product_id FROM products p WHERE p.item_no IN (SELECT i.item_no
FROM items i);

(B)
•

•

11

SELECT p.product_id FROM products p WHERE EXISTS (SELECT ‘1’ FROM items I
WHERE i.item_no = p.item_no)

FOR QUERY A, ALL ROWS IN ITEMS WILL BE READ FOR EVERY ROW IN
PRODUCTS. THE EFFECT WILL BE 1,000,000 ROWS READ FROM ITEMS. IN THE
CASE OF QUERY B, A MAXIMUM OF 1 ROW FROM ITEMS WILL BE READ FOR
EACH ROW OF PRODUCTS, THUS REDUCING THE PROCESSING OVERHEAD
OF THE STATEMENT.
Tip 11# :Not Exists vs. Not In
•

In subquery statements such as the following, the NOT IN clause causes
an internal sort/ merge.

•

SELECT * FROM student WHERE student_num NOT IN (SELECT student_num
FROM class)

•

Instead, use:
•

SELECT * FROM student c WHERE NOT EXISTS (SELECT 1 FROM class a WHERE
a.student_num = c.student_num)

12
Tip 12# : In with Minus vs. Not In for Non-Indexed
13
Columns
•

In subquery statements such as the following, the NOT IN clause causes
an internal sort/ merge

•

SELECT * FROM system_user WHERE su_user_id NOT IN (SELECT ac_user
FROM account)

•

Instead, use:
•

SELECT * FROM system_user WHERE su_user_id IN (SELECT su_user_id FROM
system_user MINUS SELECT ac_user FROM account)
Tip 13# :Correlated Subqueries vs. Inline Views

14

•

Do not use code correlated subqueries, as they will adversely impact
system performance

•

Instead, use inline views (subqueries in the from clause of your select
statements), which perform orders of magnitude faster and are much
more scalable
Tip 14# :Views Usage

15

•

Consider including the view definition in the main query by including its
code without the actual view name

•

Views can cause potential performance problems when they have outer
joins (CBO goes haywire with them, even in 9I) or are considered nonmergable views by Oracle.
Tip 15# :Use Decode to Reduce Processing

16

•

Use DECODE when you want to scan same rows repetitively or join the
same table repetitively

•

SELECT count(*) , sum(sal) FROM emp WHERE deptno = 10 AND ename
LIKE ‘MILLER’;

•

SELECT count(*) , sum(sal) FROM emp WHERE deptno = 20 AND ename
LIKE ‘MILLER’;
Tip 16# : Use Union in Place of Or

17

•

In general, always consider the UNION verb instead of OR verb in the
WHERE clauses.

•

Using OR on an indexed column causes the optimizer to perform a fulltable scan rather than an indexed retrieval.
Tip 17# : Use ‘Union All’ Instead of Union

18

•

The SORT operation is very expensive in terms of CPU consumption. The
UNION operation sorts the result set to eliminate any rows that are within
the sub-queries.

•

UNION ALL includes duplicate rows and does not require a sort. Unless you
require that these duplicate rows be eliminated, use UNION ALL.
Tip 18# : Use Indexes to Improve Performance

19

•

Choose and use indexes appropriately. Indexes should have high
selectivity. Bitmapped indexes improve performance when the index has
fewer distinct values like Male or Female

•

Avoid using functions like “UPPER” or “LOWER” on the column that has an
index

•

Index partitioning should be considered if the table on which the index is
based is partitioned. Furthermore, all foreign keys must have indexes or
should form the leading part of Primary Key

•

When using 9i, you can take advantage of skip scans. Index skip scans
remove the limitation posed by column positioning, as column order does
not restrict the use of the index

•

Large indexes should be rebuilt at regular intervals to avoid data
fragmentation. The frequency of rebuilding depends on the extents of
table inserts
20

Thank You
Please visit our official website for more information
http://www.sql-programmers.com/sql-performance-tuning.aspx

Weitere ähnliche Inhalte

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Sql Server performance tuning

  • 2. Tip # 1: Write Sensible Queries • IDENTIFY SQL STATEMENTS THAT ARE TAKING A LONG TIME TO EXECUTE & STATEMENTS THAT INVOLVE THE JOINING OF A LARGE NUMBER OF BIG TABLES AND OUTER JOINS • CHECK TO SEE IF THERE ARE ANY INDEXES THAT MAY HELP PERFORMANCE • TRY ADDING NEW INDEXES TO THE SYSTEM TO REDUCE EXCESSIVE FULL TABLE SCANS 2
  • 3. Tip # 2: Tuning Sub queries • THE MAIN QUERY WILL NOT PERFORM WELL IF THE SUBQUERIES CAN’T PERFORM WELL THEMSELVES • PAY ATTENTION TO CORRELATED SUBQUERIES, AS THEY TEND TO BE VERY COSTLY AND CPU- INSENTIVE. 3
  • 4. Tip 3# :Limit the Number of Tables in a Join • BREAK THE SQL STATEMENT INTO SMALLER STATEMENTS AND WRITING A PL/SQL BLOCK TO REDUCE DATABASE CALLS • USE THE DBMS_SHARED_POOL PACKAGE TO PIN A SQL OR PL/SQL AREA • PINNING PREVENTS MEMORY FRAGMENTATION AND HELPS TO RESERVE MEMORY FOR SPECIFIC PROGRAMS. 4
  • 5. 5 Tip 4# :Recursive Calls Should be Kept to a Minimum • LARGE AMOUNT OF RECURSIVE SQL EXECUTED BY SYS COULD INDICATE SPACE MANAGEMENT ACTIVITIES SUCH AS EXTENT ALLOCATIONS TAKING PLACE. THIS IS NOT SCALABLE AND IMPACTS USER RESPONSE TIME • THE ORACLE TRACE UTILITY TKPROF PROVIDES INFORMATION ABOUT RECURSIVE CALLS, LIBRARY CACHE MISSES AND ALSO THE USERNAME OF THE INDIVIDUAL WHO EXECUTED THE SQL STATEMENT • TKPROF-GENERATED STATISTICS CAN TKPROF_TABLE TO BE QUERIED LATER BE STORED IN A TABLE
  • 6. Tip 5# :Improving Parse Speed • USE OF BIND VARIABLES ALLOWS YOU TO REPEATEDLY USE THE SAME STATEMENTS WHILE CHANGING THE WHERE CLAUSE CRITERIA • THE PARSE PHASE FOR STATEMENTS CAN BE DECREASED BY EFFICIENT USE OF ALIASING 6
  • 7. Tip 6# :Alias Usage • IF AN ALIAS IS NOT PRESENT, THE ENGINE MUST RESOLVE WHICH TABLES OWN THE SPECIFIED COLUMNS • A SHORT ALIAS IS PARSED MORE QUICKLY THAN A LONG TABLE NAME OR ALIAS IF POSSIBLE REDUCE THE ALIAS TO A SINGLE LETTER • Bad Statement • • SELECT first_name, last_name, country FROM employee, countries WHERE country_id = id AND last_name = ‘HALL’; Good Statement • SELECT e.first_name, e.last_name, c.country FROM employee e, countries c WHERE e.country_id = c.id AND e.last_name = ‘HALL’; 7
  • 8. Tip 7# :Driving Tables • THE STRUCTURE OF THE FROM AND WHERE CLAUSES OF DML STATEMENTS CAN BE TAILORED TO IMPROVE THE PERFORMANCE 8
  • 9. Tip 8# :Caching Tables • FOR SMALL, FREQUENTLY USED TABLES, PERFORMANCE MAY BE IMPROVED BY CACHING TABLES • NORMALLY, WHEN FULL TABLE SCANS OCCUR, THE CACHED DATA IS PLACED ON THE LEAST RECENTLY USED (LRU) END OF THE BUFFER CACHE • IF THE TABLE IS CACHED (ALTER TABLE EMPLOYEES CACHE;), THE DATA IS PLACED ON THE MOST RECENTLY USED (MRU) END OF THE BUFFER, AND SO IT IS LESS LIKELY TO BE PAGED OUT BEFORE IT IS RE-QUERIED • CACHING TABLES MAY ALTER THE CBO’S PATH THROUGH THE DATA AND SHOULD NOT BE USED WITHOUT CAREFUL CONSIDERATION 9
  • 10. Tip 9# :Avoid Using Select * Clauses 10 • DO NOT USE THE * FEATURE BECAUSE IT IS VERY INEFFICIENT • THE * HAS TO BE CONVERTED TO EACH COLUMN IN TURN • THE SQL PARSER HANDLES ALL THE FIELD REFERENCES BY OBTAINING THE NAMES OF VALID COLUMNS FROM THE DATA DICTIONARY AND SUBSTITUTES THEM ON THE COMMAND LINE, WHICH IS TIME CONSUMING.
  • 11. Tip 10# :Exists vs. In • • • • THE EXISTS FUNCTION SEARCHES FOR THE PRESENCE OF A SINGLE ROW THAT MEETS THE STATED CRITERIA, AS OPPOSED TO THE IN STATEMENT THAT LOOKS FOR ALL OCCURRENCES PRODUCT - 1000 ROWS ITEMS - 1000 ROWS (A) • • SELECT p.product_id FROM products p WHERE p.item_no IN (SELECT i.item_no FROM items i); (B) • • 11 SELECT p.product_id FROM products p WHERE EXISTS (SELECT ‘1’ FROM items I WHERE i.item_no = p.item_no) FOR QUERY A, ALL ROWS IN ITEMS WILL BE READ FOR EVERY ROW IN PRODUCTS. THE EFFECT WILL BE 1,000,000 ROWS READ FROM ITEMS. IN THE CASE OF QUERY B, A MAXIMUM OF 1 ROW FROM ITEMS WILL BE READ FOR EACH ROW OF PRODUCTS, THUS REDUCING THE PROCESSING OVERHEAD OF THE STATEMENT.
  • 12. Tip 11# :Not Exists vs. Not In • In subquery statements such as the following, the NOT IN clause causes an internal sort/ merge. • SELECT * FROM student WHERE student_num NOT IN (SELECT student_num FROM class) • Instead, use: • SELECT * FROM student c WHERE NOT EXISTS (SELECT 1 FROM class a WHERE a.student_num = c.student_num) 12
  • 13. Tip 12# : In with Minus vs. Not In for Non-Indexed 13 Columns • In subquery statements such as the following, the NOT IN clause causes an internal sort/ merge • SELECT * FROM system_user WHERE su_user_id NOT IN (SELECT ac_user FROM account) • Instead, use: • SELECT * FROM system_user WHERE su_user_id IN (SELECT su_user_id FROM system_user MINUS SELECT ac_user FROM account)
  • 14. Tip 13# :Correlated Subqueries vs. Inline Views 14 • Do not use code correlated subqueries, as they will adversely impact system performance • Instead, use inline views (subqueries in the from clause of your select statements), which perform orders of magnitude faster and are much more scalable
  • 15. Tip 14# :Views Usage 15 • Consider including the view definition in the main query by including its code without the actual view name • Views can cause potential performance problems when they have outer joins (CBO goes haywire with them, even in 9I) or are considered nonmergable views by Oracle.
  • 16. Tip 15# :Use Decode to Reduce Processing 16 • Use DECODE when you want to scan same rows repetitively or join the same table repetitively • SELECT count(*) , sum(sal) FROM emp WHERE deptno = 10 AND ename LIKE ‘MILLER’; • SELECT count(*) , sum(sal) FROM emp WHERE deptno = 20 AND ename LIKE ‘MILLER’;
  • 17. Tip 16# : Use Union in Place of Or 17 • In general, always consider the UNION verb instead of OR verb in the WHERE clauses. • Using OR on an indexed column causes the optimizer to perform a fulltable scan rather than an indexed retrieval.
  • 18. Tip 17# : Use ‘Union All’ Instead of Union 18 • The SORT operation is very expensive in terms of CPU consumption. The UNION operation sorts the result set to eliminate any rows that are within the sub-queries. • UNION ALL includes duplicate rows and does not require a sort. Unless you require that these duplicate rows be eliminated, use UNION ALL.
  • 19. Tip 18# : Use Indexes to Improve Performance 19 • Choose and use indexes appropriately. Indexes should have high selectivity. Bitmapped indexes improve performance when the index has fewer distinct values like Male or Female • Avoid using functions like “UPPER” or “LOWER” on the column that has an index • Index partitioning should be considered if the table on which the index is based is partitioned. Furthermore, all foreign keys must have indexes or should form the leading part of Primary Key • When using 9i, you can take advantage of skip scans. Index skip scans remove the limitation posed by column positioning, as column order does not restrict the use of the index • Large indexes should be rebuilt at regular intervals to avoid data fragmentation. The frequency of rebuilding depends on the extents of table inserts
  • 20. 20 Thank You Please visit our official website for more information http://www.sql-programmers.com/sql-performance-tuning.aspx