04 - Plan Cache and Index Advice S4-4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

Db2 for i

Tools and Methodologies

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Db2 Optimization and Execution Feedback

SQE
Plan Cache Visual
Explain

SQE
Plan Cache
Snapshots
SQL request

SQL
Query
Performance
Optimization
Monitor

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Discovery Methodologies

All work Specific SQL Request

Complex SQL Request


Specific SQL Request All work

• Proactive and reactive approaches

• Tools support passive and active monitoring

• All methodologies are iterative in nature

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
The Process

• Proactive and reactive analysis


– Analyze the SQL request before and after execution
• Profile long running or complex queries to capture the optimization and
implementation method
– Detailed Monitor Data
– Plan Cache
• Profile the system when running long or complex queries to capture work
management configurations and performance statistics
– Database Monitor Data
– Plan Cache
– Performance Monitor data
• Understand the data being queried
– Table and index object sizes
– Data skew
– Join fanout
– Number of groups

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

• System wide information from the SQL Plan Cache


SQL Plan Cache
– Automatic
– No overhead SQE stores all query
• SQE support only plans in a centralized
system wide plan
• GUI interface via Access Client Solutions
cache.
– Access
– Filtering Along with the plans,
– Analysis by time, user, job, statement, etc. SQE keeps meta data
– Visual Explain and runtime
• Data is volatile information for the
plans (i.e. queries).
– Information in the SQL Plan Cache is “live” and
changing
The plan cache is
– SQL Plan Cache is cleared at IPL
considered temporary
– Event monitor to capture plans that are pruned storage.
• SQL Plan Cache is always available
– No need to “start and stop” a tool or utility It pages in the *BASE
pool

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

List is initially empty to allow for filtering

Example: filter on top 10 and current user

 Get the list of plans for the top 10


queries
 Get the list of plans that the current
user has run
 “AND” the plan lists together
 Return those plans to the user

If the current user ran one or more of the


top 10 plans, those particular plans will
be returned.

If the user did not run any of the top 10


plans, nothing is returned.

The top 10 plans for current user is not


necessarily returned.

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Show Statements

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Show Longest Runs

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Show Longest Runs

Default is up to 3 longest runs

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Column filtering

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Column filtering

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Properties

In addition to retaining all of the SQE access plans, the SQL plan
cache provides valuable insights into performance.
• The properties can and will change over time.
• Most properties are reported at the system/server level even though
access plans are subdivided by SYSBAS and IASP.
• The attributes described here are available as of IBM i 7.1
Properties are divided into three main types
• Summary and Usage – Information about plan usage, query usage,
and current conditions for the plan cache and queries
• Configuration – Properties that can be adjusted by the user
• Activity Thresholds – Represents the ‘high water mark’ of several key
indicators

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Accessing the Plan Cache Properties

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Plan Cache Properties Db2 for i

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Summary and Usage

• Time of Summary – Time when the properties were viewed/dumped


• Plan Cache Creation Time – Last time the server was IPLed
• Number of Currently Active Queries
– Count of query cursors that are currently open or pseudo-closed
• Number of Queries Run Since Start
– Count of query cursors that have been opened or pseudo-opened
• Number of Query Full Opens Since Start
– Count of query cursors that required a full open (rather than a pseudo-
open)
IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Summary and Usage

• Current Number of Plans in Cache


• Total Number of Plans Built Since Start
– Access plans built since IPL
• Total Number of Unique Queries Since Start
– Unqualified references in permanent schemas count as unique queries
– Unqualified references in QTEMP or SESSION instances still count as
one query

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Summary and Usage

• Current Plan Cache Size


• Plan Cache Size Threshold – Current, may be adjusted by autosizing
• Maximum Plan Cache Size Allowed for AutoSizing
– The maximum value allowed for Plan Cache Size Threshold with autosizing
• Current Plan Cache Hit Ratio
– The percentage of time that the query optimizer finds an existing plan in the plan
cache for the query – higher is better
• Target Plan Cache AutoSize Hit Ratio
– The Hit Ratio autoSizing is trying to achieve by increasing the Plan Cache Size
Threshold, potentially up to the Maximum Plan Cache Size Allowed for
AutoSizing

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Summary and Usage

• Job Scoped
– Queries that reference files or indexes in the QTEMP or SESSION
schemas
– (The third value reflects the Total Number since IPL)
• Current Total Size of Temporary Run Time Objects …
– Includes hash tables, sorted lists, buffers, etc. Some are cached for
reuse.

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Configuration

• Plan Cache Configuration – All can be right clicked and changed


– *AUTO or *DEFAULT means that the database will determine the value,
strongly encouraged
• Longest Runs
– Indicates how many of the longest runs for a query should be retained
• Maximum Number of Temporary Runtime Objects
– Indicates how many temporary data structures may be retained for reuse
• Values of *AUTO or *DEFAULT mean the database determines the value
for the property
• Any manual changes are retained across IPL’s

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Activity Thresholds

• Activity Thresholds Start Time

– Reflects IPL and can also be reset which resets all of the recorded
threshold values

– Each threshold shows both the maximum value and the timestamp of
when that maximum was reached

• Each row shows the highest value and the time at which it was
reached

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Plan Cache Properties – Best Practices Db2 for i

• Use Automatic Plan Cache Sizing


– Leave adjusting the plan cache size to database
– At most, configure maximum size and target hit rate
– Remember that the plan cache is a pageable resource in the
*BASE pool and a 100 percent hit rate is not realistic

• Use the statistics to monitor areas of interest:


– Plan cache size
– Full opens
– Use of temporary files in QTEMP and/or SESSION
– Amount of storage consumed by temporary objects

• For incremental analysis, compare statistics from the start and


end of some nominal workload period
– Use the differences to calculate full opens, temporary files,
etc.

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Event Monitors

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache – Event Monitors

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
SQL Plan Cache – Event Monitors Db2 for i

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
SQL Plan Cache Snapshots Db2 for i

• System wide information materialized from the SQL Plan Cache


– No overhead – data capture is part of normal query optimization and
execution
– Pre-filtering
– Data is placed into a single table
• SQE support only
• SQL interface (CALL QSYS2/DUMP_PLAN_CACHE)
– SQL Plan Cache Snapshots are automatically registered
• GUI interface via Access Client Solutions
– Access / Filtering / Analysis by time, user, job, statement, etc.
– Visual Explain
• Data is not volatile
– Information from the SQL Plan Cache is “captured” at a point in time
• SQL Plan Cache is always available
– No need to “start and stop” a tool or utility
• Additional analysis methods available like “before and after” comparisons
• Copy to spreadsheet

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Filters …

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Plan Cache Snapshots

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

• System wide index advice


– Data is placed into a table (QSYS2/SYSIXADV)
– Autonomic
– No overhead
• The SQE optimizer provides complex advice based on all parts
of the query
• GUI interface via Access Client Solutions
– Advice by Database, Schema, or Table
– SYSIXADV can also be queried directly
• System only adds rows, user must manage the data
– Options to clear or prune
• Can create indexes directly from GUI
– Additional indexing analysis might be required
• Index advice can be condensed to eliminate redundant advice

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – System wide

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Advisor – Additional Options

• Clear All Advised Indexes


– Clears the index advice
• Condense Advised Indexes
– Display advice after eliminating
any redundant advice based on
keys and the key order
– Index with the keys A,B,C makes
an index with keys A,B redundant
– Index with keys A,B makes an
index with keys B,A redundant if
the keys are order independent
• Prune Advised Indexes
– Removes index advice that is no
longer valid, e.g. the table no
longer exists
• Options supported for a
database, schema, or table

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes – Columns

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes – Expression Builder

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Creating Indexes

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Index Builds

• The maintenance folder in Access Client Solutions shows index


builds and can help you monitor their progress

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Visual Explain

• Graphical representation of query plan


– Representation of the DB objects and data structures
– Representation of the methods and strategy
– Associated environmental information
– Advice on indexes and column statistics
– Highlighting of specific query rewrites
– Highlighting of expensive methods
• GUI interface via Access Client Solutions
• Based on detailed optimizer information
– SQL Plan Cache
– SQL Plan Cache Snapshots
– SQL Performance Monitor
• Additional function provided:
– Explain while running
– Print attributes for a given node

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Visual Explain

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Visual Explain – Explain while Running

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Details for Job (i.e. Connection)

Right click here


for Visual Explain

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Details for Job (i.e. Connection)

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
SQL Details for Job (i.e. Connection)

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i
Graphical Tools – Access Client Solutions

– Create and Manage Db2 for i Objects


– Work with Db2 for i Complex Objects, Procedures and
Functions
– Create, Save and Run SQL Scripts
– Change Query Attributes - QAQQINI
– Generate the SQL statements used to create a database
object
– Prompt and run CL commands

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation
Db2 for i

LAB - SQL Plan Cache and


SQL Details for Jobs

IBM Systems Lab Services – January 2019 Copyright 2019 IBM Corporation

You might also like