Microsoft PowerPoint - Day2下午_Steve Chen_DB2 V8 V9 SQL New ...
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Microsoft PowerPoint - Day2下午_Steve Chen_DB2 V8 V9 SQL New ...

on

  • 527 views

 

Statistics

Views

Total Views
527
Views on SlideShare
527
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Microsoft PowerPoint - Day2下午_Steve Chen_DB2 V8 V9 SQL New ... Document Transcript

  • 1. DB2 for z/OS V8, V9 New SQL Features Steve Chen yschen@us.ibm.com DB2 for z/OS Technical Conference Sept 05-07, 2007 - Shanghai, China Sept 10-12, 2007 - Beijing, China 1
  • 2. Table of Content New SQL Features in V8 New SQL Features in V9 DB2 for z/OS Technical Forum 2
  • 3. New SQL Functions in V8 Breaking the Lim it -- Long Objects M ulti-row FETCH & INSERT INSERT within SELECT Statem ent Identity Colum n Im provement Sequences Dynam ic Scrollable Cursors Comm on Table Expressions & Recursive SQL Stage 1 predicates for unlike-data types M aterialized Query Tables M ultiple DISTINCT M ultiple CCSID per Statement Scalar Full Select DB2 for z/OS Technical Forum 3
  • 4. Key New SQL Functions in V8 - Cont'd REOPT(ONCE) Explain Statement Cache Transparent ROW ID column Session Variables VOLATILE Table Support Table UDF Enhancement DB2 for z/OS Technical Forum 4
  • 5. Breaking the limits Virtual Storage 2 GB 2**31 to 2 **64 Table name sizes 18 to 128 Column name sizes 18 to 30 Partitions 254 to 4096 SQL statement length 32K to 2 MB Index key size 255 to 2000 Literals 255 to 32704 Short strings 255 to 32704 Predicates 255 to 32704 DB2 for z/OS Technical Forum 5
  • 6. Breaking the lim its .... Tables in a join 15 to 255 Current optimization hint 8 to 128 CURRENT PACKAGESET 18 to 128 CURRENT PATH 254 to 2048 CURRENT SQLID 8 to 128 USER 8 to 128 VIEW Name 18 to 128 ALIAS Name 18 to 128 ...... DB2 for z/OS Technical Forum 6
  • 7. Multi-row INSERT Inserts multiple rows on one API call Can be ATOMIC or NOT ATOMIC Can be static or dynamic SQL Significant performance boost INSERT INTO T1 VALUES( :ARRAY1, :ARRAY2) FOR :hv ROW S NOT ATOMIC CONTINUE ON SQLEXCEPTION; DB2 for z/OS Technical Forum 7
  • 8. Multi-row FETCH Returns multiple rows on one API crossing "wide" cursor with locks on multiple rows Supports scrollable and non-scrollable, static and dynamic SQL Significant performance boost DECLARE C1 CURSOR WITH ROW SET POSITIONING FOR SELECT COL1, COL2 FROM T1; OPEN C1; FETCH NEXT ROWSET FROM C1 FOR :hv ROW S INTO :ARRAY1, :ARRAY2; DB2 for z/OS Technical Forum 8
  • 9. Positioned UPDATE/DELETE of Multi-row FETCH Allows positioned UPDATE or DELETE to be used on a "wide" cursor Update all rows Or update a specific row UPDATE T1 SET COL1='ABC' W HERE CURRENT OF CURSOR C1 FOR ROW :hv OF ROW SET DB2 for z/OS Technical Forum 9
  • 10. INSERT within SELECT Elegant technique for retrieving values created / modified by DB2 during INSERT identity columns, sequence values user-defined defaults, expressions columns modified by triggers ROWIDs, CURRENT TIMESTAMP, SELECT C1, C2, C3, C4, C5 FROM FINAL TABLE (INSERT (C1, C5) INTO T1 VALUES('ABC', CURRENT DATE)); DB2 for z/OS Technical Forum 10
  • 11. Identity Column Improvements ALTER support for Identity Columns GENERATED ALW AYS | BY DEFAULT RESTART W ITH value INCREMENT BY MINVALUE | NO MINVALUE MAXVALUE | NO MAXVALUE CYCLE | NO CYCLE CACHE | NO CACHE ORDER | NO ORDER DB2 for z/OS Technical Forum 11
  • 12. Sequences CREATE SEQUENCE ALTER SEQUENCE RESTART W ITH value INCREMENT BY MINVALUE, MAXVALUE CYCLE/NO CYCLE CACHE/NO CACHE GRANT/REVOKE privileges for sequence object NEXT VALUE FOR expression PREVIOUS VALUE FOR expression DB2 for z/OS Technical Forum 12
  • 13. Dynam ic Scrollable Cursors Scrollable cursor provides access to base table rather than work file -- allows viewing of updates by others. Defaults to single row fetch, so DDF applications should use: multi-row FETCH positioned update/delete for multi-row FETCH DECLARE C1 SENSITIVE DYNAMIC SCROLL CURSOR FOR SELECT C1, C2 FROM T1; DB2 for z/OS Technical Forum 13
  • 14. Com mon Table Expressions (CTE) & Recursion Refer to table-name later in SQL Allow in SELECT, CREATE VIEW , INSERT W ITH table-name [ column-list ] AS fullselect For recursion fullselect of CTE refers to itself fullselect that does not refer to CTE UNION ALL fullselect that refers to CTE DB2 for z/OS Technical Forum 14
  • 15. Com mon Table Expression & Recursion Example W ITH RPL (PART, SUBPART, QUANTITY) AS ( SELECT R.PART, R.SUBPART, R.QUANTITY FROM PARTLIST AS R W HERE R.PART = '01' UNION ALL SELECT C.PART, C.SUBPART, C.QUANTITY FROM RPL AS PARENT, PARTLIST AS C W HERE PARENT.SUBPART = C.PART ) SELECT DISTINCT PART, SUBPART, QUANTITY FROM RPL ORDER BY PART, SUBPART, QUANTITY; DB2 for z/OS Technical Forum 15
  • 16. Stage 1 Predicate for Unmatch Operands Turning Predicate to stage-1 predicate aggressively Employing stage-1 predicate in index Significant performance improvement for many applications Emp (Name char(11), Gender char(1), Sal int) SELECT * FROM EMP W HERE Gender ='F' AND Sal > 999999.99; prior to V8 V8 & beyond Evaluated as a Stage-2 predicate Evaluated as a Stage-1 predicate Fetching half of the EMP table Fetching 10% of the EMP table through through the index on the Gender the index on the Sal column column Apply the stage-1 predicate Apply the stage-2 predicate DB2 for z/OS Technical Forum 16
  • 17. Stage 1 Predicate for Unmatch Operands SELECT * FROM EMP E, DIVISION D W HERE E.Sal > D.Midmark * 1.25 AND E.Division = D.Id AND D.Midmark > 50000 prior to V8 V8 & beyond Evaluated as a Stage-2 predicate Evaluated as a Stage-1 predicate Join DIVISION to EMP Join DIVISION to EMP Fetch EMP records for the division Fetch EMP records through the Apply the stage-2 predicate index on E.Division or index on E.Sal Apply the stage-1 predicate DB2 for z/OS Technical Forum 17
  • 18. Materialized Query Tables Sometimes called Summary Tables, Automatic Summary Tables, Automatic Materialized Query Tables, Materialized Views, ... Optimizer can rewrite queries to access MQT instead of base table or view Pre-computed information, very significant performance improvement Managed by user or system (SQL REFRESH) Automatic rewrite or manual Informational Referential Integrity (not enforced) DB2 for z/OS Technical Forum 18
  • 19. Click here to type page title DB2 for z/OS Technical Forum 19
  • 20. Click here to type page title DB2 for z/OS Technical Forum 20
  • 21. Materialized Query Table CREATE TABLE DATAMART_MQT AS ( SELECT T.MONTH, P.KIND, SUM(F.QTY * F.PRICE) TOTAL SUM(F.QTY * F.PRICE) CNT FROM Transacs F, Calendar T, Products P, Stores S W HERE F.DID = T.ID AND F.PID = P.ID AND F.SID = S.ID AND GROUP BY P.KIND, T.MONTH, S.SALESZONE ) DATA INITIALLY DEFERRED REFRESH DEFERRED MAINTAINED BY SYSTEM ENABLE QUERY OPTIMIZATION IN ...; DB2 for z/OS Technical Forum 21
  • 22. Materialized Query Table SELECT T.MONTH, P.KIND, AVG (F.QTY * F.PRICE) AVGAMT FROM Transacs F, Calendar T, Products P, Stores S W HERE F.DID = T.ID AND F.PID = P.ID AND F.SID = S.ID AND T.MONTH IN ('01/01', '02/01', '01/02', '02/02') AND P.KIND IN ('FOOD', 'DRINK', 'TOOLS') GROUP BY P.KIND, T.MONTH ORDER BY T.MONTH, P.KIND; AFTER QUERY Query Rewrite SELECT MONTH, KIND, CASE W HEN SUM(CNT) = 0 THEN NULL ELSE SUM(TOTVAL)/SUM(CNT) END AVGAMT FROM DATAMART_MQT W HERE MONTH IN ('01/01', '02/01', '01/02', '02/02') AND KIND IN ('FOOD', 'DRINK', 'TOOLS') GROUP BY KIND, MONTH ORDER BY MONTH, KIND; DB2 for z/OS Technical Forum 22
  • 23. Multiple DISTINCT Distinct keyword can be specified more than once as long as the semantics is well-defined In SELECT list and HAVING clause select count(distinct(c1)), count(distinct(c2)) ... select avg(distinct(c1)), sum(distinct(c2)) ... select min(distinct(c1)), max(distinct(c2)) from t where c3 > 100 group by c4 select count(distinct(c1)) from t group by c2 having avg(distinct(c3)) > 1 DB2 for z/OS Technical Forum 23
  • 24. Multiple CCSIDs per Statement A single SQL statement can now intermix EBCDIC , ASCII and Unicode tables and host variables Unlike host variables are translated to column CCSID Unlike column CCSIDs are "promoted" to Unicode May require query to be materialized/sorted SELECT e.C1 || a.C1 , e.C2 || GX'42C1' FROM ET e, AT a, UT u W HERE e.C1 = u.C1 and EBCDIC Unicode a.C2 = GX'42C1' and UX'42C142C2' = X'C1C2' Unicode Unicode ASCII DB2 for z/OS Technical Forum 24
  • 25. Scalar fullselect Allows scalar fullselect where expressions were previously supported Result is the null value if the fullselect does not return a row. SQLCODE -811 if more than one row returned select product, price from products where price between 2 * (select min(price) from products) and 0.5 * (select max(price) from products); select part, (select price from partprice where part = a.part) from parts a DB2 for z/OS Technical Forum 25
  • 26. Scalar fullselect - 2 UPDATE NEW _PARTPRICE N SET PRICE = CASE W HEN( (SELECT ONHAND# FROM INVENTORY W HERE PART=N.PART) < 7 ) THEN 1.1 * PRICE W HEN( (SELECT ONHAND# FROM INVENTORY W HERE PART=N.PART) > 2 ) THEN .8 * PRICE ELSE PRICE END; DB2 for z/OS Technical Forum 26
  • 27. IS NOT DISTINCT FROM A new predicate to support NULL = NULL IS NOT DISTINCT FROM --- (sim ilar to equal) IS DISTINCT FROM ---- (sim ilar to not equal) SELECT C1 FROM T1 WHERE SELECT C1 FROM T1 W HERE C1 IS NOT DISTINCT FROM :hv; C1 IS DISTINCT FROM :hv; C1 value :hv value result C1 value :hv value result Null 'abc' false Null 'abc' true Null Null true Null Null false 'abc' 'abc' true 'abc' 'abc' false 'abc' Null false 'abc' Null ture 'abc' 'def' false 'abc' 'def' ture DB2 for z/OS Technical Forum 27
  • 28. REOPT(ONCE) BIND Option Controls when DB2 builds access path for dynamic SQL Default, access path is calculated at PREPARE. REOPT(ONCE) Defers access path selection until OPEN Values of host variables on OPEN used to calculate access path at the first execution Resulting access path cached in the statement cache DB2 for z/OS Technical Forum 28
  • 29. EXPLAIN for Global Statement Cache Enhancements to the EXPLAIN statement allow you to obtain EXPLAIN information for entries in the DB2 global statement cache Visual Explain uses this new function. EXPLAIN STMTCACHE STMTID=integer STMTTOKEN=string DB2 for z/OS Technical Forum 29
  • 30. Transparent ROW ID column Eliminates the need to explicitly declare a ROWID column in tables that include LOB s DB2 will generate a "hidden" ROW ID column, which is not visible on SELECT * Simplifies porting of LOB applications from other platforms DB2 for z/OS Technical Forum 30
  • 31. Session Variables Variables set by DB2, connection or signon exit Built in function to retrieve value for a variable Use function in views, triggers, stored procedures & constraints to enforce security policy Can have more general, flexible access checks Multiple columns, AND/OR logic, ... PLAN, PACKAGE, SECLABEL, VERSION, ... Complements other security mechanisms CREATE VIEW V1 AS SELECT * FROM T1 W HERE COL5 = GETVARIABLE(SYSIBM.SECLABEL); DB2 for z/OS Technical Forum 31
  • 32. VOLATILE Table Support Encourages index access for tables that have unpredictable cardinality Disable List Prefetch and certain optimization Significant performance improvement for some SAP applications CREATE TABLE XYZ ...... VOLATILE DB2 for z/OS Technical Forum 32
  • 33. Table UDF Enhancement Table UDF Cardinality clause Specify the expected number of rows returned by UDF Used by optimizer for better access path Select * from books b, table(contains(1, 'database') CARDINALITY 15000) as X1(ID) where b.id = X1.id; prior to V8 V8 and beyond Stage 2 predicate Stage 2 predicate, if book --> TUDF R scan on books Stage 1 predicate, if TUDF --> books TABLE UDF block fetch All rows are returned during the first invocation of the UDF Store the returned rows into workfile Predicate using TABLE UDF indexable and stage 1 DB2 for z/OS Technical Forum 33
  • 34. DB2 Catalog V8 Longer nam es (128 byte varchar Unicode) table, view & alias colum n (30) schem a UDF, stored procedures, triggers, package Som e page sizes greater than 4K 4K, 8K, 16K, 32K pages in DB2 catalog Indexes longer than 255 bytes Contains Unicode data DB2 for z/OS Technical Forum 34
  • 35. Click to edit Master title style SQL Enhancements in V9 DB2 for z/OS Technical Forum DB2 for z/OS Technical Forum 35
  • 36. Key SQL Functions in V9 New data types: BIGINT, BINARY, VARBINARY, DECFLOAT Instead of Trigger Merge SELECT FROM MERGE/UPDATE/DELETE ORDER BY and FETCH FIRST in subselect TRUNCATE INTERSECT/EXCEPT Index on Expression FETCH Continue DB2 for z/OS Technical Forum 36
  • 37. Key SQL Functions in V9 - cont'd Sparse Index and In Memory Data Caching Dynamic Index Anding and Star Schema OLAP specification -- RANK, DENSE_RANK, ROW _NUMBER RENAME INDEX/COLUMN REOPT (AUTO) Clone Table Spatial DB2 for z/OS Technical Forum 37
  • 38. New data types: BIGINT, BINARY, VARBINARY, DECFLOAT BIGINT - big integer. Big integer is a binary integer with a precision of 63 bits. The range of big integers is [-9223372036854775808, 9223372036854775807 BINARY ? fixed-length binary string. Fixed-length binary string is in a range of [1,255]. The padding with hexadecimal zeros (X? 0?. Not associated with any CCSID VARBINARY ? varying-length binary string. Varying-length binary string is in a range of [1,32704]. No padding is performed. Not associated with any CCSID DECFLOAT ? Decimal float. DECFLOAT(16) = decimal64 format (8 bytes) DECFLOAT(34) = decimal128 format (16 bytes) DB2 for z/OS Technical Forum 38
  • 39. DECFLOAT Both IEEE and hexadecimal floating point numbers can only approximate common decimal numbers. But DFP can represent decimal number exactly. DFP can represent much bigger and smaller number than DECIMAL. Description Lim it Smallest DECFLOAT(16) Values -9.999999999999999x10 384 Largest DECFLOAT(16) Value 9.999999999999999x10 384 Smallest positive DECFLOAT(16) 1.000000000000000x10 -383 Value Largest negative DECFLOAT(16) value -1.000000000000000x10 -383 Smallest DECFLOAT(34) Value -9.999999999999999999999999999999999x10 6144 Largest DECFLOAT(34) Value 9.999999999999999999999999999999999x10 6144 Smallest positive DECFLOAT(34) 1.000000000000000000000000000000000x10 -6143 Value Largest negative DECFLOAT(34) -1.000000000000000000000000000000000x10 -6143 Value DB2 for z/OS Technical Forum 39
  • 40. Instead of Trigger A new type of trigger (~ BEFORE, AFTER triggers) Defined on VIEW s provides an extension to the updatability of views requested update operation against the view gets replaced by the trigger logic application still believes all operations are performed against the view applicable even for updatable views DB2 for z/OS Technical Forum 40
  • 41. Instead of Trigger CREATE TABLE W EATHER (CITY VARCHAR(25), TEMPF DECIMAL(5,2)); CREATE VIEW CELCIUS_WEATHER_V (CITY, TEMPC) AS SELECT CITY, (TEMPF-32)*5.00/9.00 FROM W EATHER CREATE TRIGGER CW_INSERT INSTEAD OF INSERT ON CELCIUS_WEATHER_V REFERENCING NEW AS NEWCW DEFAULTS NULL FOR EACH ROW MODE DB2SQL INSERT INTO WEATHER VALUES (NEW CW.CITY, 9.00/5.00*NEW CW.TEMPC+32) CREATE TRIGGER CW_UPDATE INSTEAD OF UPDATE ON CELCIUS_W EATHER_V REFERENCING NEW AS NEWCW OLD AS OLDCW DEFAULTS NULL FOR EACH ROW MODE DB2SQL UPDATE WEATHER AS W SET W.CITY = NEWCW.CITY, W .TEMPF = 9.00/5.00*NEW CW.TEMPC+32 WHERE W.CITY = OLDCW.CITY DB2 for z/OS Technical Forum 41
  • 42. Merge Combine Update and Insert operation to a target table or view, from a input source of a list of host-variable-arrays modeled as a source table W hen source rows match to target, Update target rows from source W hen source rows do not match to target, Insert source rows into target Update/Insert triggers will be fired MERGE INTO account AS T USING VALUES (:hv_id, :hv_amt) FOR 5 ROW S AS S(id,amt) ON T.id = S.id W HEN MATCHED THEN UPDATE SET balance = T.balance + S.amt W HEN NOT MATCHED THEN INSERT (id, balance) VALUES (S.id, S.amt) NOT ATOMIC CONTINUE ON SQLEXCEPTION DB2 for z/OS Technical Forum 42
  • 43. SELECT FROM MERGE/UPDATE/DELETE V8 - The INSERT statement was allowed in the FROM clause V9 - A searched UPDATE/DELETE is now allowed in the FROM clause Delete employees at level 'Contractor' and return the total amount of salary: SELECT SUM(Salary) FROM OLD TABLE (DELETE FROM Employee W HERE Level = 'Contractor'); DB2 for z/OS Technical Forum 43
  • 44. SELECT FROM MERGE/UPDATE/DELETE Update salaries of employees at level 'Associate' and return the new salary: SELECT Name, Salary FROM FINAL TABLE (UPDATE Employee SET Salary = Salary *1.1 WHERE Level = 'Associate'); Update salaries of employees at level 'Associate' and return the old salary: SELECT Name, Salary FROM OLD TABLE (UPDATE Employee SET Salary = Salary *1.1 W HERE Level = 'Associate'); DB2 for z/OS Technical Forum 44
  • 45. ORDER BY and FETCH FIRST in subselect ORDER BY clause can be specified in subselect or fullselect FETCH FIRST n ROW S ONLY clause can be specified in subselect or fullselect ORDER OF table-designator extension to the ORDER BY clause (SELECT * FROM T1 (SELECT * FROM T1 ORDER BY C1) ORDER BY C1) UNION UNION (SELECT * FROM T2 SELECT * FROM T2 ORDER BY C2 ORDER BY C2 FETCH FIRST 2 ROWS) FETCH FIRST 2 ROWS DB2 for z/OS Technical Forum 45
  • 46. Example Using the EMP_ACT table, find the project numbers that have an employee whose salary is in the top 3 of all employees. SELECT EMP_ACT.EMPNO, PROJNO FROM EMP_ACT WHERE EMP_ACT.EMPNO IN (SELECT EMPLOYEE.EMPNO FROM EMPLOYEE ORDER BY SALARY DESC FETCH FIRST 3 ROWS ONLY ) Employee EMP_ACT EMPNO SALARY EMPNO PROJNO 5 100,000 EMPNO SALARY 5 100 8 50,000 12 150,000 8 101 subq 11 60,000 5 100,000 11 123 12 150,000 22 80,000 12 100 18 30,000 18 112 22 80,000 22 105 23 55,000 23 107 DB2 for z/OS Technical Forum 46
  • 47. TRUNCATE Table A fast way to empty a table DELETE Triggers are ignored Indexes, LOB, XML Tablespaces are also deleted X lock on the target table, Mass-delete T R U N C AT E < T AB LE > T AB LE - N AM E < D R O P ST O R AG E | R E U SE ST O R AG E > < R E ST R I C T W H E N D E LE T E T R I G G E R S | I G NO R E D E LE T E T R I G G E R S> < I M M E D I AT E > DB2 for z/OS Technical Forum 47
  • 48. INTERSECT/EXCEPT SET operator: UNION, INTERSECT, EXCEPT R 1 R 2 R 1 R 2 IN T E R S E C T EXC EPT ( D if f e r e n c e ) R 1 R 2 U N IO N SELECT c11, c12, ? c1n FROM T1 <set-op> SELECT c21, c22, ? c2m FROM T2 DB2 for z/OS Technical Forum 48
  • 49. INTERSECT/EXCEPT EXCEPT INTERSECT R1 R2 UNION ALL UNION EXCEPT INTERSECT ALL ALL 1 1 1 1 1 2 1 1 1 1 1 2 2 5 1 3 1 3 1 3 2 3 4 2 3 1 4 2 4 2 3 1 5 4 2 3 2 5 3 4 2 4 2 4 3 5 3 3 3 3 4 4 4 5 DB2 for z/OS Technical Forum 49
  • 50. Index on Expression Create index on result of Expression Enhance Query Performance If we want to search for customers whose Upper(Lastname) = 慡MITH CREATE INDEX IX_LastName ON CUSTOMER ( UPPER (Lastname), CUSTOMER_ID); SELECT * FROM EMP WHERE UPPER (Lastname) = 'SMITH'; Root Root S M IT H S m ith bush s m it h SMITH(Brian) BUSH SMITH(John) … ZAJAC SMITH(K yle) DB2 for z/OS Technical Forum 50
  • 51. Index on Expression - 2 CREATE INDEX IX1 ON T1 ( HEX(c1), BINARY(LTRIM(c2)) ); CREATE INDEX IX2 ON T2 (SUBSTR(c2, 1, 23), CONCAT(c2, c3)); CREATE INDEX IX3 ON T2 (salary, bonus/salary, bonus+salary); CREATE INDEX IX4 ON T1 (DAYOFYEAR(endship) - DAYOFYEAR(startship)); CREATE INDEX IX5 ON T2 (GRAPHIC(c3)); CREATE INDEX IX6 ON T1 (VARCHAR(INSERT(vchar30,1,0,''),20)); CREATE INDEX IX7 ON T1 (posstr(lvcharx2, '7.2E+02')) ; CREATE INDEX IX8 ON T1 (MIDNIGHT_SECONDS(birthday)); DB2 for z/OS Technical Forum 51
  • 52. FETCH CONTINUE Provides 2 new syntax extensions on FETCH for LOB and XML data: FETCH W ITH CONTINUE Just like a regular FETCH but Tells DB2 how to react when truncation occurs on output of a LOB or XML column Preserve the rest of the data, remember positiion In the output length field, return the size that the host variable should have been No effect on VARCHAR column truncation FETCH CURRENT CONTINUE Tells DB2 to continue fetching from the truncation point The CURRENT keyword implies 搒tay on the same row Can be executed multiple times to 搒tream? the data 揜 ow-based? operation ? DB2 tries retrieve all truncated LOB/XML columns. Column-based operation can be achieved by setting output lengths to zero for other columns DB2 for z/OS Technical Forum 52
  • 53. FETCH CONTINUE – Basic Application Application Flow DB2 Integer hostvar1 74 char[32767] hostvar2 1048576 | I’m a looo…oooo Char[ ] *hostvar3 “based” structure T1 INTCOL CLOBCOL (10MB) DECLARE CURSOR C1 FOR SELECT INTCOL, CLOBCOL FROM T1 … 23 I’m a short LOB 74 I’m a loo…oong LOB OPEN C1 FETCH WITH CONTINUE C1 Assume INTO :hostvar1, :hostvar2 1MB If hostvar2 was truncated { get length from output length field allocate storage to hold the rest FETCH CURRENT CONTINUE INTO :hostvar3 } heap storage: 1015809 | ooooooo…ooooooong LOB DB2 for z/OS Technical Forum 53
  • 54. OLAP specification -- RANK, DENSE_RANK, ROW_NUMBER RANK() OVER Window ----> OLAP Function PARTITION BY sh.territory --- row should be assigned to partition according to territory ORDER BY sh.sales --- row sorted in the order of sales amount within each partition Apply after Join, Predicates, Group By, Having A new class of aggregate functions Rank DENSERANK ROWNUMBER SELECT sh.territory, sh.sales, Rank() over (PARTITION BY sh.territory ORDER BY sh.sales desc) as rank FROM sales_history; DB2 for z/OS Technical Forum 54
  • 55. OLAP specification -- RANK, DENSE_RANK, ROW _NUMBER SELECT EMPNUM, DEPT, SALARY, RANK() OVER (ORDER BY SALARY DESC) as RANK, DENSERANK() OVER (ORDER BY SALARY DESC)as DENSERANK, ROWNUMBER() OVER (ORDER BY SALARY DESC) as ROWNUM FROM EMPLOYEE; EMPNUM DEPT SALARY RANK DENSERAN ROWNUM K 3 - 84000 1 1 1 8 3 79000 2 2 2 6 1 78000 3 3 3 2 1 75000 4 4 4 7 1 75000 4 4 5 12 3 75000 4 4 6 10 3 55000 7 5 7 11 1 53000 8 6 8 DB2 for z/OS Technical Forum 55
  • 56. RENAME INDEX/COLUMN W ithout having to drop and recreate the object Rename Column ALTER TABLE tb1 RENAME COLUMN old_columnname TO new_columnname Rename Index RENAME INDEX/TABLE old_name TO new_name DB2 for z/OS Technical Forum 56
  • 57. REOPT(AUTO) W e currently have REOPT(NONE), REOPT(ONCE) and REOPT(ALW AYS) for a dynamic query (with parameter marker). REOPT(NONE) Generate access path based on default filter factor at BIND time Cache the access path REOPT(ALW AYS) Generate access path based on real parameter marker value at each execution No statement cache REOPT(ONCE) Generate access path based on real parameter marker value at the first excution Cache the access path DB2 for z/OS Technical Forum 57
  • 58. REOPT(AUTO) REOPT(AUTO) Generate access path based on real parameter marker value at the first execution. Cache the access path At each execution, DB2 will check if the cache plan is still a good one based on the real value. A new prepare might be automatically invoked Cache the newly generated access path DB2 for z/OS Technical Forum 58
  • 59. Clone Table MY_IX2 MY_IX1 DB2 catalog ... ... SYSTABLES (etc) MY_BASE_TABLE char # date UDT_$$$LOB MY_CLONE_TAB LE LOB AUX TS MY_BASE_TABLE MY_IX2 catnam e.DSNDBx.MYDB1.TSPACE1.I000 1 .A001 MY_IX1 ... ... ALTER TABLE MY_BASE TABLE ADD CLONE MY_CLONE_TABLE MY_CLONE_TABLE char # date UDT_$$$ LOB LOB AUX TS catname.DSNDBx.MYDB1.TSPACE1.I000 2 .A001 DB2 for z/OS Technical Forum 59
  • 60. Clone Table - EXCHANGE statement EXCHANGE DATA BETWEEN MY_BASE_TABLE AND MY_CLONE_TABLE MY_IX2 MY_IX1 .. DB2 catalog .. . . SYSTABLES (etc) char # date UDT_$$$ LOB MY_BASE_TABLE MY_CLONE_TABLE LOB AUX TS MY_BASE_TABLE catname.DSNDBx.MYDB1.TSPACE1.I0002 .A001 MY_IX2 MY_IX1 appl pgm .. .. . . SELECT . . . char # date UDT_$$$ LOB FROM MY_BASE_TABLE LOB AUX TS MY_CLONE_TABLE catname.DSNDBx.MYDB1.TSPACE1.I0001 .A001 DB2 for z/OS Technical Forum 60
  • 61. Seattle Olympia Spokane Portland Great Falls Bangor Sale m Helena Bismark Augusta St. Paul Montpelier Conc ord Boise Minneapolis Boston Sioux Pie rre Milwaukee Albany Falls Provide nce Detroit Hartford Rock Springs M adison Lansing Sioux Des Carson City Che yenne City Cleveland New York M oine s Philadelphia Omaha Chicago Tre nton Salt Lake City Pittsburgh Sacramento Lincoln Harrisbur g Dove r San Francisco Springfield Columbus Kansas City Indianapolis Washington, D.C. De nve r Je ffe rson Charleston Las Annapolis Vegas Tope ka City Richmond Frankfort Norfolk St. Louis Louisville Los Angeles Santa Fe Raleigh Amarillo Tulsa O klahoma Nashville San Diego Cit y Little Rock Albu querque Columbia Phoenix Birmingham Atlanta Ch arleston Tucson Dallas Jack son M ontgome ry El Paso Tallahasse e Baton Rouge Jacksonville Austin New O rleans Houston Tam pa Spatial Honolulu Corpu s Christi Miami Fairbanks Brownsville Anchorage Valdez June au San Juan Modeling spatial data Spatial data type ST_POINT, ST_POLYGONE, ... Spatial UDF Created by DB2 when enabling V9 Spatial support CREATE DISTINCT DATA TYPE db2gse.ST_Polygone AS BLOB(2M); CREATE FUNCTION db2gse.ST_Contains ( geometry1 db2gse.ST_Point, geometry2 db2gse.ST_Polygon) ...... Indexing spatial data Manipulating spatial data Spatial query Spatial predicate DB2 for z/OS Technical Forum 61
  • 62. Seattle Olympia Spokane Portland Great Falls Bangor Salem Helena Bismark Augusta St. Paul Montpelier Concord Boise Minneapolis Boston Sioux Pierre Milwaukee Albany Falls Providence Detroit Hartford Rock Springs Madison Lansing Sioux Des Carson City Che yenne City Cleveland New York Moine s Philadelphia Omaha Chicago Trenton Salt Lake City Pittsburgh Sacramento Lincoln Harrisburg Dover San Francisco Springfield Columbus Kansas City Indianapolis Washington, D.C. Denver Jefferson Charleston Las Annapolis Vegas Tope ka City Richmond Frankfort Norfolk St. Louis Louisville Los Angeles Santa Fe Raleigh Amarillo Tulsa Oklahoma Nashville San Diego City Little Rock Albuquerque Phoenix Columbia Birmingham Atlanta Charleston Tucson Dallas Jackson Montgomery El Paso Tallahassee Austin Baton Rouge Jacksonville New Orleans Houston Tampa Spatial - cont'd Honolulu Corpus Christi Miami Fairbanks Brownsville Anchorage Valdez Juneau San Juan CREATE TABLE CUSTOMERS ( ..., LOCATION DB2GSE.ST_POINT, ... ) ; CREATE INDEX using stored procedue CALL sysproc.ST_create_index (null,'CUSTOMERS','LOCATION',.....) INSERT INTO CUSTOMERS (..., LOCATION) VALUES ( ..., DB2GSE.ST_POINT( ... ) ) ; SELECT * FROM customers c, crimeZone cz WHERE db2gse.ST_within (c.Location, cz.CrimeZone) = 1; DB2 for z/OS Technical Forum 62