© 2015 ibm corporation application-enabling features of db2 10 and 11 for z/os & dba enabling...

57
© 2015 IBM Corporation plication-enabling features of 2 10 and 11 for z/OS & DBA nabling features w England DB2 User’s Group ne 18, 2015 Jim Brogan DB2 for z/OS Advisor [email protected]

Upload: peter-flowers

Post on 24-Dec-2015

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Application-enabling features ofDB2 10 and 11 for z/OS & DBA enabling features

New England DB2 User’s Group June 18, 2015

Jim Brogan

DB2 for z/OS Advisor

[email protected]

Page 2: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

Version PID General Availability

Marketing Withdrawal

End of Service

5 5655-DB2 June 1997 December 2001

December 2002

6 5645-DB2 June 1999 June 2002 June 2005

7 5675-DB2 March 2001 March 2007 June 2008

8 5625-DB2 March 2004 September 2009

April 2012

9 5635-DB2 March 2007 December 2012

June 2014

10 5605-DB2 October 2010 July 2015 September 2017

11 5615-DB2 October 2013

2

DB2 z/OS Availability Summary

http://www.ibm.com/software/data/support/lifecycle/

Page 3: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

The aim of this presentation

To help ensure that you are aware of recentlydelivered DB2 for z/OS features that can boostagility and productivity with respect to applicationdevelopment

2

Page 4: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Agenda (1)

DB2 10 application-enabling features

– Temporal data support

– Enhanced SQL user-defined functions

– RETURN TO CLIENT cursors

– OLAP moving aggregates

– LOB enhancements

– Implicit casting of character string and numeric values

– Timestamp extensions

– XML enhancements

3

Page 5: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Agenda (2)

DB2 11 application-enabling features

– Autonomous native SQL procedures

– Array parameters (and variables) for SQL procedures(and user-defined functions)

– Temporal special registers and temporal support forviews

– Global variables

– Transparent DB2-managed data archiving

– New grouping options: GROUPING SETS, ROLLUP,CUBE

– DB2 integration with Hadoop-managed data

– XQuery support for XML data4

Page 6: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Application enabling featuresof DB2 10 for z/OS

5

Page 7: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Temporal data support

Allows you to give a time dimension to data in a DB2 table

Two flavors:

– System time: DB2 maintains a history table associated with a base table,and will insert into the history table the “before” version of a row everytime a base table row is changed via update or delete

• DB2 also maintains “from” and “to” timestamp values in base and history tablerows, showing when a row in the history table was current, and when a row inthe base table became current

– Business time: a dimension that shows when data in a row is valid froma business perspective (e.g., a product price that will go into effect nextyear)

• You maintain business time values, but DB2 can help by preventing FROMand TO business time period “overlaps” (so one version of a given row will bevalid from a business perspective at any given time)

– You can combine system and business time in one table (“bi-temporal”)6

Page 8: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

More on temporal data support

SELECT syntax extended to include the time dimension of a table

Example: “What was the coverage associated with insurancepolicy number 127348 at 10 AM on February 24, 2010?”

Can specify BUSINESS_TIME if table hasthat dimension

Alternatively, can specify FROM and TO, orBETWEEN two timestamp values

SELECT COL1, COL2,,,

FROM POLICY

FOR SYSTEM_TIME AS OF TIMESTAMP ‘2010-02-2410.00.00’

WHERE POLICY_NUM = ‘127348’;

7

Page 9: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Advantages of temporal data support System time makes it easy to provide an audit

history of data changes in a DB2 table

Business time enables “forward looking” dataanalysis possibilities

– Real-world example: forecasting future profit margins usingprices that will go into effect at a later time

DB2-provided temporal capabilities GREATLYincrease programmer productivity versus “do ityourself” temporal data functionality

DB2-implemented temporal table functionalitydelivers better performance than the do-it-yourselfalternative

8

Page 10: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Enhanced SQL user-defined functions (UDFs) Prior to DB2 10, the “logic” in a SQL scalar UDF was restricted to

what you could code in the RETURN part of CREATE FUNCTION,and that was quite limited

– RETURN could not contain a SELECT statement

– RETURN could not include a column name

You were basically limited to receiving a value (or values) asinput, transforming that value (or values) arithmetically and/orwith scalar functions, and returning the result of thattransformation

– Example:CREATE FUNCTION KM_MILES(X DECIMAL(7,2))

RETURNS DECIMAL(7,2)

LANGUAGE SQL

RETURN X*0.62;

You can still create a UDF like this one,but DB2 10 enabled you to do much morewith UDFs written in SQL

9

Page 11: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Enhanced SQL UDFs (continued) Starting with DB2 10, the RETURN part of a SQL scalar UDF can

contain a scalar fullselect

RETURN(SELECT WORKDEPT FROM EMP WHERE EMPNO = P1);

Also new with DB2 10: the RETURNS part of a SQL scalar UDF cancontain a compound SQL statement, in which variables can bedeclared and which can include logic flow control statements suchas IF and WHILE

BEGIN

DECLARE VAR1, VAR2 CHAR(10);

SET VAR1 = …;

IF P1 = …;

RETURN VAR2;

END@

Also new with DB2 10: SQL table UDFs, which return a result set10

Page 12: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

RETURN TO CLIENT cursors

Prior to DB2 10, a cursor in a stored procedure could be declaredWITH RETURN TO CALLER, allowing the result set rows to be directlyfetched only by the direct caller of the stored procedure

– Example: program PROG_A calls stored procedure PROC_B, whichcalls procedure PROC_C, which has a WITH RETURN TO CALLERcursor

– PROC_B can directly fetch rows from the cursor, but PROG_A cannot

• If PROG_A needs the result set, PROC_C can put it in a temporary table, andPROG_A can get the rows from that temp table

– Clunky from a programming perspective, and not optimal for performance

DB2 10: stored procedure can declare a cursor WITH RETURN TOCLIENT

– Makes result set rows directly FETCH-able by “top-level” program (i.e.,the one that initiated a chain of nested stored procedure calls)

11

Page 13: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Previous slide’s point, in a picture…

Before DB2 10:

Program XYZ

With DB2 10:

Program XYZ

DECLARE C1 CURSOR…

CALL

CALL

WITH RETURN TO CLIENT

WITH RETURN TO CALLER

Stored proc A

CALL

Stored proc BDECLARE C1 CURSOR…

WITH RETURN TO CALLER

Still an option withDB2 10, if this is thebehavior you want

Stored proc A

CALL

Stored proc B

12

Page 14: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

OLAP moving aggregates

A new (with DB2 10) SQL syntax that allows:

– Partitioning of a result set (e.g., by name)

– Ordering of rows within result set partitions (e.g., by date)

– Generation of aggregate values based on the “moving” currentposition within a set of rows (e.g., sum of sales for the current

row plus the two preceding rows)

– Example:

FROM PRODUCT_SALES;

The desired result setpartitioning value

SELECT NAME, DATE, UNITS_SOLD,

SUM(UNITS_SOLD) OVER(PARTITION BY NAME rows within result setpartitions

ORDER BY DATE

function ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) SUM

The desired scope of aggregation as DB2moves through the result set partitions

13

Page 15: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

The result of the SELECT on the previous slide

NAME

Jones

Jones

Jones

Jones

Smith

Smith

Smith

Smith

DATE

2015-01-10

2015-01-11

2015-01-12

2015-01-13

2015-01-10

2015-01-11

2015-01-12

2015-01-13

UNITS_SOLD

7

8

5

6

4

9

8

5

SUM

7

15

20

26

4

13

21

26

Sum of this row’sUNITS_SOLD (5) plus theUNITS_SOLD values of thepreceding two rows in theresult set partition (7 and 8)

14

Page 16: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

LOB enhancements: Inline Lobs Prior to DB2 10, every bit of every value in a LOB column had to be

physically stored in a separate LOB table space (the LOB valueslogically appear to be in the base table rows)

With DB2 10, a LOB column’s definition can include a specificationof the amount of space in the base table that can be occupied byLOB values

– The portion (if any) of a value over the limit is stored in LOB tablespace

Great for a LOB column for which relatively few values are truly large

– Can significantly improve the performance of LOB-reading and LOB-inserting programs (and utilities) when most of a LOB column’s valuescan be completely in-lined

– Also allows creation of index on expression on in-lined portion of aCLOB column (using the SUBSTR)

• Example: if contracts are stored in a CLOB column, and if data in bytes 10through 20 is always the contract number, can build index on that

15

Page 17: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Lob enhancements: utilities

Variable-block spanned (VBS) record format now supported for datasets used for table UNLOAD and LOAD (referring to SYSREC dataset)

– What this means: you can unload a table with a LOB column (orcolumns) and have ALL of the data – LOB and non-LOB – go into asingle data set

– And reverse is true for LOAD (i.e., data – LOB and non-LOB values –can be loaded from a single input data set

• Before DB2 10, had to unload individual LOB values to members of a PDS,or to individual files in the z/OS UNIX System Services file system (andreverse was true for LOAD)

• DB2 10 spanned record support greatly simplifies use of UNLOAD andLOAD for tables with LOB columns, and substantially boosts performance

DB2 10 also delivered support for online REORG of LOB table spacewith SHRLEVEL(CHANGE)

16

Page 18: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

Implicit casting of character, numeric values Consider this statement:

SELECT 1 CONCAT ‘+’ CONCAT 1 CONCAT ‘=‘ CONCAT 2

FROM SYSIBM.SYSDUMMY1;

In a pre-DB2 10 environment, that statement gets this result:

SQLCODE = -171, ERROR: THE DATA TYPE, LENGTH,

OR VALUE OF ARGUMENT 1 OF CONCAT IS INVALID

In a DB2 10 (new-function mode) system, you get this:•1+1=2

Works assignment (SET) statements, too (but not for specialregisters)

Numeric values are implicitly cast to VARCHAR, character valuesare implicitly cast to DECFLOAT(34)

– Why? Because VARCHAR and DECFLOAT(34) are compatiblewith all other character and numeric data types, respectively

© 2015 IBM Corporation17

Page 19: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Timestamp extensions

New with DB2 10: timestamp values down to the picosecond(that’s a trillionth of a second)

– One reason this was needed: mainframe engines are so fast nowthat microsecond-level timestamps (often defined as unique keysin DB2 tables) can regularly produce duplicate values

Also new with DB2 10: variable-precision timestamps

– From 0 (no fractions of a second) to 12 (picosecond-levelprecision), with 6 being the default

– Syntax: TIMESTAMP(n)

Another DB2 10 enhancement: TIMESTAMP(n) WITH TIME ZONE

– New data type– Sample value: ‘2012-10-03-10.15.00.123456-05:00’

Difference betweenlocal time and UTC

18

Page 20: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

XML enhancements

With DB2 10, you can specify in the definition of a table the XML schemathat is to be used to validate data inserted into an XML column

– No longer have to invoke DB2-supplied user-defined function to accomplishschema validation

– Additionally, DB2 10 XML schema validation is done “in the DB2 engine”

• Better performance, and zIIP-eligible

And, you can update part of an XML document (versus replacing the wholething) via new XMLMODIFY built-in function

– Can insert a node into an XML document, replace a node, delete a node, orreplace values of a node

Also, the CHECK DATA utility can check on the structural validity of XMLdocuments in an XML table space

– Pre-DB2 10: only checked consistency between base table and XML tablespace

19

Page 21: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Application enabling featuresof DB2 11 for z/OS

20

Page 22: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Autonomous native SQL procedures A DB2 11 native SQL procedure can function as an autonomous

transaction

– How it’s done: AUTONOMOUS option specified in CREATEPROCEDURE (or ALTER PROCEDURE) statement

• Specified instead of COMMIT ON RETURN YES/NO

– An autonomous SQL procedure commits on returning to the callingprogram, but (unlike the case when COMMIT ON RETURN YES is ineffect) that commit does NOT affect the calling program’s unit of work

– An autonomous SQL procedure’s unit of work (UOW) is independent ofthe calling program’s UOW – if the calling program’s UOW is rolledback, data changes made by autonomous SQL procedure will not berolled back

• Very useful if you require that a data update be accomplished when atransaction executes, and you need that update to persist even if thetransaction subsequently fails

– A restriction: one autonomous SQL procedure can’t call another21

Page 23: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Array parameters (and variables) for SQLprocedures (and UDFs)

DB2 11: array parameters can be passed to (and/or receivedfrom), and array variables can be declared in, native SQLprocedures (and the same is true for SQL user-definedfunctions)

– Call to SQL procedure with array input or output parameter cancome from a SQL PL routine, a Java program, or a .NETprogram (for latter two, via IBM Data Server Driver type 4 driver)

• If .NET caller, array must be input parameter

– An array in this context is a form of a DB2 user-defined data type(UDT) – you create it, then you use it

– Built-in functions are provided to:•

Construct arrays

Derive tables from arrays

Obtain information about arrays

Navigate array elements22

Page 24: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Max number of elements in ordinaryarray (defaults to about 2 billion)

Data type of values in the array

More on array parameters and variables There are two array types:

– Ordinary

• Has a user-defined upper bound on number of elements (defaults toINTEGER high value)

• Elements referenced by their ordinal position in the array

– Associative

• No user-defined upper bound on number of elements

• Elements are ordered by and can be referenced via array index values

• Values in a given array index are INTEGER or VARCHAR, are unique, anddon’t have to be contiguous

This is an ordinary array – associative array would have data type of indexvalues (e.g., VARCHAR(8)) after ARRAY keyword

CREATE TYPE PHONENUMBERS AS DECIMAL(10,0) ARRAY[50];

23

Page 25: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Temporal special registers

The need: what if you want a program (or just a SQL statement) to havean other-than-current view of temporal data, but you don’t want tochange the program’s code?

Solution: two new special registers delivered with DB2 11

– CURRENT TEMPORAL SYSTEM_TIME

– CURRENT TEMPORAL BUSINESS_TIME

When set to a non-null value, has the effect of adding the following to aSELECT statement that targets a temporal-enabled table (in this case, useof system time is assumed):

– FOR SYSTEM_TIME AS OF CURRENT TEMPORAL SYSTEM_TIME

Example of setting special register’s value:

SET CURRENT TEMPORAL SYSTEM_TIME = CURRENT TIMESTAMP – 1 YEAR;

(this would result in a program having a view of data that was current as of one year ago)

24

Page 26: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

More on temporal special registers

A special register non-null value, once set, remains in effect forthat particular session (thread) until it’s changed (setting to nullhas the effect of “turning the special register off”)

– But if set within a routine (stored procedure or UDF), the new value is notpassed back to the invoking application

SYSTIMESENSITIVE, BUSTIMESENSITIVE bind options determinewhether or not SQL statements (static or dynamic) issuedthrough a package will be affected by temporal special registers

– Default value is YES

If CURRENT TEMPORAL SYSTEM_TIME is set to non-null valuefor a thread, data modification statements targeting system time-enabled tables are not allowed

25

Page 27: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

SQLCODE -4736

View

© 2015 IBM Corporation

Temporal support for viewsWith DB2 11, you can use temporal predicates when referring to a view definedon a temporal table (but you can’t use a temporal predicate in defining a view)

Temporal predicateBase table

Temporal predicate

26

Page 28: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Global variables

The need: how can you pass data values from one SQL statement toanother in the context of a thread?

– Before DB2 11:

• Do it with application code (values placed into variables by one SQLstatement are copied to variables used as input to another SQL statement)

• Want a trigger to be able to access those values? Not easy…

– DB2 11: use global variables

You can create your own global variables using the new CREATEVARIABLE statement

– DB2 11 also provides a few built-in global variables:

• SYSIBM.CLIENT_IPADDR• SYSIBMADM.GET_ARCHIVE

• SYSIBMADM.MOVE_TO_ARCHIVE

More on this archive stuffmomentarily…

27

Page 29: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Globalvariablesexample

Assign value to a(previously created)global variable

Reference the global variable

28

Page 30: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

Transparent DB2-managed data archivingMeaning: infrequentlyreferenced

The need: get old and “cold” data out of a table (for better SQL andutility performance), but retain deleted rows in an archive table andtransparently enable retrieval of archived rows

DB2 11 will do this for you

What a DBA does (suppose that table TAB_A is to be archive-enabled):

– Create an archive table that looks just like TAB_A (same number ofcolumns, same order of columns, same column names anddefinitions)

– Tell DB2 to associate the archive table with TAB_A (assume that younamed the archive table TAB_A_ARCHIVE):

ALTER TABLE TAB_A ENABLE ARCHIVE USE TAB_A_ARCHIVE;

29

Page 31: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

More on DB2-managed data archiving

Temporal and archive tables are mutually exclusive

New built-in global variables affect interaction with archive-enabledtables (default value for both is ‘N’):

– SYSIBMADM.GET_ARCHIVE – if ‘Y’ then SELECT targetingarchive-enabled table will automatically include UNION ALL witharchive table

– SYSIBMADM.MOVE_TO_ARCHIVE – if ‘Y’ or ‘E’ then rows deletedfrom archive-enabled table will be inserted into archive table (if ‘Y’then INSERT/UPDATE/MERGE disabled for base table)

ARCHIVESENSITIVE bind option determines whether statements(static or dynamic) will be affected by value ofSYSIBMADM.GET_ARCHIVE global variable (default is YES)

– ARCHIVE SENSITIVE option on create of native SQL procedure orUDF does the same thing

© 2015 IBM Corporation30

Page 32: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

New grouping option: GROUPING SETS

Example: determine average total compensation for WorkDept, Job, and EdLevel sets

Basically means, “groupby each of thesecolumns, in turn”

31

Page 33: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

New grouping option: ROLLUPExample: determine average total compensation for the various hierarchies ofWorkDept, Job, and EdLevel, and for overall set

••

Column order in GROUP BY expression affects result setORDER BY helps with readability

You get a grouping by all values ofcolumn 1, column 2, and column 3; agrouping by all values of column 1and column 2; and a grouping by allvalues of column 1 You also get an aggregate

over all qualifying rows

32

Page 34: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

New grouping option: CUBE Example: determine average total compensation for various combinations of

WorkDept, Job, and EdLevel– Column order in GROUP BY expression doesn’t matter

– ORDER BY helps with readability

You get grouping by all values of all threecolumns, by all values of all combinationsof two of the three columns, and by allvalues of each individual column

You also get an aggregate over all qualifying rows33

Page 35: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

DB2 integration with Hadoop-managed data

Hadoop: an open source software framework that supports data-intensivedistributed applications

Two main components–Hadoop distributed file system–MapReduce engine

• Powerful, but tedious from a developmentperspective

• “Like the assembly language of Hadoop”

34

Page 36: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

IBM BigInsightsA new user-defined function (UDF)allows a data analytics job,specified in JAQL, to be submittedto a BigInsights server

A new table UDF reads the outputof the analytics job and returns itin relational form

DB2 11: new UDFs for Hadoop integrationAvailable now forLinux on z Systems

35

Page 37: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

XQuery support for XML data Pre-DB2 11: XPath expressions can be used to navigate

through XML documents and to address parts of XMLdocuments

– XPath is a subset of XQuery, which is a richer language foraccessing XML documents

– XPath limitations often necessitated using a mixture of XPathand SQL, and that could make query coding more difficult

DB2 11 includes XQuery support, providing a richer set ofXML expressions that can be used with the built-in functionsXMLQUERY, XMLEXISTS, and XMLTABLE

– Queries can be expressed purely using XQuery, versus amixture of XPath and SQL, and that can boost programmerproductivity

XQuery support was retrofitted to DB2 10 via APARSPM47617 and PM47618

36

Page 38: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation

In conclusion…

DB2 10 and 11 delivered a lot of new application-enabling features

– How many of these are being used at your site?

– How many could be put to good use at your site?

37

Page 39: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

39

Migration Catalog / Directory Summary• All new non-AUX create Table Spaces are PBGs

– MAXPARTITIONS 1– DSSIZE 64G

• 108 Unicode; 7 EBCDIC; 1 ASCII

Catalog / Directory Visualization

TS Page Size Counts– 4K = 76 -> 94– 8K = 10– 16K = 5 -> 6– 32K = 4 -> 6

Page 40: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

40

Application Compatibility ...• Allows applications to continue experiencing SQL

DML & XML behavior from a previous release (DB2 10)– APPLCOMPAT ZParm

• Must be V10R1 until NFM– Migrations default to the migrate-from release (V10R1)– Installations default to the migrate-to release (V11R1)

• DDL and DCL is not fenced by APPLCOMPAT• This includes new functions, not just changes to

existing behavior• May not be possible when conforming to SQL

standards

Page 41: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

41

Application Compatibility ...• Similar limited capability in DB2 10

– BIF_COMPATIBILITY– DDF_COMPATIBILITY (Disabled when APPLCOMPAT set to (V11R1) via PM94719

• Static SQL is governed by the Package APPLCOMPAT– Cannot bind with V11R1 until NFM

• Dynamic SQL is governed by the:– CURRENT APPLICATION COMPATIBILITY– Which defaults to the Package APPLCOMPAT if not SET

• Once in NFM:– CURRENT APPLICATION COMPATIBILITY can be set to either level– RE/BIND PACKAGE can choose either level

Page 42: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

42

Application Compatibility ...• BIND / REBIND (TRIGGER) ... APPLCOMPAT Defaults– Must be V10R1 until NFM

• V11R1 before NFM returns error– During REBIND, if already rebound with a compatibility level

• Defaults to this level• Including Autobind

– If BINDind, or not yet set, defaults to APPLCOMPAT ZParm

• CREATE / ALTER PROCEDURE /FUNCTION– Same rules as BIND / REBIND

• On DB2I defaults panels for– BIND: DSNEBP10– REBIND: DSNEBP11

Page 43: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

43

Application Compatibility ...• CURRENT APPLICATION COMPATIBILITY

– Defaults to the Package RE/BIND– If not rebound, defaults to the ZParm– SET this Special Register overrides all

• Must be in NFM to SET this register

• IFCID 239– Indicates Packages using a function that changes in DB2 11– Field QPACINCOMPAT– See SDSNMACS(DSNDQPAC) for mapping

• IFCID 366/376– Records indicate SQL using the V10 code path which is different from the V11 code path– Use these in CM to identify programs needing review– 376 is new in V11 and is a roll up of activity reported in 366

• Attempts once per dynamic and static statement (bound V10 or later)• Once per Plan, Package, Statement # bound prior to V10

– See SDSNMACS(DSNDQW05) for detailed description

Page 44: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

44

Application Compatibility ...

• ZParm V10R1– Can set to

V11R1 but will not operate that way

• BIND/REBIND– Must be V10R1

• CREATE/ALTER– Must be V10R1

• SET CAC* not available

• IFCID 239/366/376

10 NFM 11 CM 11 ENFM 11 NFM Same as CM

*CAC = CURRENT APPLICATION COMPATIBILITY

ZParm– V10R1 or V11R1

BIND/REBIND– V10R1/V11R1 available

BIND– Defaults to ZParm

REBIND & Autobind– Defaults to previous

Catalog value first– ZParm second

CREATE/ALTER– V10R1 or V11R1

SET CAC* available New features– Require V11R1

Page 45: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

45

RBA / LRSN Expansion ...• DB2 10 and prior used a 6 byte (Basic) RBA / LRSN– Some customers have had to take RBA action to keep systems

running• RBA reset

– Manual recovery action to reset • Bring up new data sharing members

– Represents 256 TBs of logging space– Messaging (DSNJ032I) and system actions

• F000 0000 0000 warning threshold surfaces at log switch & restart• FFFF 0000 0000 critical threshold, DB2 will only run ACCESS(MAINT)

– The LRSN also has a limit in Year 2042 if there’s no DELTA RBA– STORCLK is 8 bytes, and therefore LRSN spin can occur

Page 46: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

46

RBA / LRSN Expansion ...• DB2 11 offers the option to convert to a 10 byte RBA / LRSN

– Almost 4 Billion times the logging space– RBA extended with high-end (left) 4 bytes

• Extended value represents 1 YB of logging space (1 YB = 1 Trillion TBs)– LRSN

• 1 byte on high-end• 3 bytes on the low-end• Adding 30,000 years of logging

– Conversion is optional if not nearing the 6 byte limit• However, DB2 11 uses 10 bytes internally and converts to 6 on writes

– Convert earlier than required to:• Avoid internal conversions• Resolve LRSN spin conditions• Disabling Data Sharing requires 10 byte RBA/LRSN for surviving members

Page 47: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

47

RBA / LRSN Expansion ...• Must restart the subsystem / member on NFM before expansion• There are 3 areas for conversion which can be done in any order and schedule IF

NOT NEARING 6 byte limit– BSDS (DSNTIJCB)

• DB2 is down• BSDSs are reformatted and will grow• A checkpoint will be taken at restart

– Catalog (DSNTIJCV)• Some of these may have been converted during DSNTIJEN (ENFM)

– User Data / Indexes• REORG, REBUILD, LOAD REPLACE with any SHRLEVEL• At the PART level, except for XML* & Hashed• Data & Indexes can be converted independently• Growth is not expected, as there is enough room in the pages

• DB2 11 internals are always using a 10 byte RBA / LRSN– But can be converted to 6 byte for objects in BASIC format for writes– As long as DB2 is not close to the 6 byte limit

* Research options for XML. Based on the options and if previously was Expanded, PART may be an option

Page 48: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

48

RBA / LRSN Expansion ...• DSNTIJCB

– Tailored during the MIGRATE execution of the CLIST– DB2 must be down

• Recommend –STOP DB2 MODE(QUIESCE)– Defines new BSDSs (suffix NEWFMT1)– Converts into the new BSDS data sets– Renames:

• existing to .OLDFMT• NEWFMT1 to existing

– A demo system observed a 50% growth in the BSDS

Page 49: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

49

RBA / LRSN Expansion ...• DSNTIJCV

– Tailored during the ENFM execution of the CLIST– Consider MODIFY RECOVER & REORG prior to conversion

• For large / active Catalogs• When executed outside of the migration project to clean up again

– All converted areas are COPYed– As with JEN, SYSUTILX cannot be REORGed and therefore is reset

• Make sure it is empty and quiesced before running JCV• CATMAINT converts SYSUTILX

– REORG ... SHRLEVEL CHANGE converts the rest– Builds LISTDEF with BASIC YES, so already converted objects are skipped– This job can be split apart, but review PM95430

• When SYSLGRNX is Extended & SYSCOPY is Basic• COPY SHRLEVEL REFERENCE is not recorded

Page 50: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

50

RBA / LRSN Expansion ...• In CM:– IFCID 306 & Log Capture Exit products (Replication) see 10

bytes– Work files are Extended when opened– DISPLAY THREAD and restart status messages are 10 bytes

• In ENFM– JEN REORGed Catalog / Directory objects converted based

on UTILITY_OBJECT_CONVERSION• In NFM– JNF converts SCA to 10 bytes– DSNTIJCB & DSNTIJCV available to convert BSDS & Cat/Dir– Use utilities RBALRSN_CONVERSION keyword for user

data/indexes

Page 51: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

51

RBA / LRSN Expansion ...• Clone tables must be dropped to convert• SYSTABLEPART & SYSINDEXPART indicate format (RBA_FORMAT)

– All migrated objects will indicate blank– At open time, REORG, REBUILD, LOAD, or REPAIR these values will be set as “B” or “E”– CREATE sets RBA_FORMAT

• DEFINE NO = “U”– DEFINE NO objects created according to OBJECT_CREATE_FORMAT in effect

• Utilities and Service Aids accept either format– UTILITY_OBJECT_CONVERSION defaults utility RBALRSN_CONVERSION keyword.– DSN1COPY may need REPAIR to correct the Catalog definition

• Must be TO a DB2 11 NFM system if Expanded– RECOVER of Expanded object with a Basic copy will reset the object to Basic

• Cannot roll forward across an RBA / LRSN change• IFCIDs

– Many are reformatted.– The RBA/LRSN was moved when possible to not impact other fields

Page 52: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

52

RBA / LRSN Expansion• V11 6 byte Thresholds

– RBA• F000 0000 0000

– DSNJ032I Warning with each log switch and DB2 restart• FFF8 0000 0000

– -904 00C2026D Soft Limit– No SQL Updates allowed for Basic Objects

• FFFF 0000 0000– DSNJ033E Critical Threshold– DB2 stops with 00D10251– DB2 only runs in ACCESS(MAINT)

• If you manage to reach all ‘F’s, then previous RBA reset procedure is still likely– LRSN

• 1 Year left– DSNJ034I Warning with each log switch and DB2 restart

• 2 Months left– 904 00C2026D Soft Limit– No SQL Updates allowed for Basic Objects

• 2 Weeks left– DSNJ033E Critical Threshold– DB2 stops with 00D10251– DB2 only runs in ACCESS(MAINT)

Page 53: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

Suppress-null Indexes Support creation of indexes where the default NULL values are excluded from the

index– Reduced index size, improved insert/update/delete performance, 3rd party DBMS

compatibility

New CREATE INDEX keywords– INCLUDE NULL KEYS (default)• DB2 will create an index entry even if every key column contains the NULL value

– EXCLUDE NULL KEYS • DB2 will not create an index entry when every key column contains the NULL value. If any key column

is not null the index entry will be indexed Conditions:– EXCLUDE NULL KEYS must not be specified if any of the columns identified by column-name

are defined as NOT NULL– Not supported if the index is defined as a partitioning index

53 IDX

Page 54: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

Auto Cleanup of Pseudo-deleted Index Entries DB2 11 automatically cleans up pseudo deleted entries– zIIP eligible and runs in the background– Designed to have minimal or no disruption to applications– New ZParm INDEX_CLEANUP_THREADS (0-128) to control number of concurrent

cleanup tasks – Default is 10– 0 disables index cleanup– Value can vary between members of a data sharing group– Online changeable

– New SYSIBM.SYSINDEXCLEANUP Catalog table to control auto cleanup at index level• Day of week/month, start/end time.• By default cleanup is enabled for all indexes

– IFCID 377 written when index is cleaned up

-DIS THREAD TYPE(SYSTEM) to see threads– Correlation id in the output shows: 014.IDAEMKxx– xx indicates thread number (01, 02…)

54 IDX

Page 55: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

Pseudo-deleted Index Cleanup Cleanup done under system tasks, run as enclave SRBs and zIIP eligible

• Parent thread (one per DB2 member) reads through RTS to find candidates – Runs every 5 minutes

• Eligible indexes sorted based on number of pseudo deleted rids to delete highest first• Child threads assigned based on ZParm setting

55

Child cleanup thread IX4

NAME … NPAGES … REORGPSEUDODELETES

IX1 n 100 X 5000

IX2 n 1000 X 20000

IX3 n 500 X 100000

IX4 n 2000 X 75000

SYSIBM.SYSINDEXSPACESTATS

Parent thread

Index

IX3

IX4

IX2

IX1

SELECT FROM… ORDER BY

Child cleanup thread IX3

– Child cleanup thread only startedif Index already open for INSERT, UPDATE or DELETE• ‘X’-type P-lock already held

IDX

In Memory

Page 56: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

SYSIBM.SYSINDEXCLEANUP Example All index spaces in DB_1234 are enabled for cleanup on Sundays from 4:30 until noon,

except

– Index space IX_9876 is always disabled for cleanup

DB2 checks SYSIBM.SYSINDEXCLEANUP table at 10 min intervals– Enforcement of new row may be delayed up to 10 min

RECOMMENDATION: Use rows in SYSIBM.SYSINDEXCLEANUP only to define exceptions to default index cleanup behavior– Define time windows at system or database levels, rather than specific indexes when

possible– Remove unneeded or conflicting rows

56

DBNAME INDEX-SPACE

ENABLE_DISABLE

MONTH_WEEK

MONTH DAY START_TIME

END_TIME

DB_1234 NULL E W NULL 7 043000 120000

DB_1234 IX_9876 D NULL NULL NULL NULL NULL

SYSIBM.SYSINDEXCLEANUP

IDX

Page 57: © 2015 IBM Corporation Application-enabling features of DB2 10 and 11 for z/OS & DBA enabling features New England DB2 User’s Group June 18, 2015 Jim Brogan

© 2015 IBM Corporation38