IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
    
     Home      Products      Services & industry solutions      Support & downloads      My IBM     
developerworks > My developerWorks >  Dashboard > IBM Database Wiki > ... > Best Practices > Best Practice - Writing and Tuning Queries for Optimal Performance
developerWorks
Log In   View a printable version of the current page.
Best Practice - Writing and Tuning Queries for Optimal Performance
Added by torodanhan, last edited by torodanhan on Apr 01, 2009  (view change)
Labels: 
(None)

  Writing and Tuning Queries for Optimal Performance

This document describes the best practices for minimizing the impact of SQL statements on DB2 database performance. You can minimize this impact in several ways:

  • By writing SQL statements that the DB2 optimizer can more easily optimize. The DB2 optimizer might not be able to efficiently run SQL statements that contain non-equality join predicates, data type mismatches on join columns, unnecessary outer joins, and other complex search conditions.
  • By correctly configuring the DB2 database to take advantage of DB2 optimization functionality. The DB2 optimizer can select the optimal query access plan if you have accurate catalog statistics and choose the best optimization class for your workload.
  • By using the DB2 explain functionality to review potential query access plans and determine how to tune queries for best performance.

This document includes best practices that apply to general workloads, warehouse workloads, and SAP workloads.
There are a number of ways to deal with specific query performance issues after an application is written. However, this document focuses on good fundamental writing and tuning practices that can be widely applied to help improve DB2 database performance.

If you follow the recommendations discussed in this document and still experience poor query performance, there are a number of techniques available to understand why. The "Tuning and Monitoring Database System Performance" best practices paper describes a number of techniques for identifying performance problems and ways the system can be configured to help prevent them. The "Physical Database Design" best practices paper describes how to use DB2 database system features such as multi-dimensional clustering (MDC), materialized query tables (MQTs), and the DB2 Design Advisor to achieve optimal query performance. A subsequent best practices paper will describe techniques to analyze performance problems with a specific query.

For suggestions on improving XQuery performance, see the "Managing XML Data" best practices paper.

Table of contents

Best Practice - Writing and Tuning Queries for Optimal Performance - 1. Introduction
Best Practice - Writing and Tuning Queries for Optimal Performance - 2. Writing SQL statements
Best Practice - Writing and Tuning Queries for Optimal Performance - 3. Designing and configuring your database
Best Practice - Writing and Tuning Queries for Optimal Performance - 4. Tuning SQL statements using the explain facility
Best Practice - Writing and Tuning Queries for Optimal Performance - 5. Conclusion
Best Practice - Writing and Tuning Queries for Optimal Performance - 6. Best Practices Summary


    About IBM Privacy Contact