23
1 z/OS Application Development DB2 10 – What to Implement First! Sheryl M. Larsen Sheryl M. Larsen Sheryl M. Larsen, Inc. Sheryl M. Larsen, Inc. Platform: September 20, 2012 NEODB2UG, Sturbridge, MA

1 z/OS Application Development DB2 10 – What to Implement First! Sheryl M. Larsen Sheryl M. Larsen, Inc. Platform: September 20, 2012 NEODB2UG, Sturbridge,

Embed Size (px)

Citation preview

1

z/OS

Application Development

DB2 10 – What to Implement First!

Sheryl M. LarsenSheryl M. LarsenSheryl M. Larsen, Inc.Sheryl M. Larsen, Inc.

Platform:

September 20, 2012

NEODB2UG, Sturbridge, MA

2© Sheryl M. Larsen, Inc. 2000-2012Contact: [email protected] (630) 399-3330 WWW.SMLSQL.COMContact: [email protected] (630) 399-3330 WWW.SMLSQL.COM

Sheryl M. Larsen, Inc.DB2 SQL Consulting & Education

Sheryl has over 20 years experience in DB2, has published articles, white papers, webtv:WWW.IBM.DEVELOPERWORKS.COM

WWW.CA.COM

WWW.BMC.COM

WWW.SOFTBASE.COM

Sheryl Larsen is an internationally recognized researcher, consultant and lecturer, specializing in DB2 and is known for her extensive expertise in SQL. She co-authored a book, DB2 Answers, Osborne-McGraw-Hill, 1999.

She was voted an inaugural IBM Information Champion 2009 , IDUG Speaker Hall of Fame and, a member of IBM’s DB2 Gold Consultants program since 1994.

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.

3© Sheryl M. Larsen, Inc. 2000-2012

DB2 10 – WOW!

DirectoryDirectory

WorkWorkFilesFiles

Buffer Pool

SQL

CatalogCatalog

DataData

Buffer Manager

Result

Stage 2

IndexIndex

Stage 1 DirectoryDirectory

CatalogCatalog

In MemoryQuery techniques

In Memory

Buffer pool enhancements

New technique for p-key access

Automatic Stats Collection

Indexing support of DECFLOAT

Dynamic Index ANDing improvements

Moving SUMMoving AVG

Enhanced Parallelism

Caching of dynamic SQL with literals

Individual cells restricted,value returned with

access denied

Greater TIMESTAMP precision

Instance Based SQL Hints

Caching DB2 CodeAnd control structures

INCLUDE Indexing support

SQL Paging for partial result

Temporal Semantics

4© Sheryl M. Larsen, Inc. 2000-2012

DB2 10 for z/OS

DB2 10 Optimization Enhancements

Data dependent paging

DB2 10 SQL EnhancementsIndex INCLUDE OptionMoving SUMMoving AVGTemporal Data Requests

5

© Sheryl M. Larsen, Inc. 2000-2012

Declare BRWSUM1 Cursor

COL1 COL2 COL3 COL4 COL5

A 1 TT 99 Data ….

A 1 UU 77 Data ….

A 4 SS 66 Data ….

B 2 RR 66 Data ….

B 3 RR 77 Data ….

B 3 RR 88 Data ….

B 3 SS 66 Data ….

B 4 SS 99 Data ….

B 4 UU 88 Data ….

C 1 SS 66 Data ….

C 1 SS 77 Data ….

DELCLARE BRWSUM1 CURSOR FORDELCLARE BRWSUM1 CURSOR FORSELECT COL5 SELECT COL5 FROM BRWSUMFROM BRWSUMWHERE ((COL1 = :col1-lastWHERE ((COL1 = :col1-last AND COL2 = :col2-lastAND COL2 = :col2-last AND COL3 = :col3-lastAND COL3 = :col3-last AND COL4 > :col4-last)AND COL4 > :col4-last)OR (COL1 = :col1-lastOR (COL1 = :col1-last AND COL2 = :col2-lastAND COL2 = :col2-last AND COL3 > :col3-last)AND COL3 > :col3-last)OR (COL1 = :col1-lastOR (COL1 = :col1-last AND COL2 > :col2-last)AND COL2 > :col2-last) OR (COL1 > :col1-last)) OR (COL1 > :col1-last))ORDER BY COL1, COL2, COL3, COL4ORDER BY COL1, COL2, COL3, COL4FETCH FIRST 5 ROWS ONLY;FETCH FIRST 5 ROWS ONLY;

6

© Sheryl M. Larsen, Inc. 2000-2012

Get First 5 Rows

OPEN BRWSUM1;OPEN BRWSUM1;FETCH BRWSUM1 FOR 5 FETCH BRWSUM1 FOR 5

ROWS;ROWS;Store :col1-4-last = :last-fetched-Store :col1-4-last = :last-fetched-

row in COM AREA and :page1 row in COM AREA and :page1 Display screenDisplay screen

COL1 COL2 COL3 COL4 COL5

A 1 TT 99 Data ….

A 1 UU 77 Data ….

A 4 SS 66 Data ….

B 2 RR 66 Data ….

B 3 RR 77 Data ….

B 3 RR 88 Data ….

B 3 SS 66 Data ….

B 4 SS 99 Data ….

B 4 UU 88 Data ….

C 1 SS 66 Data ….

C 1 SS 77 Data ….

SET SET :col1-last = low values, :col2-last = 0, :col3-last = low values,:col4-last = 0, :col1-last = low values, :col2-last = 0, :col3-last = low values,:col4-last = 0,

:page0 in COM AREA:page0 in COM AREA

7

© Sheryl M. Larsen, Inc. 2000-2012

Get Next 5 Rows

OPEN BRWSUM1;OPEN BRWSUM1;

( (COL1 = ‘B’( (COL1 = ‘B’AND COL2 = 3AND COL2 = 3AND COL3 = ‘RR’AND COL3 = ‘RR’AND COL4 > 77)AND COL4 > 77)OROR (COL1 = ‘B’ (COL1 = ‘B’AND COL2 = 3AND COL2 = 3AND COL3 > ‘RR’)AND COL3 > ‘RR’)OR OR

(COL1 = ‘B’(COL1 = ‘B’AND COL2 > 3)AND COL2 > 3)OROR (COL1 > ‘B’)) (COL1 > ‘B’))

FETCH BRWSUM1 FOR 5 ROWS;FETCH BRWSUM1 FOR 5 ROWS;Store :col1-4-last = :last-fetched-row in COM AREA and :page2 Store :col1-4-last = :last-fetched-row in COM AREA and :page2 Display screenDisplay screen

COL1 COL2 COL3 COL4 COL5

A 1 TT 99 Data ….

A 1 UU 77 Data ….

A 4 SS 66 Data ….

B 2 RR 66 Data ….

B 3 RR 77 Data ….

B 3 RR 88 Data ….

B 3 SS 66 Data ….

B 4 SS 99 Data ….

B 4 UU 88 Data ….

C 1 SS 66 Data ….

C 1 SS 77 Data ….

Get from COM AREA Get from COM AREA :col1-last = ‘B’, :col2-last = 3, :col3-last = ‘RR’,:col4-last =77 :col1-last = ‘B’, :col2-last = 3, :col3-last = ‘RR’,:col4-last =77

First Screen

8

© Sheryl M. Larsen, Inc. 2000-2012

Go Back 1 Page

OPEN BRWSUM1;OPEN BRWSUM1;

( (COL1 = low( (COL1 = lowAND COL2 = 0AND COL2 = 0AND COL3 = lowAND COL3 = lowAND COL4 > 0)AND COL4 > 0)OROR (COL1 = low (COL1 = low AND COL2 = 0AND COL2 = 0AND COL3 > low)AND COL3 > low)OROR (COL1 = low (COL1 = low AND COL2 > 0)AND COL2 > 0)OR OR (COL1 > 0)) (COL1 > 0))

FETCH BRWSUM1 FOR 5 ROWS;FETCH BRWSUM1 FOR 5 ROWS;Store :col1-4-last = :last-fetched-row in COM AREA and :page1 Store :col1-4-last = :last-fetched-row in COM AREA and :page1 Display screenDisplay screen

COL1 COL2 COL3 COL4 COL5

A 1 TT 99 Data ….

A 1 UU 77 Data ….

A 4 SS 66 Data ….

B 2 RR 66 Data ….

B 3 RR 77 Data ….

B 3 RR 88 Data ….

B 3 SS 66 Data ….

B 4 SS 99 Data ….

B 4 UU 88 Data ….

C 1 SS 66 Data ….

C 1 SS 77 Data ….

Get from COM AREA for page0Get from COM AREA for page0:col1-last = low values :col2-last = 0, :col3-last = low values,:col4-last =0 :col1-last = low values :col2-last = 0, :col3-last = low values,:col4-last =0

Last Screen

DB2 10 - Data Paging for Partial Results

SELECT … FROM phoneBook SELECT … FROM phoneBook

WHERE lastName = ? WHERE lastName = ?

AND firstName >= ? AND firstName >= ?

OR lastName > ?OR lastName > ?ORDER BY lastName, firstNameORDER BY lastName, firstName

Prior OR would be ugly if no MIA(Multi-Index-Access)Prior OR would be ugly if no MIA(Multi-Index-Access) Now this query can be satisfied with a single index access Now this query can be satisfied with a single index access

(lastname, firstname in this example) (lastname, firstname in this example) Via a new access method called 'range list access' (currently 'NR' Via a new access method called 'range list access' (currently 'NR'

in explain).in explain).

9© Sheryl M. Larsen, Inc. 2000-2012

10

DB2 10 SQL Enhancements

Index INCLUDE OptionIndex INCLUDE Option

Moving SUMMoving SUM

Moving AVGMoving AVG

Temporal Data RequestsTemporal Data Requests

DB2 SQL TrendsDB2 for z/OS V8 vs. DB2 for LUW V8

Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions, Limited Fetch, Scrollable Cursors, UNION Everywhere, Functions, Limited Fetch, Scrollable Cursors, UNION Everywhere,

MIN/MAX Single Index Support, Self Referencing Updates with MIN/MAX Single Index Support, Self Referencing Updates with Subqueries, Sort Avoidance for ORDER BY, and Row Expressions 2M Subqueries, Sort Avoidance for ORDER BY, and Row Expressions 2M

Statement Length, GROUP BY Expression, Sequences, Scalar Full Statement Length, GROUP BY Expression, Sequences, Scalar Full select, Materialized Query Tables, Common Table Expressions, select, Materialized Query Tables, Common Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Table Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Table

Support, Star Join Sparse Index, Qualified Column names, Multiple Support, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT clauses, IS NOT DISTINCT FROM, ON COMMIT DROP, DISTINCT clauses, IS NOT DISTINCT FROM, ON COMMIT DROP,

Transparent ROWID Column, GET DIAGNOSTICS Transparent ROWID Column, GET DIAGNOSTICS

11© Sheryl M. Larsen, Inc. 2000-2012

Updateable UNION in Views, INSERT with UPDATE/DELETE, ORDER BY/FETCH FIRST in subselects & table expressions, GROUPING

SETS, ROLLUP, CUBE, INSTEAD OF TRIGGER, EXCEPT, INTERSECT, and 16 Built-in Functions

Stage1 unlike data types, Multi-row INSERT, Multi-row FETCH, Dynamic Scrollable Cursors, Multiple CCSIDs per statement,

Enhanced UNICODE, and Parallel Sort

DB2 10 for z/OS vs. DB2 9.7 for LUW

Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Inner and Outer Joins, Table Expressions, Subqueries, GROUP BY, Complex Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions including Correlation, Global Temporary Tables, CASE, 100+ Built-in Functions including

SQL/XML, Limited Fetch, Insensitive Scrollable Cursors, UNION Everywhere, SQL/XML, Limited Fetch, Insensitive Scrollable Cursors, UNION Everywhere, MIN/MAX Single Index Support, Self Referencing Updates with Subqueries, Sort MIN/MAX Single Index Support, Self Referencing Updates with Subqueries, Sort

Avoidance for ORDER BY, and Row Expressions 2M Statement Length, GROUP BY Avoidance for ORDER BY, and Row Expressions 2M Statement Length, GROUP BY Expression, Sequences, Scalar Full select, Materialized Query Tables, Common Expression, Sequences, Scalar Full select, Materialized Query Tables, Common

Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Table Table Expressions, Recursive SQL, CURRENT PACKAGE PATH, VOLATILE Table Support, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT Support, Star Join Sparse Index, Qualified Column names, Multiple DISTINCT clauses, ON COMMIT DROP, Transparent ROWID Column, call from trigger, clauses, ON COMMIT DROP, Transparent ROWID Column, call from trigger,

statement isolation, FOR READ ONLY KEEP UPDATE LOCKS, SET CURRENT statement isolation, FOR READ ONLY KEEP UPDATE LOCKS, SET CURRENT SCHEMA, client special registers, long SQL Object names, SELECT FROM INSERT, SCHEMA, client special registers, long SQL Object names, SELECT FROM INSERT,

UPDATE, DELETE, MERGE, INSTEAD OF TRIGGER, Native SQL Procedure UPDATE, DELETE, MERGE, INSTEAD OF TRIGGER, Native SQL Procedure Language, BIGINT, file reference variables, XML, FETCH FIRST & ORDER BY IN Language, BIGINT, file reference variables, XML, FETCH FIRST & ORDER BY IN

subselect and full select, caseless comparisons, INTERSECT, EXCEPT, not logged subselect and full select, caseless comparisons, INTERSECT, EXCEPT, not logged tables, DECIMAL FLOAT, XQuery, TRUNCATE, OLAP Functions, Session variables, tables, DECIMAL FLOAT, XQuery, TRUNCATE, OLAP Functions, Session variables,

OmniFind, Spatial, DECIMAL FLOAT, OmniFind, Spatial, DECIMAL FLOAT, TRUNCATE, ROLE ,last committed, CREATED temps TRUNCATE, ROLE ,last committed, CREATED temps

12© Sheryl M. Larsen, Inc. 2000-2012

Updateable UNION in Views, GROUPING SETS, ROLLUP, CUBE, Many Built-in Functions, SET CURRENT ISOLATION , multi-site join, MERGE, ARRAY data type, more vendor friendly syntax, parameterized cursers,

CREATE MODULE

Multi-row INSERT, FETCH, Multi-row cursor UPDATE, Dynamic Scrollable Cursors, GET DIAGNOSTICS, Enhanced UNICODE, MERGE,,

IS NOT DISTINCT FROM, VARBINARY, FETCH CONTINUE temporal data, access controls

Index INCLUDE Option For reduction of indexesFor reduction of indexes How many?How many? One per table X 9,000 tables!One per table X 9,000 tables!

» DASD savings – sureDASD savings – sure» UPDATE/INSERT/DELETE savings – GREAT!UPDATE/INSERT/DELETE savings – GREAT!

13© Sheryl M. Larsen, Inc. 2000-2010

DB2 10 - Moving AverageFind the seven day centered moving average of XYZ stock for each day the stock traded. The Find the seven day centered moving average of XYZ stock for each day the stock traded. The

window is specified by the row clause.window is specified by the row clause.

SELECT date, symbol, close_price,SELECT date, symbol, close_price,decimal(avg(close_price) decimal(avg(close_price) overover (order by date (order by date rowsrows betweenbetween 3 3 precedingpreceding and and 3 3 followingfollowing),6,3) as smooth_cp),6,3) as smooth_cpFROM stockFROM stock

DATE DATE SYMBOL CLOSE_PRICE SYMBOL CLOSE_PRICE SMOOTH_CPSMOOTH_CP--------------------------------------------------------------------------------------------------------------------------------------------------04/23/2007 04/23/2007 XYZ XYZ 110.125 110.125 112.343112.34304/24/2007 04/24/2007 XYZ XYZ 109.500 109.500 112.000112.00004/25/200704/25/2007 XYZ XYZ 110.000 110.000 111.854111.85404/26/200704/26/2007 XYZ XYZ 119.750 119.750 112.125112.12504/27/2007 04/27/2007 XYZ XYZ 110.625 110.625 112.678112.67804/30/2007 04/30/2007 XYZ XYZ 111.125 111.125 113.285113.28505/01/2007 05/01/2007 XYZ XYZ 113.750 113.750 113.589113.58905/02/2007 05/02/2007 XYZ XYZ 114.000 114.000 112.160112.16005/03/2007 05/03/2007 XYZ XYZ 113.750 113.750 112.214112.21405/04/2007 05/04/2007 XYZ XYZ 112.125 112.125 112.160112.16005/07/2007 05/07/2007 XYZ XYZ 109.750 109.750 111.339111.33905/08/2007 05/08/2007 XYZ XYZ 111.000 111.000 110.642110.64205/09/2007 05/09/2007 XYZ XYZ 110.750 110.750 110.125110.12505/10/2007 05/10/2007 XYZ XYZ 108.000 108.000 109.725109.72505/11/2007 05/11/2007 XYZ XYZ 109.125 109.125 109.718109.718

14© Sheryl M. Larsen, Inc. 2000-2012

Numbers Graphed

15© Sheryl M. Larsen, Inc. 2000-2012

CLOSE_PRICESMOOTH_CP

DB2 10 - Moving AverageFor the stock XYZ, find the 7 day historical average for each day the stock traded. For the stock XYZ, find the 7 day historical average for each day the stock traded.

The window is specified by the range clause.The window is specified by the range clause.

SELECT date,substr(dayname(date),1,9) as day, close_price,SELECT date,substr(dayname(date),1,9) as day, close_price,decimal(avg(close_price) decimal(avg(close_price) overover ( (order by order by date date rangerange 00000006. 00000006. precedingpreceding),7,2) as ),7,2) as avg_7_range,avg_7_range,count(close_price) count(close_price) overover ( (order by order by date date rangerange 00000006. 00000006. precedingpreceding) as count_7_range) as count_7_rangeFROM stock WHERE symbol = ‘XYZ’FROM stock WHERE symbol = ‘XYZ’

DATE DATE DAY DAY CLOSE_PRICE CLOSE_PRICE AVG_7_RANGE COUNT_7_RANGEAVG_7_RANGE COUNT_7_RANGE------------------------------------------------------------------------------------------------------------------------------------------04/23/2007 04/23/2007 Monday Monday 110.125 110.125 110.12 110.12 1104/24/2007 04/24/2007 Tuesday Tuesday 109.500 109.500 109.81 109.81 2204/25/2007 04/25/2007 Wednesday 110.000 Wednesday 110.000 109.87 109.87 3304/26/2007 04/26/2007 Thursday Thursday 119.750 119.750 112.34 112.34 4404/27/2007 04/27/2007 Friday Friday 110.625 110.625 112.00 112.00 5504/30/2007 04/30/2007 Monday Monday 111.125 111.125 112.20 112.20 5505/01/2007 05/01/2007 Tuesday Tuesday 113.750 113.750 113.05 113.05 5505/02/2007 05/02/2007 Wednesday 114.000 Wednesday 114.000 113.85 113.85 5505/03/2007 05/03/2007 Thursday Thursday 113.750 113.750 112.65 112.65 5505/04/2007 05/04/2007 Friday Friday 112.125 112.125 112.95 112.95 5505/07/2007 05/07/2007 Monday Monday 109.750 109.750 112.67 112.67 5505/08/2007 05/08/2007 Tuesday Tuesday 111.000 111.000 112.12 112.12 5505/09/2007 05/09/2007 Wednesday 110.750 Wednesday 110.750 111.47 111.47 5505/10/2007 05/10/2007 Thursday Thursday 108.000 108.000 110.32 110.32 5505/11/2007 05/11/2007 Friday Friday 109.125 109.125 109.72 109.72 55

16© Sheryl M. Larsen, Inc. 2000-2012

Moving Average

17© Sheryl M. Larsen, Inc. 2000-2012

CLOSE_PRICEAVG_7_RANGE

Origins of Temporal Data and Databases

Time Based InformationTime Based Information

19© Sheryl M. Larsen, Inc., Reed Meseck 2012

Point-In-Time Backup

Time

T1 T3

IntervalT2

IntervalT4

Interval

PIT1 PIT2 PIT3 PIT4

IBM Bi-Temporal Support● ● Table-level specification to control the management of data based uponTable-level specification to control the management of data based upon

timetime

● ● Two notions of time:Two notions of time:

System timeSystem time: notes the occurrence of a data base change: notes the occurrence of a data base change “ “row xyz was deleted at 10:05 pm”row xyz was deleted at 10:05 pm” Query at current or any prior period of timeQuery at current or any prior period of time Useful for auditing, complianceUseful for auditing, compliance

Business timeBusiness time: notes the occurrence of a business event: notes the occurrence of a business event “ “customer xyz’s service contract was modified on March 23”customer xyz’s service contract was modified on March 23” Query at current or any prior/Query at current or any prior/futurefuture period of time period of time Useful for tracking of business events over time, app logic greatly simplifiedUseful for tracking of business events over time, app logic greatly simplified

● ● New syntax in FROM clause to specify a time criteria for selectingNew syntax in FROM clause to specify a time criteria for selecting

historical datahistorical data

20© Sheryl M. Larsen, Inc. 2000-2012

VIEW Magic Can imitate pointing to the correct portion of Can imitate pointing to the correct portion of

the history tablethe history table Emulates getting data “AS OF” a particular Emulates getting data “AS OF” a particular

range.range. Can only solve the Can only solve the historyhistory problem problem More application magic is needed to emulate More application magic is needed to emulate

asking business questions of asking business questions of futurefuture

21© Sheryl M. Larsen, Inc. 2000-2010

FROM T1 FOR SYSTEM_TIME AS OF timestamp-expression

22© Sheryl M. Larsen, Inc. 2000-2012

FROM T1 FOR BUSINESS_TIME FROM timestamp-expression1 TO timestamp-expression2

23© Sheryl M. Larsen, Inc. 2000-2012

DB2 10 – WOW!

DirectoryDirectory

WorkWorkFilesFiles

Buffer Pool

SQL

CatalogCatalog

DataData

Buffer Manager

Result

Stage 2

IndexIndex

Stage 1 DirectoryDirectory

CatalogCatalog

In MemoryQuery techniques

In Memory

Buffer pool enhancements

New technique for p-key access

Automatic Stats Collection

Indexing support of DECFLOAT

Dynamic Index ANDing improvements

Moving SUMMoving AVG

Enhanced Parallelism

Caching of dynamic SQL with literals

Individual cells restricted,value returned with

access denied

Greater TIMESTAMP precision

Instance Based SQL Hints

Caching DB2 CodeAnd control structures

INCLUDE Indexing support

SQL Paging for partial result

Temporal Semantics