Reina_DB2 Optimizer Guidelines Usage
-
Upload
alinawazahmed4 -
Category
Documents
-
view
222 -
download
2
description
Transcript of Reina_DB2 Optimizer Guidelines Usage
![Page 1: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/1.jpg)
IBM Software Group | DB2 Curriculum Course
1
DB2 Optimizer Guidelines Usage
Speaker name: Anthony E. Reina
Email: [email protected]
![Page 2: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/2.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
2
The IBM Software Accelerated Value Program delivers a proactive, cost-reducing, and productivity enhancing advisory service. The program pairs you with an assigned team who build a foundational understanding of your overall environment. Through that understanding, the trusted partnet works to facilitate faster deployment, lifecycle leadership, risk mitigation, and more by identifying ways to improve your environment, staff skill set, and processes.
http://www-01.ibm.com/software/support/acceleratedvalue/
IBM Software Accelerated Value Program
![Page 3: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/3.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
3
Mechanism to alter default access plan Overrides the default access plan selected by the optimizer. Instructs the optimizer how to perform table access or join. Allows users to control specific parts of access plan.
Can be employed without changing the application code Compose optimization profile, add to db, rebind targeted packages.
Should only be used after all other tuning options exhausted Query improvement, RUNSTATS, indexes, optimization class, db and
dbm configs, etc. Should not be employed to permanently mitigate the effect of
inefficient queries.
Optimizer Profiles
![Page 4: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/4.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
4
Optimizer Profiles Anatomy of an optimizer profile:
XML document Elements and attributes used to define optimization guidelines. Must conform to a specific optimization profile schema.
Profile Header (exactly one) Meta data and processing directives. Example: schema version.
Global optimization guidelines (at most one) Applies to all statements for which profile is in effect. Example: eligible MQTs guideline defining MQTs to be considered for routing.
Statement optimization guidelines (zero or more) Applies to a specific statement for which profile is in effect. Specifies directives for desired execution plan.
![Page 5: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/5.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
5
Optimizer Profiles
Anatomy of an optimizer profile (continued):
<?xml version="1.0" encoding="UTF-8"?><OPTPROFILE VERSION="9.7.0.0">
<OPTGUIDELINES> <MQT NAME="Test.AvgSales"/> <MQT NAME="Test.SumSales"/> </OPTGUIDELINES>
<STMTPROFILE ID="Guidelines for TPCD"> <STMTKEY SCHEMA="TPCD"> <![CDATA[SELECT * FROM TAB1]]> </STMTKEY> <OPTGUIDELINES> <IXSCAN TABLE=“TAB1"
INDEX="I_SUPPKEY"/> </OPTGUIDELINES></STMTPROFILE>
</OPTPROFILE>
Profile Header
Global optimization guidelines section. Optional but at most one.
Statement guidelines section. Zero or more.
![Page 6: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/6.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
6
Optimizer Profiles
Each statement profile contains a statement key (STMTKEY) and one or more statement-level optimization guidelines (OPTGUIDELINES).
The statement key identifies the statement or query to which the statement-level optimization guidelines apply.
The statement-level optimization guidelines identify one of more directives, e.g. access or join requests, which specify methods for accessing or joining tables in the statement.
<STMTKEY SCHEMA="TPCD"> <![CDATA[SELECT * FROM TAB1]]></STMTKEY>
<OPTGUIDELINES> <IXSCAN TABID=“TAB1" INDEX="I_SUPPKEY"/></OPTGUIDELINES>
![Page 7: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/7.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
7
Optimizer Profiles
Optimizer guidelines:
Access plan guidelines: Base access request (method to access a table, e.g. TBSCAN, IXSCAN) Join request (method and sequence for performing a join, e.g. HSJOIN, NLJOIN)
Query rewrite guidelines: INLIST2JOIN (convert IN-list to join) SUBQ2JOIN (convert subquery to join) NOTEX2AJ (convert NOT EXISTS subquery to anti-join) NOTIN2AJ (convert NOT IN subquery to anti-join)
General optimization guidelines: REOPT (ONCE/ALWAYS/NONE) MQT choices QRYOPT (set the query optimization class) RTS (limit the amount of time taken by real-time statistics collection)
![Page 8: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/8.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
8
Optimizer Profiles
How to create and use an optimizer profile:
1. Create the SYSTOOLS.OPT_PROFILE table in the SYSTOOLS schema:
Using the CREATE TABLE statement:
CREATE TABLE SYSTOOLS.OPT_PROFILE (SCHEMA VARCHAR(128) NOT NULL, Schema nameNAME VARCHAR(128) NOT NULL, Profile namePROFILE BLOB (2M) NOT NULL, Profile XML
PRIMARY KEY ( SCHEMA, NAME ));
Using the SYSINSTALLOBJECTS procedure:
db2 "call sysinstallobjects('opt_profiles', 'c', '', '')"
2. Compose optimization profile in XML file prof1.xml.
![Page 9: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/9.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
9
Optimizer Profiles
How to create and use an optimizer profile (continued):
3. Create file prof1.del as follows:
"EXAMPLE","PROF1","prof1.xml"
4. Import prof1.del into SYSTOOLS.OPT_PROFILE table as follows:
IMPORT FROM prof1.del OF DEL MODIFIED BY LOBSINFILEINSERT INTO SYSTOOLS.OPT_PROFILE;
5. Enable the PROF1 profile for the current session:
db2 "set current optimization profile = 'EXAMPLE.PROF1'"
![Page 10: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/10.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
10
Optimizer Profiles Checking if the guidelines are applied:
SQL0437W reason code 13 is issued if there were problems with applying the guidelines (usually due to syntax error)Db2exfmt output contains a section with details on the problems encountered while attempting to apply the guidelines:
Db2exfmt Profile Information section informs on which guidelines were used:
Extended Diagnostic Information:--------------------------------No extended Diagnostic Information for this statement.
Profile Information:--------------------OPT_PROF: (Optimization Profile Name) EXAMPLE.PROF1STMTPROF: (Statement Profile Name) Guidelines for the items out query
![Page 11: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/11.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
11
Optimizer Profiles
Example 1
Examine the optimize profile in example1.xml:Global guideline forces OPTLEVEL 7 for all queries in the
current session. Statement guideline forces nested loop join method
(NLJOIN) for tables MOVIE and TRANSACTION_DETAIL for a given query.
Run example1.bat – this will create and apply an optimizer profile named PROF1. It will also collect db2exfmt output before and after using the profile.
Compare the before and after .exfmt files – how can you tell if the guidelines were applied?
![Page 12: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/12.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
12
Optimizer Profiles Example1.xml
![Page 13: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/13.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
13
Optimizer Profiles
Example1.del
Example1.sql
![Page 14: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/14.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
14
Optimizer Profiles Example1.bat
![Page 15: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/15.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
15
Optimizer Profiles Example1-base.exfmt
![Page 16: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/16.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
16
Optimizer Profiles Example1-prof1.exfmt
![Page 17: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/17.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
17
Optimizer Profiles
Example 2 : Specify to always use a specific index
Force the access plan to always use T1X index when accessing T1 table.
![Page 18: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/18.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
18
Optimizer Profiles
Example 3 : Use REOPT always
Defer the query optimization until the input variables have been provided during runtime.
Possible Values – ONCE, ALWAYS, or NONE
![Page 19: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/19.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
19
Optimizer Profiles
Example 4 : Change Optimization Level
Change the optimization level for a particular sql.
Possible Values – same as setting the DFT_QUERYOPT
![Page 20: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/20.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
20
Optimizer Profiles
Example 5 : Runtime Degree setting
Change the runtime degree of a query for INTRA-PARTITION environment.
Possible Values – same as setting the DFT_DEGREE
![Page 21: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/21.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
21
Optimizer Profiles
Example 6 : INLIST to Nested Loop Join
Change the list of values (inlist) to use the GENROW function which is more efficient and can improve query performance.
![Page 22: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/22.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
22
Optimizer Profiles
Example 7 : Sub-Query to Join
By enabling the SUBQ2JOIN, a sub-query is transformed to a join during query rewrite.
![Page 23: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/23.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
23
Optimizer Profiles
Example 8 : Influencing Join Order
Most of the time the join order of a query will greatly determine the query execution performance, as filtering rows early as possible is the most efficient.
![Page 24: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/24.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
24
Usefull Links
Developer Work Article - Influence query optimization with optimization and statistical views in DB2 V9x
http://www.ibm.com/developerworks/data/library/techarticle/dm-0612chen/index.html
DB2 V9.7 Info Center - Optimization Profiles and Quidelineshttp://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.perf.doc%2Fdoc
%2Fc0024522.html
![Page 25: Reina_DB2 Optimizer Guidelines Usage](https://reader030.fdocuments.us/reader030/viewer/2022020208/55cf8fa0550346703b9e2000/html5/thumbnails/25.jpg)
IBM Software Group | DB2 Information Management Software | Curriculum Course
25
Optimizer Profiles
Q&A