Documente Academic
Documente Profesional
Documente Cultură
Currently, she is President of the Midwest Database Users Group (mwdug.org), and owns Sheryl M. Larsen, Inc., a firm specializing in Advanced DB2 Consulting and Education.
WWW.SMLSQL.COM
Contact: smlsql@comcast.net
(630) 399-3330
SQL Performance
DB2 Engine Components Predicate Processing Intelligence Optimizer Details SQL Performance Rules
SQL
Optimizer
Catalog
Meta Data
Directory
Access Plans
Buffer Pool
Buffer Manager
Data Index
RIDs
DB2 V8 Enhancements
8K 16K 32K Pages 64 Bit Addressing
Result
SQL
Optimizer
2M Statement Length Multi-row FETCH Multi-row INSERT SELECT INTO w/ ORDER BY Common Table Expressions Recursive SQL IS NOT DISCTINCT FROM Scalar Fullselect GROUP BY Expression Dynamic Scrollable Cursors INSERT with SELECT Multiple DISTINCT Clauses Sequences
Work Files
RID Pool
Stage 2
Catalog
Meta Data
Top & Bottom NUDS
Parallel Sort
Stage 1 Unlike Data Types IS NOT NULL IS NOT DISTINCT FROM
Directory Stage 1 Dynamic Access Plans Statement More Hybrid Joins Buffer Pool Cache
Buffer Manager
Data
SMLI 2009
Index
RIDs
DB2 9 WOW!
In Memory GLOBAL TEMP TABLES Views Table Expressions
TRUNCATE MERGE SELECT FROM UPDATE/DELETE EXCEPT, INTERSECT OLAP Expressions ORDER BY / FETCH FIRST in Subselect
Result
SQL
Histogram Statistics
Optimizer
Work Files
Sparse Indexes for more Work Files Faster Sorts for GROUP BY DISTINCT, ORDER BY
Stage 2
In Memory
RID Pool
Catalog
Meta Data
Global Optimization
Directory
Access Plans
More Parallelism
Page Range Index Screening For Partitioned Indexes
Buffer Manager
Data Index
RIDs
Sheryl M. Larsen, Inc. 2000-2009
Index on Expression
7
Stage 2
4K
Stage 1 Predicates
Predicate Type COL <> value COL <> noncol expr COL NOT BETWEEN value1 AND value2 COL NOT BETWEEN noncol expr1 AND noncol expr2 COL NOT IN (list) COL NOT LIKE ' char' COL LIKE '%char' COL LIKE '_char' T1.COL <> T2.COL T1.COL1 = T1.COL2 COL <> (non subq) COL IS DISTINCT FROM
1.
Indexable N N N N N N N N N N N N
Stage 1 Y Y Y Y Y Y Y Y Y Y Y Y
Indexable = The predicate is a candidate for Matching Index access. When the optimizer chooses to use a predicate in the probe of the index, the condition is named Matching (matching the index). This is the first point that filtering is possible in DB2. Index Screening = The Stage 1 predicate is a candidate for filtering on the index leaf pages. This is the second point of filtering in DB2. Data Screening = The Stage 1 predicate is a candidate for filtering on the data pages. This is the third point of filtering in DB2. Stage 2 = The predicate is not listed as Stage 1 and will be applied on the remaining qualifying pages from Stage 1. This is the fourth and final point of filtering in DB2.
2.
3.
4.
Y
Predicate Type
value BETWEEN COL1 AND COL2 COL BETWEEN COL1 AND COL2 COL BETWEEN expression1 AND expression2 value NOT BETWEEN COL1 AND COL2 T1.COL1 op T1.COL2 T1.COL1 <> T1.COL2 COL = ANY (non subq) COL = ALL (non subq) COL <> ANY (non subq) COL <> ALL (non subq) COL NOT IN (non subq) COL = (cor subq)
Indexable Stage 1
N N N N N N N N N N N N
Stage 1
N N N N N N N N N N N N
10
Predicate Type
Not made Indexable, . . V7 just rewrites the query to a join
COL = (cor subq) COL = ANY (cor subq) COL = ALL (cor subq) COL op (cor subq) COL op ANY (cor subq) COL op ALL (cor subq) COL <> (cor subq) COL <> ANY (cor subq) COL <> ALL (cor subq) COL IN (cor subq) COL NOT IN (cor subq) EXISTS (subq) NOT EXISTS (subq) expression = value expression <> value expression op value expression op (subquery)
Sheryl M. Larsen, Inc. 2000-2008
Indexable Stage 1
N N N N N N N N N N N N N N N N N
Stage 1
N N N N N N N N N N N N N N N N N
11
1
Non-Leaf Page O O O
C1.C2.C3 TOKEN_NR. O O O
Root Page
ROLE_CD
Non-Leaf Page O O Non-Leaf Page O O O O
2
Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o o
Use constants and literals if the values will not change in the next 3 years
Increase optimizer accuracy for static values
Sheryl M. Larsen, Inc. 2000-2008
13
Bad BETWEENs
WHERE 0001-01-01 BETWEEN B.SCND_ALOC_EFF_DATE AND B.SCND_ALOC_END_DATE Should be:
Do not place any local filtering in the ON clause for OUTER JOINs
Disallow during join filtering, encourage before join
Sequence filtering from most restrictive to least restrictive by table, by predicate type
WHERE AND AND AND AND A.COL2 = abracadabra A.COL1 IN (:hv1, :hv2, :hv3) A.COL4 > :hvcol4 A.COL3 > :hvcol3 A.COL5 LIKE %SON
Sheryl M. Larsen, Inc. 2000-2008
Ties Matter!
15
16
COLCARD
Factor for <, <=, >, >= BETWEEN, LIKE 1/100,000,000 1/10,000,000 1/1,000,000 1/100,000 1/10,000 1/1,000 1/100 1/3
17
6.
7. 8.
Examine Program logic Examine FROM clause Verify Join conditions Promote Stage 2s/Residuals Prune SELECT lists Verify local filtering sequence Analyze Access Paths Tune if necessary
Sheryl M. Larsen, Inc. 2000-2011
18
Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions including SQL/XML, Limited Fetch, Insensitive Scrollable Cursors, UNION Everywhere, MIN/MAX Single Index Support, Self Referencing Updates with Subqueries, Sor Avoidance for ORDER BY, and Row Expressions 2M Statement Length, GROUP BY Expression, Sequences, Scalar Fullselect, Materialized Query Tables, Common Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Table Support, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT clauses, ON COMMIT DROP, Transparent ROWID Column, call from trigger, statement isolation, FOR READ ONLY KEEP UPDATE LOCKS, SET CURRENT SCHEMA, client special registers, long SQL Object names, SELECT FROM INSERT, UPDATE, DELETE, MERGE, INSTEAD OF TRIGGER, Native SQL Procedure Language, BIGINT, file reference variables, XML, FETCH FIRST & ORDER BY IN subselect and fullselect, caseless comparisons, INTERSECT, EXCEPT, not logged tables, DECIMAL FLOAT, XQuery,TRUNCATE OLAP Functions, Session variables, OmniFind, Spatial, ROLE
GROUPING SETS, ROLLUP, CUBE, Many Built-in Functions, SET CURRENT ISOLATION , multi-site join, MERGE, ARRAY data type, global variables, Oracle syntax, XML enhancements
Sheryl M. Larsen, Inc. 2000-2008
19
1. Use joins over subqueries when detail row information is required 2. Use subqueries over joins when detail row information is not required 3. Use INNER JOIN over LEFT JOIN when exceptions are not expected or needed 4. Use CREATE GLOBAL TEMPORARY TABLE when data is infrequently accessed 5. Use DECLARE GLOBAL TEMPORARY TABLE with a clustered index when DTT is large and data is frequently accessed
Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions including SQL/XML, Limited Fetch, Insensitive Scroll Cursors, UNION Everywhere, MIN/MAX Single Index, Self Referencing Updates with Subqueries, Sort Avoidance for ORDER BY, and Row Expressions, 2M Statement Length, GROUP BY Expression, Sequences, Scalar Fullselect, Materialized Query Tables, Common Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Tables, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT clauses, ON COMMIT DROP, Transparent ROWID Column, Call from trigger, statement isolation, FOR READ ONLY KEEP UPDATE LOCKS, SET CURRENT SCHEMA, Client special registers, long SQL object names, SELECT from INSERT, UPDATE or DELETE, INSTEAD OF TRIGGER, Native SQL Procedure Language, BIGINT, file reference variables, XML, FETCH FIRST & ORDER BY in subselect & fullselect, caseless comparisons, INTERSECT, EXCEPT, not logged tables, OmniFind, spatial, range partitions, data compression, session variables, DECIMAL FLOAT, optimistic locking, ROLE, TRUNCATE, index & XML compression, created temps, inline LOB, administrative privileges, implicit cast, date/time changes, currently committed, moving sum & average, index include columns, row and column access control, time travel query
Updateable UNION in Views, GROUPING SETS, ROLLUP, CUBE, more Built-in Functions, SET CURRENT ISOLATION, multi-site join, MERGE, MDC, XQuery, XML enhancements, additional data type (array, row, cursor), global variables, even more 21 vendor syntax, temp table compression, MODULEs
DB2 11 SQL Standard SQL support (not exhaustive, some features may be missing)
DB2 11 for z/OS and DB2 10.5 Linux, Unix & Windows
z
c o m m o n l u w
Multi-row INSERT, FETCH & multi-row cursor UPDATE, Dynamic Scrollable Cursors, GET DIAGNOSTICS, Enhanced UNICODE SQL, join across encoding schemes, IS NOT DISTINCT FROM, VARBINARY, FETCH CONTINUE, SELECT FROM MERGE, MERGE, routine versioning, transparent archive query
Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions including SQL/XML, Limited Fetch, Insensitive Scroll Cursors, UNION Everywhere, MIN/MAX Single Index, Self Referencing Updates with Subqueries, Sort Avoidance for ORDER BY, and Row Expressions, 2M Statement Length, GROUP BY Expression, Sequences, Scalar Fullselect, Materialized Query Tables, Common Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Tables, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT clauses, ON COMMIT DROP, Transparent ROWID Column, Call from trigger, statement isolation, FOR READ ONLY KEEP UPDATE LOCKS, SET CURRENT SCHEMA, Client special registers, long SQL object names, SELECT from INSERT, UPDATE or DELETE, INSTEAD OF TRIGGER, SQL PL in routines, BIGINT, file reference variables, XML, FETCH FIRST & ORDER BY in subselect & fullselect, caseless comparisons, INTERSECT, EXCEPT, MERGE not logged tables, OmniFind, spatial, range partitions, data compression, DECFLOAT, optimistic locking, ROLE, TRUNCATE, index & XML compression, created temps, inline LOB, administrative privileges, implicit cast, increased timestamp precision, currently committed, moving sum & average, index include columns, row and column access controls, time travel query, GROUPING SETS, ROLLUP, CUBE, global variables, Text Search functions, accelerated tables, DROP COLUMN, array data type, XML enhancements
Updateable UNION in Views, more Built-in Functions, SET CURRENT ISOLATION, multi-site join, full MERGE, MDC, XQuery, additional data type (row, cursor), even more vendor syntax, temp table compression, MODULEs
Name: __________________
Level
Assessment = YOU CAN FULLY UNDERSTAND THE FEATURE AND PROPER USE OF:
Before:_______
0 1
You think SQL is a new energy drink Simple SELECT statements, WITH clause, ORDER BY WHERE clauses, BETWEEN, LIKE, IN(list), =, >=, >, <, <=, <>, NOT IN(list), NOT LIKE, NOT BETWEEN, DISTINCT Table joins (inner, outer, full), UNION, UNION ALL, CONCAT, static CURSORs, FOR UPDATE OF, ROW_NUMBER, EXCEPT, INTERCEPT noncorrelated and correlated subqueries, EXISTS, NOT EXISTS, FETCH FIRST x ROWS ONLY, OPTIMIZE FOR x ROWS, MERGE, TRUNCATE Indexable, Stage1 and Stage 2 predicate evaluation, multirow FETCH/INSERT, GET DIAGNOSTICS, Scalar full SELECT
Table expressions/common table expressions, GROUP BY, HAVING, IS NOT DISTINCT FROM, embedded dynamic SQL, ORDER BY/FETCH FIRST in subselect, FETCH CONTINUE
CASE expressions, Global Temporary Table (GTT), Declared Temporary Table (DTT), Dynamic Scrollable cursors, SEQUENCES/IDENTITY Queries involving > 10 tables, INSERT within (SELECT , UPDATE, DELETE, MERGE), Star Schema, GROUP BY expression MQT (Materialized Query Tables), Recursive SQL, UNION in Views, > 30 useful Built-in Functions, DENSE_RANK, RANK Codes effective and efficient SQL applying performance rules and knows when to use each SQL feature appropriately
10
After:________
Not until the query is coded the best it can be All predicates are the best they can be
Promote Stage 2s if possible Promote Stage 1s if possible Apply performance rules
Check Access Paths of all Query Blocks Apply data knowledge and program knowledge to predict response time If, and only if, the predicted service levels are not met - TUNE!
24
Performance! Host variables force the optimizer to guess IBM optimizer researchers and developers provide extremely good guesses Occasionally (2-7% of queries) they guess wrong Have no fear, changing the optimizers mind is easier than you think
Sheryl M. Larsen, Inc. 2000-2011
25
Do not change statistics, just keep accurate Do not panic Choose a proven, low maintenance, tuning technique IBMs list:
OPTIMIZE FOR n ROWS FETCH FIRST n ROWS ONLY No Op (+0, CONCAT ) TX.CX=TX.CX REOPT(VARS) ON 1=1
Sheryl M. Larsen, Inc. 2000-2011
26
No Operation
SELECT S.QTY_SOLD, S.ITEM_NO , S.ITEM_NAME FROM SALE S WHERE S.ITEM_NO > :hv ORDER BY ITEM_NO Limited FETCH FIRST 22 ROWS ONLY
Fetch
WHERE B.BID BETWEEN :hvlo AND :hvhi AND B.BID = D.DID AND B.SID = S.SID AND B.COL2 >= :hv AND B.COL3 >= :hv AND B.COL4 >= :hv
Sheryl M. Larsen, Inc. 2000-2011
Fake Filter
27
Tuning Tools
28
UNION queries for index access until V3 Multiple Index Access (Predicate OR 0 = 1) until V5 No Operations Layered Table Expressions until V6 smarter optimizer Correlated Subqueries until V7 query re-write No cross table indexes - until V8 Materialized Query Tables (more on that later)
29
Step 1
Learn the DB2 Access Paths
www.smlsql.com
www.ca.com/ Google Sheryl Larsen
31
Direct Row
32
Limited Partition Scan With Partitioning Index Limited Partition Scan With NPSI
All can be parallel All can omit data access Clustering index or nonclustering access
Root Page O O O
Non-Leaf Page O O
range
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
33
One Fetch
SELECT MAX(C3) FROM T1 WHERE C1 = L ANDType C2 2 =Index 99 SELECT MIN(C1) FROM T1
C1.C2.C3 O O O
Non-Leaf Page O O O O
Root Page
1
Leaf Page o o oo oo
Non-Leaf Page O O O
Non-Leaf Page O O
3
Leaf Page o o oo o o
Leaf Page o o oo oo
Leaf Page o o oo o o
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o o o o o
34
1
Non-Leaf Page O O O
C1.C2.C3 O O O
Non-Leaf Page O O O O
Root Page
Non-Leaf Page O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
35
1
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
2
Sheryl M. Larsen, Inc. 2000-2011
36
1
Leaf Page o o o o o o
2
Leaf Page o o o o o o
3
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
37
1
Leaf Page o o o o o o
1
Leaf Page o o o o o o
1
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
38
List Prefetch
WHERE C1 > 50 AND C2 = :hv
COL1 Index
Root Page O O O
1
Non-Leaf Page O O O
2
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3 4
39
WHERE C2 = :hv
COL2 Index
Root Page O O O
1
Non-Leaf Page O O O
Root Page O O O
C1
4
Non-Leaf Page O O O O
Non-Leaf Page O O
C2
2
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O
Non-Leaf Page O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
AND/OR 3
7
8
40
41
C1 Parts
1
Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
1
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Type 2 Index
Root Page O O O
Non-Leaf Page O O
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
42
Limited Partition Scan Using Nonclustered Partitioning Index WHERE CORP IN (20,
Partitioning Index Nonclustered
1
Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
CORP
Type 2 Index
Root Page O O O
1
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Type 2 Index
Root Page O O O
Non-Leaf Page O O
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
43
WHERE TOKEN_NR BETWEEN ? AND ? AND TICKET_PREFIX = A AND LAST_NM LIKE LAR%
1
Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
1
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Type 2 Index
Root Page O O O
Non-Leaf Page O O
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
44
1
Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
1
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Type 2 Index
Root Page O O O
Non-Leaf Page O O
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
45
Type 2 Index
Root Page O O O
1
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
46
BP03
TOKEN_NR BETWEEN ? AND ? AND LAST_NM_LIKE ?
New
Partition by Date Partition by Date Cluster by Custid Partition by Date Cluster by Custid Partition by Date Cluster by Custid Partition Cluster by by TOKEN_NR Custid Cluster by LAST_NM
Sheryl M. Larsen, Inc. 2000-2011
47
Partitioning by Date 1
Type 2 Index
Root Page O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Clustered by Customer 1 2
Type 2 Index
Root Page O O O Non-Leaf Page O O O Non-Leaf Page O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Non-Leaf Page O O O O
Non-Leaf Page O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3
Sheryl M. Larsen, Inc. 2000-2011
3
48
can be parallel
If
not enough room in memory, at run time create sparse index instead
49
Table Scan
WHERE C1 BETWEEN :lowest AND :highest
50
1
Part 1
Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8
51
1
Part 1
Part 3 Part 4 Part 16 Part 17 Part 18
52
choose outer table and filter first Nested Loop Hybrid Join Type C All can be parallel (Star Hybrid Join Type N CPU only ) Merge Scan Join Worry about join table Star Join Cartesian sequence instead of join Star Join Pair Wise method
53
WHERE T1.ORDER > 222 AND T1.ID = T2.ID AND T2.COLOR IN (BLUE, YELLOW, GREEN)
Root Page O O O
Non-Leaf Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Inner Index
Root Page O O O
ID.COLOR index
Non-Leaf Page O O O O
Non-Leaf Page O O O
Non-Leaf Page O O
3
4
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
54
1
Leaf Page o o o o o o
Non-Leaf Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
COL2 Index
Root Page O O O
Non-Leaf Page O O
Non-Leaf Page O O
Non-Leaf Page O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Filtered outer
R I D S
3 6 5
55
1
Leaf Page o o o o o o
Root Page O O O
Non-Leaf Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
COL2 Index
Root Page O O O
Non-Leaf Page O O
Non-Leaf Page O O
Non-Leaf Page O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
3 4
Sheryl M. Larsen, Inc. 2000-2011
56
57
1 2 6
Non-Leaf Page O O O
3
Inner Index Big/Fact Table Index
Root Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
5
Sheryl M. Larsen, Inc. 2000-2008
58
1
Type 2 Index
Root Page O O O Non-Leaf Page O O O Non-Leaf Page O O Non-Leaf Page O O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Non-Leaf Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
2
Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Type 2 Index
Root Page O O O
3
Non-Leaf Page O O O O Non-Leaf Page O O O Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o Leaf Page o o o o o o
Type 2 Index
Root Page O O O
Non-Leaf Page O O O
Non-Leaf Page O O
Non-Leaf Page O O
Non-Leaf Page O O O O
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
Leaf Page o o o o o o
4 5 8 9
59
3.
Create table with ROWID type column (DIRECT_ID) SELECT DIRECT_ID INTO :direct-id FROM TAB12 2 WHERE UKEY = AMX UPDATE TAB12 3 WHERE DIRECT_ID = :direct-id
1
DIRECT_ID AMX DIRECT_ID
DIRECT_ID
DIRECT_ID
60
61
Step 2
Interpret the Optimizers Decisions
62
Find out what the general access path is for each query block (subselect, union, table expression) Calculate execution frequencies of each query block
Correlated subselects execute bottom query block once for each qualifying row in bottom query
Identify join table sequence Identify materialization (intermediate or final) Identify sorts (even hidden Rid sorts an IN(list) Identify User Defined Table or Column functions
Sheryl M. Larsen, Inc. 2000-2011
63
Using EXPLAIN
EXPLAIN PLAN SET QUERYNO = n FOR ..; SELECT * FROM PLAN_TABLE ORDER BY ..;
Q No
1 1 2 2 2
Qblock Step No No
1 1 1 1 1 1 2 1 2 3
Meth
0 4 0 2 4
Access Type
R I N I I
Match Cols
0 2 2 2 2
Pre Fetch
S L
Join Type
IX Only
N N Y
IX Name
IX22
F L
N N
IX27 IX42
3 3
1 2
1 1
0 2
I R
4 0 S
N N
IXF1
64
Using EXPLAIN
SORTN UJOG NNNN NNNN NYNN NNNN NNNN NNNN NNNN NNNN NNNN SORTC UJOG NNYN NNNN NNNN NNNN NNNN NNNN NNNN NNNN NNNN R S Y Y Y Y R R Page Col Range Func Y S S Corr Name AB CD EF XX GA SL ML KL TL Qblock Type SELECT UPDATE INSERT DELECT NCOSUB CORSUB DELCUR UPDCUR SELUPD SS SS XX XX XX Opt Hint GG NN Hint Used GG TS Remark s Good 1 Bad 1 +0 Bogus 3 Extra > parens help
. . . . . . . . .
65
Learning EXPLAIN
Need IBMs definition of the PLAN_TABLE Need a way to transform PLAN_TABLE into something readable (i.e. QMF Form or program) Review PLAN_TABLE contents with Access Path descriptions Study, practice, practice, practice
66
Using DSN_STATEMENT_TABLE
Explain Time Stmt Type Cost Cat PROCMS PROCSU Reason
Time Stamp
SEL UPD
A or B
Milli seconds
Service Units
For Cat B
67
Service Units
http://www-03.ibm.com/servers/eserver/zseries/srm/
zSeries 990
Processor Model 2084-301 2084-302 2084-303 2084-304 STIDP Type 2084 2084 2084 2084 STSI Model Name 301 302 303 304 #C P 1 2 3 4 SU/SEC 21857.9235 20752.2698 20075.2823 19559.9022 SRMsec/RealSec 508.1298 508.1298 508.1298 508.1298
68
Service Units
IBM System z10
Processor Model 2097-401 2097-402 2097-501 2097-502 2097-503 2097-701 2097-702 2097-703 2097-704 STIDP Type 2097 2097 2097 2097 2097 2097 2097 2097 2097 STSI Model Name 401 402 501 502 503 701 702 703 704 #CP 1 2 1 2 3 1 2 3 4 SU/SEC 11291.4608 10680.9079 24427.4809 23021.5827 22222.2222 47619.0476 44692.7374 43010.7527 41666.6667 SRMsec/RealSec 262.6049 262.6049 568.1815 568.1815 568.1815 1106.1941 1106.1941 1106.1941 1106.1941
69
EXPLAIN
BLOCK PLAN METH TABLE_NAME PQB TYPE MC ANAME IO --+---------+---------+---------+---------+---------+---------+---------+------01 01 00 R10_CLM_FACT12 12 M 00 N 01 01 00 R10_CLM_FACT12 01 X011_10_12_F_IX07 Y Index Name 12 MX 01 01 00 R10_CLM_FACT12 12 MX 01 X011_10_12_F_IX04 Y 01 01 00 R10_CLM_FACT12 12 MI 00 N 01 01 00 R10_CLM_FACT12 12 MX 01 X011_10_12_F_IX04 Y 01 01 00 R10_CLM_FACT12 12 MX 01 X011_10_12_F_IX04 Y Index Only? 01 01 00 R10_CLM_FACT12 12 MU 00 N 01 01 00 R10_CLM_FACT12 12 MI 00 N 01 02 01 OTR_PRTY_LIAB_NET 12 N 03 OPL_NET_IX04 N Step # 01 03 01 MEMBER_ELIG_NET 12 N 04 MBR_ELIG_NET_IX06 Y 01 04 01 R10_CHG_FACT12 12 N 03 X007_10_12_F_IX19 N 01 05 01 R10_MULTI_CD_FAC12 12 I 02 X021_10_12_F_IX14 N Join Method 02 01 00 R10_CHG_FACT12 09 N 03 X007_10_12_F_IX19 Y
dave@davebeulke.com
70 smlsql@comcast.co
SNU SNJ SNO SNG SCU SCJ SCO SCG PF QB_TYPE STMT_TYPE T_TP PR JT +---------+---------+---------+---------+---------+---------+---------+------N N N N N N N N L NCOSUB SELECT T N N N N N N S NCOSUB SELECT T O NG N U N N N Nr Nr N N N S NCOSUB SELECT T J n N N N N No N N N Limited NCOSUB SELECT Partition Scan? T d o N N N N Nu N N N S NCOSUB SELECT T i e i N N N Nr Np N N N S NCOSUB SELECT T q n N N N N N N N N NCOSUB SELECT T u N N N N N N NCOSUB SELECT T B NB N e N N N N N N N NCOSUB SELECT T y N y Prefetch N N N N N N N N NCOSUB SELECT T N N N N N N N N NCOSUB SELECT Type T N N N N N N N N NCOSUB SELECT T N N N N N N N N CORSUB SELECT T
smlsql@comcast.com
dave@davebeulke.com
72
Step 3
Fetch Top CPU Consumers
73
Tuning SQL
FIND
---------+---------+--PROGNAME PROCSU ---------+---------+--EXPNPROG 121,059,664 EXPNPROG 21,059,664 ONESECPG 79,664 SUBSECPG 9,664 CHEEPPRG 64 FREEPROG 4
dave@davebeulke.com
74 smlsql@comcast.co
2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647 2,147,483,647
Copyright Sheryl Larsen 2011
75 smlsql@comcast.co
Step 4
Learn Traditional and Extreme Tuning Techniques
76
Experiment with Extreme Tuning Techniques DISTINCT Table Expressions Correlated Table Expressions Odd/old Techniques Anti-Joins Manual Query Rewrite (X2QBOpt) covered in Extreme
77
78
SELECT S.QTY_SOLD , S.ITEM_NO , S.ITEM_NAME FROM SALE S WHERE S.ITEM_NO > :hv ORDER BY ITEM_NO
Optimizer choose List Prefetch Index Access + sort for ORDER BY for 50,000 rows All qualifying rows processed (materialized) before first row returned = .81 sec <.1sec response time required
Optimizer now chooses Matching Index Access (first probe .004 sec) No materialization Cursor closed after 22 items displayed (22 * .0008 repetitive access) .004 + .017 = .021 sec
SELECT S.QTY_SOLD, S.ITEM_NO , S.ITEM_NAME FROM SALE S WHERE S.ITEM_NO > :hv ORDER BY ITEM_NO FETCH FIRST 22 ROWS ONLY
79
80
No Op Example CONCAT
SALES_ID.MNGR.REGION Index
SELECT S.QTY_SOLD , S.ITEM_NO , S.ITEM_NAME FROM SALE S WHERE S.SALES_ID > 44 AND S.MNGR = :hv-mngr AND S.REGION BETWEEN :hvlo AND :hvhi ORDER BY S.REGION . FROM SALE S WHERE S.SALES_ID > 44 AND S.MNGR = :hv-mngr AND S.REGION BETWEEN :hvlo AND :hvhi CONCAT ORDER BY R.REGION
MNGR Index
REGION Index
Optimizer chooses Multiple Index Access The table contains 100,000 rows and there are only 6 regions Region range qualifies 2/3 of table <.1sec response time required No Op allows Multiple Index Access to continue on first 2 indexes Two Matching index accesses, two small Rid sorts, & Rid intersection ____unique Rids/16 * .000375 sec = _____ + sort for Region = ______
81
No Op Example - Scan
SALES_ID.MNGR.REGION Index MNGR Index REGION Index
SELECT S.QTY_SOLD , S.ITEM_NO , S.ITEM_NAME FROM SALE S WHERE S.SALES_ID > 44 +0 AND S.MNGR = :hv-mngr CONCAT AND S.REGION BETWEEN :hvlo AND :hvhi CONCAT ORDER BY S.REGION FOR FETCH ONLY WITH UR
If you know the predicates do very little filtering, force a table scan Use a No Op on every predicate This forces a table scan FOR FETCH ONLY encourages parallelism WITH UR for read only tables to reduce CPU
82
REOPT
Long running queries/programs easily benefit High volume transactions will reflect the cost of the rebind (90% of a full BIND)
83
Fake Filtering
Fake Predicates
To encourage index access To alter table join sequence when nothing else works Works by decreasing filter factor on a certain table The filtering is fake and negligible cost Not effective for dynamic queries if the filter contains :host variables
84
Nested
Loop
S.SID Index 20 rows B.BID Index 6 billion rows
Joins
Large report query with average of 400,000 row range of BID table Need to start nested loop with big table Tools required
85
Nested Loop
Joins
S.SID Index 20 rows
Keep adding filters until table join sequence changes Start with index columns To preserve index-only access No limit! For Dynamic
86
ON 1 = 1
ON
1=1
To fill in a required join field To request a star join When table ratios are under the system specified number (starts at 1:25) Can benefit when large table has high selectivity
87
88
Work File
SELECT Columns FROM TABX, TABY, (SELECT DISTINCT COL1, COL2 .. FROM BIG_TABLE Z WHERE local conditions) AS BIGZ WHERE join conditions
Optimizer is forced to analyze the table expression prior to joining TABX & TABY
90
Result
is only 1,000 rows ADDR and NAME first two tables in join Index scan on TAB6 table
Not good because zero filter
Sheryl M. Larsen, Inc. 2000-2011
91
Tuning Technique
SELECT COL1, COL2 .. FROM ADDR, NAME, (SELECT DISTINCT columns FROM TAB3, TAB4, TAB5, TAB6, TAB7 WHERE join conditions AND (TAB6.CODE = :hv OR 0 = 1)) AS TEMP WHERE join conditions Gets rid of Index Scan
Keeps large tables joined last
92
Performance gains
Access path changes Encourages Nested Loop Join Reduced processing and/or materialization
SELECT Columns from either set of data FROM table1 T1 ,TABLE(SELECT T2.STUDENT_YEAR, SUM(C8) AS SUM8, MAX(C9) AS MAX9 FROM table2 T2 WHERE T1.column = T2.column GROUP BY T2.STUDENT_YEAR) AS T2
93
a students class load, and average & max class load of their peers
SELECT SR.NAME, SS.CLASS_LOAD, P.AVG_CLASS_LOAD, P.MAX_CLASS_LOAD FROM SMLU_STUDENT_ROSTER SR , TABLE(SELECT SR2.STUDENT_YEAR ,AVG(SR2.NUM_OF_CLASSES) AS AVG_CLASS_LOAD ,MAX(SR2.NUM_OF_CLASSES) AS MAX_CLASS_LOAD FROM SMLU_STUDENT_ROSTER SR2 WHERE SR.STUDENT_YEAR = SR2.STUDENT_YEAR GROUP BY SR2.STUDENT_YEAR) AS P LEFT JOIN TABLE(SELECT SS.SID, COUNT(*) AS SS.CLASS_LOAD FROM SMLU_STUDENT_SCHED SS WHERE SS.SID = SR.SID GROUP BY SS.SID) as SS ON 1=1
Sheryl M. Larsen, Inc. 2000-2011
94
Anti-Join
SELECT Columns FROM TABY Y LEFT JOIN TABX X ON X.COL1 = Y.COL1 WHERE X.COL1 IS NULL
SELECT Columns FROM TABX X WHERE NOT EXISTS (SELECT * FROM TABY Y WHERE X.COL1 = Y.COL1)
TABX Exceptions
TABY Exceptions
Inner Join SELECT Columns FROM TABX X, TABY Y WHERE X.COL1 = Y.COL1
95
Anti-Join
TABX Exceptions
SELECT Columns FROM TABX X WHERE NOT EXISTS (SELECT * FROM TABY Y WHERE X.COL1 = Y.COL1)
Stage 2 when correlated
Indexable Stage 1
SELECT Columns FROM TABX X LEFT JOIN TABY Y ON X.COL1 = Y.COL1 WHERE Y.COL1 IS NULL
96
Step 5
Tune if Necessary
97
List Onlines Doing List Prefetch List Index Scans List Nasty Hybrid Joins
SYSPACKSTMT
WHERE STMT LIKE %WHERE_:%BETWEEN%
WHERE
List NOTs
WHERE
WHERE
99
Step 6
Designing Optimal Performance Structures for One Query or a Workload
100
Equal predicates first Sequencing columns next Predicates most restrictive to least restrictive All remaining SELECT Columns
Type 2 Index
Root Page C4.C5.C6.C1.C2.C3.C9.C7.C8.C12 O O O
SELECT C7, C8, C12, C2, C3 WHERE C4 = L AND C5 = 99 AND C6 = :hv AND C1 IN (:a,:b,:c) AND C2 NOT LIKE :hv AND C3 BETWEEN :hvstart AND :hvend AND C9 = (CASE expression) ORDER BY C1.C2.C3
Non-Leaf Page O O O O
Non-Leaf Page O O O
Non-Leaf Page O O
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o o o o o
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o o o o o
Leaf Page o o oo oo
Leaf Page o o oo oo
Leaf Page o o o o o o
101
MQT strategies
HUGE MQT with many indexes Many small MQTs with few indexes
Optimal
MQT strategy
102
at Execution
103
MQT
CREATE TABLE ORG_LIST AS ( WITH ORG_CHART(BOSS, DIRECT_REPORT, N) AS (SELECT BOSS, DIRECT_REPORT, 1 FROM ORG_TABLE WHERE BOSS= SAM UNION ALL SELECT T1.BOSS, T2.DIRECT_REPORT, N+1 FROM ORG_CHART T2, ORG_TABLE T1 WHERE T2.DIRECT_REPORT = T2.BOSS ) SELECT BOSS, DIRECT_REPORT, N FROM ORG_CHART) DATA INITIALLY DEFERRED REFRESH DEFERRED MAINTAINED BY SYSTEM ENABLE QUERY OPTMIZATION;
104
Query Speed Up
WITH ORG_CHART (BOSS, DIRECT_REPORT, N) AS (SELECT BOSS, DIRECT_REPORT, 1 FROM ORG_TABLE WHERE BOSS= BETH UNION ALL SELECT T1.BOSS, T2.DIRECT_REPORT, N+1 FROM ORG_CHART T2, ORG_TABLE T1 WHERE T2.DIRECT_REPORT = T2.BOSS AND N < 10 0,000) SELECT BOSS, DIRECT_REPORT, N FROM ORG_CHART
Accessed at Execution
ORG_LIST
Designing Indexes
For a Workload
106
Table/Column Usage
Tran tran1
c1
q1 q2 q3
O1 G1
=T4.C2
c2
O2 G2
=:hv
c3 c4 c5
O3 G3
>800
c6 c7 c8 c9
S S S
O1 = Order By First Position G1 = Group By First Position S = SELECT list W = Local or Join WHERE/ON or Specify actual local/join filter Specify Group by Aggregates as: Aggr BY Column(s)
c10
c11
MAX by C1.C2. C3
=T2.C1
AVG by C1.C2.C3
s
=T3.C1
w s
=22
o1 s
=:hv o2
o1
=T3.C11
=T3.C1
tran2
q1 q2
O1 s
O2 s
O3
=:hv
=:hv
>:hv
O1
IN(list)
LIKE :hv
107
Final Ranking
Weight
tran 1
100
4200
q1 q2 q3
4200 O O4200 S w S S S 4200 2 3 4200 G4200 4200 4200 4200 4200 w 4200 G 2 3 4200 4200 w w s10 w 10 w 10 w o10 1 w 10 o2 10
10 9900
9900
tran2
3 0 0
Frequency * Weight
Sheryl M. Larsen, Inc. 2000-2011
108
Determining Weight
Copy
the top 30% Lets say 5,500 is top Sort by Frequency frequent Pull of the top number Then 55,000 is the goal Multiply by 10 Now you have the frequency number to beat
Sheryl M. Larsen, Inc. 2000-2011
109
Grand Total
By Table, by Operation
c1
O1 55980 G1 4790 O2 2220 O6 70 W 3920
Total Activity
c2
c3
c4 c5
O1 8740 S 8740 w 22090
c6
O2 3940 S 480
c7
c8
Use
110
Summary
It is Easy to Change the Optimizers Mind The Trick is to Know WHEN to use:
Extreme Tuning Techniques DISTINCT Table Expressions Correlated Table Expressions OR 0 = 1 Anti-Join Technique Index and MQT Design X2QBOpt
111
Traditional Tuning Techniques OPTIMIZE FOR n ROWS No Ops REOPT(VARS) Fake Filtering Index & MQT Redesign
DB2 Developers Guide, Sixth Edition SAMS Publishing, Craig S. Mullins Covers DB2 9 & 10 for z/OS!!!!!
112