IBM ^ iSeries
© 2003 IBM Corporation
DB2 UDB for iSeries – The new Architecture
Sabine JordaniSeries Technical Support
DB2 UDB on iSeries
© 2003 IBM Corporation1
Trademarks & Disclaimer
! Course content and examples are based upon Version 5 Release 2 of OS/400 and DB2 UDB for iSeries. System and application behavior may be different on other releases of OS/400 and DB2 UDB.
! Example queries may not compile or run.! NOTICE: this publication may refer to products that are not currently available in your
country.! IBM makes no commitment to make available any products referred to herein.! IBM, eServer, iSeries, AS/400, OS/400 and DB2 are trademarks of the IBM Corporation
in the United States or other countries or both.! Other company, product, and service names may be trademarks or service marks of
others.! Java and all java-based trademarks and logos are trademarks of Sun Microsystems,
Inc. In the United States and/or other countries.! IBM’s VisualAge products and services are not associated with or sponsored by Visual
Edge software, ltd.! A list of trademarks may be found on the worldwide web:
http://www.ibm.com/trademarks.html
DB2 UDB on iSeries
© 2003 IBM Corporation2
V5R1 Database Architecture
SQLSQL
Static
Compiled embedded statements
Extended DynamicPrepare once
and then reference
Dynamic
Prepare every time
DB2 UDB(Data Storage & Management)
DB2 UDB(Data Storage & Management)
Host ServerHost Server CLI / JDBCCLI / JDBC
OptimizerOptimizer
ODBC / JDBC / ADO / DRDA / XDAODBC / JDBC / ADO / DRDA / XDA
Native(Record I/O)
Native(Record I/O)
NetworkNetwork
The optimizer and database engine are
separated at different layers of
the operating system
TIMI
DB2 UDB on iSeries
© 2003 IBM Corporation3
V5R2 Database Architecture
Optimizer
Query Dispatcher
CQE (Classic Query Engine)
Optimizer
SQE Optimizer
SLICDB2 UDB (Data Storage & Management)
SQE Optimizer
CQE Database Engine
SQE Primitives
SQE Statistic Manager
The optimizer and database engine
merged to form the SQL Query Engine and much of the
work was moved to SLIC
DB2 UDB on iSeries
© 2003 IBM Corporation4
What’s in a Name
! DB2 UDB for iSeries represents entire integrated database
! Optimizer now determines which engine will handle specific query – Classic Query Engine (CQE)
– SQL Query Engine (SQE)
! Still only one interface into Optimizer
DB2 UDB on iSeries
© 2003 IBM Corporation5
Query Dispatcher
D A T AD A T A S Q EC Q E
System Licensed Internal Code (SLIC)
Parts of the SQE Optimizer now reside in SLIC
Query Dispatcher
Optimizer
Non-SQL InterfacesOPNQRYFQuery/400
QQQQry API
Non-SQL InterfacesOPNQRYFQuery/400
QQQQry API
SQL Based InterfacesODBC / JDBC / CLI
Embedded & Interactive SQLRun SQL ScriptsQuery Manager
Net.DataRUNSQLSTM
SQL Based InterfacesODBC / JDBC / CLI
Embedded & Interactive SQLRun SQL ScriptsQuery Manager
Net.DataRUNSQLSTM
S Q EC Q E
DB2 UDB on iSeries
© 2003 IBM Corporation6
What goes to CQE?
– >1 Table (i.e. no joins)
– OR & IN predicates
– SMP requested
– Non-Read (INSERT with subselect can use new path)
– LIKE predicates
– UNIONS
– View or Logical File references
– Subquery
– Derived Tables & Common Table expressions
– LOB columns
– NLSS/CCSID translation between columns
– DB2 Multisystem
– Non-SQL queries (QQQQry API, Query/400, OPNQRYF)
New features PTF’d into V5R2 1H2003
DB2 UDB on iSeries
© 2003 IBM Corporation7
SQE Optimizer
! Finds best way to implement given query! No knowledge of metadata or system capabilities
– Asks questions on these factors
– Separation of responsibilities between Optimizer and Statistics Manager
! Access Plans organized in tree based structure! Responsible for collecting and processing
feedback information
DB2 UDB on iSeries
© 2003 IBM Corporation8
SQE Primitives
! Provide actual implementation of given query! More aggressive on using I/O subsystems and
main memory! Redesign of many data access methods
– Less CPU consumption
– New algorithms for distinct and SMP processing
! Temporary results retooled to eliminate need for a “true” database object to be created
DB2 UDB on iSeries
© 2003 IBM Corporation9
Statistics Manager
! Controls access to meta data used for query optimization– Does not run or optimize query
! Answers questions from Optimizer– Accuracy of answers dictates Optimizer’s ability to find
best plan
– Must always provide an answer
! Answers are derived from different sources
DB2 UDB on iSeries
© 2003 IBM Corporation10
Types of statistics questions
How many I/O’s will be required to process this table or index?I/O estimates
What indexes exist over a given table and what keys are interesting?Meta-data
How many records exist within a table?Meta-data
How many distinct occurrences of a value exist for a single column or multiple columns in a query?Cardinality
How many records will be selected by a given selection predicate or combination of predicates?Selectivity
DescriptionType of Question
DB2 UDB on iSeries
© 2003 IBM Corporation11
Sources for Answers
! Meta data sources– Existing indexes (radix or EVI)
– Information in physical objects (tables…)
– System information
! Default values – No representation of actual data
! Single Column Statistics NEW
DB2 UDB on iSeries
© 2003 IBM Corporation12
Column Cardinality
The number of distinct values in a column.
DB2 UDB on iSeries
© 2003 IBM Corporation13
Histograms
Distribution statistic that describes the selectivity and the distribution of values for a given column.
DB2 UDB on iSeries
© 2003 IBM Corporation14
Most Frequent Values List
A table of values that most frequently occurs within a column and a count of their frequency.
DB2 UDB on iSeries
© 2003 IBM Corporation15
Automatic Statistics Collection
! Automatic collection performed by default! Automatic update of collected column statistics
– > 15% change in number of records
– > 15% of records in table changed
– Checked when stats are used
! Performed as background job (QDBFSTCCOL)– Priority 90 to 99
– Low priority I/O
– Job goes to wait when higher priority job needs CPU
DB2 UDB on iSeries
© 2003 IBM Corporation16
Statistics Collection Interface
! Systemvalue QDBFSTCCOL controls automatic collection– *ALL
– *NONE
– *USER
– *SYSTEM
! iSeries Navigator graphical interface to column statistics– APIs available for use in programms
DB2 UDB on iSeries
© 2003 IBM Corporation17
Plan Cache
! Caches all plans optimized by SQE Optimizer– More reuse of plans regardless of interfaces
– Works in conjunction with systemwide statement cache, SQL programs and SQL packages
! Self managed– User doesn’t have to do any housekeeping
! Plan Cache is cleared at IPL
DB2 UDB on iSeries
© 2003 IBM Corporation18
Plan Cache Example
Plan A
Plan B
Plan C
Statement 1Statement 2
Statement 3Statement 4
Statement 3Statement 6
SQL Pgm X
SQL Package 1
SQL Package 2
Plan Cache
DB2 UDB on iSeries
© 2003 IBM Corporation19
Feedback Differences
! New DBMON records for stats feedback(QQRID 3015)
! QQC16 in 3014 record shows use of SQE (Y/N)! Optimizer may not recommend all possibly helpful
indexes! Optimizer recommends index creation without
checking whether they are already there! Order of debug messages / DBMON records may
be different
DB2 UDB on iSeries
© 2003 IBM Corporation20
How do I get it?
! All V5R2 systems take advantage of SQE! Code was refreshed via PTFs in May 2003
– Currently DB group PTF 9
– SI07650
! Refer to following website for availability of PTFsrequired for SQE– http://www.iseries.ibm.com/db2/sqe.html
DB2 UDB on iSeries
© 2003 IBM Corporation21
Additional Information
! Redbook “Preparing for and Tuning the V5R2 SQL Query Engine” – SG24-6598
! http://www.iseries.ibm.com/db2 (DB2 for iSerieshomepage)
! http://www.iseris.ibm.com/db2/books.htm (DB2 for iSeries manuals)
Top Related