Database Performance and Query Optimization 7.1
Total Page:16
File Type:pdf, Size:1020Kb
IBM IBM i Database Performance and Query Optimization 7.1 IBM IBM i Database Performance and Query Optimization 7.1 Note Before using this information and the product it supports, read the information in “Notices,” on page 393. | This edition applies to IBM i 7.1 (product number 5770-SS1) and to all subsequent releases and modifications until | otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) | models nor does it run on CISC models. © Copyright IBM Corporation 1998, 2010. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Database performance and query Encoded vector indexes ......... 201 optimization ............. 1 Comparing binary radix indexes and encoded | What's new for IBM i 7.1 .......... 1 vector indexes ............ 207 PDF file for Database performance and query Indexes & the optimizer ......... 208 optimization .............. 2 Indexing strategy ........... 216 Query engine overview ........... 2 Coding for effective indexes ....... 217 SQE and CQE engines .......... 3 Using indexes with sort sequence ..... 220 Query dispatcher ............ 4 Index examples............ 221 Statistics manager ........... 5 Application design tips for database performance 229 | Global Statistics Cache .......... 6 Using live data ............ 230 Plan cache .............. 6 Reducing the number of open operations ... 231 Data access methods............ 8 Retaining cursor positions ........ 234 Permanent objects and access methods .... 8 Programming techniques for database performance 236 Temporary objects and access methods .... 22 Use the OPTIMIZE clause ........ 236 Objects processed in parallel........ 50 Use FETCH FOR n ROWS ........ 237 Spreading data automatically ....... 51 Use INSERT n ROWS ......... 238 Processing queries: Overview ........ 52 Control database manager blocking ..... 239 How the query optimizer makes your queries Optimize the number of columns that are more efficient............. 52 selected with SELECT statements...... 240 General query optimization tips ...... 52 Eliminate redundant validation with SQL Access plan validation.......... 53 PREPARE statements .......... 240 Single table optimization ......... 54 Page interactively displayed data with Join optimization ........... 55 REFRESH(*FORWARD) ......... 241 Distinct optimization .......... 65 | Improve concurrency by avoiding lock waits 241 Grouping optimization ......... 66 General DB2 for i performance considerations .. 242 Ordering optimization .......... 72 Effects on database performance when using View implementation .......... 73 long object names ........... 242 Materialized query table optimization .... 75 Effects of precompile options on database Recursive query optimization ....... 85 performance............. 242 | Adaptive Query Processing ........ 95 Effects of the ALWCPYDTA parameter on Optimizing query performance using query database performance ......... 243 optimization tools ............ 99 Tips for using VARCHAR and VARGRAPHIC | DB2 for IBM i – Health Center ....... 99 data types in databases ......... 244 Monitoring your queries using the Database | Using field procedures to provide column level Monitor .............. 121 | encryption ............. 246 Using System i Navigator with detailed | SYSTOOLS .............. 249 monitors .............. 132 | Using SYSTOOLS ........... 249 Index advisor ............ 137 Database monitor formats ......... 251 Viewing your queries with Visual Explain ... 141 Database monitor SQL table format ..... 251 Optimizing performance using the Plan Cache 146 Optional database monitor SQL view format 258 Verifying the performance of SQL applications 155 Query optimizer messages reference...... 350 Examining query optimizer debug messages in Query optimization performance information the job log ............. 155 messages .............. 350 Print SQL Information ......... 156 Query optimization performance information Query optimization tools: Comparison .... 157 messages and open data paths ...... 374 PRTSQLINF Changing the attributes of your queries ... 158 message reference ....... 379 Collecting statistics with the statistics manager 186 Displaying materialized query table columns 192 Appendix. Notices ......... 393 Managing check pending constraints columns 193 Programming interface information ...... 395 Creating an index strategy ......... 194 Trademarks .............. 395 Binary radix indexes .......... 194 Terms and conditions........... 395 © Copyright IBM Corp. 1998, 2010 iii iv IBM i: Database Performance and Query Optimization Database performance and query optimization | The goal of database performance tuning is to minimize the response time of your queries by making the | best use of your system resources. The best use of these resources involves minimizing network traffic, | disk I/O, and CPU time. This goal can only be achieved by understanding the logical and physical | structure of your data, the applications used on your system, and how the conflicting uses of your | database might affect performance. | The best way to avoid performance problems is to ensure that performance issues are part of your | ongoing development activities. Many of the most significant performance improvements are realized | through careful design at the beginning of the database development cycle. To most effectively optimize | performance, you must identify the areas that yield the largest performance increases over the widest | variety of situations. Focus your analysis on these areas. Many of the examples within this publication illustrate a query written through either an SQL or an OPNQRYF query interface. The interface chosen for a particular example does not indicate an operation exclusive to that query interface, unless explicitly noted. It is only an illustration of one possible query interface. Most examples can be easily rewritten into whatever query interface that you prefer. Note: By using the code examples, you agree to the terms of the “Code license and disclaimer information” on page 390. | What's new for IBM i 7.1 | The following information was added or updated in this release of the information: | v “Global Statistics Cache” on page 6 | v “Encoded vector index index-only access” on page 17 | v “Encoded vector index symbol table scan” on page 18 | v “Encoded vector index symbol table probe” on page 21 | v “Encoded vector index INCLUDE aggregates” on page 18 | v “Array unnest temporary table” on page 49 | v “Adaptive Query Processing” on page 95 | v “Health Center SQL procedures” on page 100 | v “Sparse indexes” on page 194 | v “View index build status” on page 213 | v “Improve concurrency by avoiding lock waits” on page 241 | v “Using field procedures to provide column level encryption” on page 246 | v “SYSTOOLS” on page 249 | What's new | The following revisions or additions have been made to the Performance and query optimization | documentation since the first 7.1 publication: | v April 2016 update : | – An additional query option was added to QAQQINI : ALLOW_EVI_ONLY_ACCESS. For details, see | “QAQQINI query options” on page 162 | v May 2015 update : | – Additional options were added to the QAQQINI query option Memory_Pool_Preference. For details, | see “QAQQINI query options” on page 162 © Copyright IBM Corp. 1998, 2010 1 | v October 2014 update: | – The database monitor topic has been updated: “Monitoring your queries using the Database | Monitor” on page 121 | – The SQL Plan Cache topic has been updated: “Optimizing performance using the Plan Cache” on | page 146 | How to see what's new or changed | To help you see where technical changes have been made, this information uses: | v The image to mark where new or changed information begins. | v The image to mark where new or changed information ends. | To find other information about what's new or changed this release, see the Memo to users. PDF file for Database performance and query optimization View and print a PDF of this information. To view or download the PDF version of this document, select Database performance and query optimization (about 5537 KB). Other information You can also view or print any of the following PDF files: v Preparing for and Tuning the SQL Query Engine on DB2® for i5/OS v SQL Performance Diagnosis on IBM® DB2 Universal Database™ for iSeries . Saving PDF files To save a PDF on your workstation for viewing or printing: 1. Right-click the PDF in your browser (right-click the preceding link). 2. Click the option that saves the PDF locally. 3. Navigate to the directory in which you want to save the PDF. 4. Click Save. Downloading Adobe Reader You need Adobe Reader installed on your system to view or print these PDF files. You can download a free copy from Adobe (http://get.adobe.com/reader/) . Query engine overview IBM DB2 for i provides two query engines to process queries: Classic Query Engine (CQE) and SQL Query Engine (SQE). The CQE processes queries originating from non-SQL interfaces: OPNQRYF, Query/400, and QQQQry API. SQL-based interfaces, such as ODBC, JDBC, CLI, Query Manager, Net.Data®, RUNSQLSTM, and embedded or interactive SQL, run through the SQE. For ease of use, the routing decision for processing the query by either CQE or SQE is pervasive and under the control of the system. The requesting user or 2 IBM i: Database Performance and Query Optimization application program cannot control or influence this behavior. However, a better understanding of the