SQL in V9 of DB2 for Z/OS IDUG 2012 - DENVER

SQL in V9 of DB2 for Z/OS IDUG 2012 - DENVER

SQL in V9 of DB2 for z/OS IDUG 2012 - DENVER Bonnie K. Baker Bonnie Baker Corporation PO Box 18123 Tampa, FL 33679-8123 USA 1-813-477-4885 [email protected] http://www.bonniebaker.com 1 AGENDA PERFORMANCE ENHANCEMENTS SQL CHANGES OBJECT CHANGES 2 PERFORMANCE ENHANCEMENTS Buffer Pool Management • Efficient large BP (>5GB) support • Bigger prefetch and deferred-write quantity for bigger buffer pools – Doubling the prefetch quantity for large buffer pools • Large buffer pool defined as VPSEQT x VPSIZE > 160MB • Max of 128 in V8; now 256KB in V9 for SQL tablespace scan – Was 32 4K pages; now 64 4K pages • 256 in V8; now 512KB in V9 for utilities – Was 64 4K pages; now 128 4K pages 3 PERFORMANCE ENHANCEMENTS Buffer Pool Management continued • Sequential Prefetch has changed in other ways - Now uses Sequential Detection for first 8 Get Pages More use of dynamic prefetch over sequential prefetch • Except for tablespace scans Considered more robust • Data is usually NOT all sequential NOR all random • Allows for data status in between REORGs • Plan_table PREFETCH column will be ‘D’ or ‘S’ 4 PERFORMANCE ENHANCEMENTS Consolidated Temporary Work Space • Single source for all temporary space in DB2 for – SORTWORK – SORTOUT – DECLARED GLOBAL TEMPORARY TABLES – CREATED GLOBAL TEMPORARY TABLES – MATERIALIZED VIEWS – STATIC SCROLL CURSORS – FINAL_TABLEs – For Developers, this means more sharing, more possible -904s – AND 32K Work Space is used much more – should be same as 4K? 5 PERFORMANCE ENHANCEMENTS Consolidated TEMP Space continued • Supports 4K & 32K page sizes . Automatic selection of the appropriate page size (for efficiency) . Expect an increased use of the 32K temp space . Consider sizing your 32K space @ 50% to 100% of your 4K buffers • Monitor statistics and adjust for actual usage • Access is virtualized for small amounts of data (approximately 32K), eliminating cost of work file creation (reduced CPU and I/O) • NEW ZPARM (MAXTEMPS) prevents WORKFILE monopolization – Similar to MaxDegree 6 NEW SQL • MERGE • SELECT FROM . UPDATE . DELETE . MERGE • FETCH FIRST / ORDER BY in Subselect • INTERSECT • EXCEPT • SKIP LOCKED DATA • TRUNCATE • NEW . Built In Functions . Scalar Functions . Session Variables • NATIVE SQL STORED PROCEDURES 7 NEW SQL Select from Update or Delete SINGLETON OR CURSOR SELECT SELECT data from an UPDATE DECLARE CAND CURSOR FOR SELECT ATHLETE, SCORE FROM FINAL_TABLE (UPDATE EVENTS SET SCORE = SCORE + 10 WHERE EVENT = ‘BOXING’) 8 NEW SQL Select from Merge SELECT data from a MERGE with an INCLUDE column (returns the compare column from the ON clause + an indicator of whether the row was Updated or Inserted) DECLARE CURSOR C1 FOR SELECT MEMBER_ID, UPSERT_INDICATOR FROM FINAL_TABLE ( MERGE INTO MEMBER_PROFILE AS T INCLUDE (UPSERT_INDICATOR CHAR(1)) USING (VALUES (:col1, :col2, :col3) ) AS A (MEMBER_ID, MEMBER_NAME, MEAL_PREFERENCE) ON (T.MEMBER_ID = A.MEMBER_ID) --------------------------------------THE COMPARE COLUMN WHEN MATCHED THEN UPDATE SET T.MEMBER_NAME = A.MEMBER_NAME, T.MEAL_PREFERENCE = A.MEAL_PREFERENCE, UPSERT_INDICATOR = 'U' WHEN NOT MATCHED THEN INSERT (MEMBER_ID, MEMBER_NAME, MEAL_PREFERENCE ,UPSERT_INDICATOR) VALUES (A.MEMBER_ID, A.MEMBER_NAME, A.MEAL_PREFERENCE, 'I') NOT ATOMIC CONTINUE ON SQLEXCEPTION ) 9 NEW SQL FETCH FIRST/ ORDER BY in SUBSELECT INSERT INTO T2 (SELECT C1, C2, C3 FROM T1 FETCH FIRST 10 ROWS ONLY ORDER BY C2, C1); 10 NEW SQL INTERSECT AND EXCEPT – Intersect returns the records that two result sets have in common Frequently used in ‘find the duplicates query’ Rows from either result set that do not match are excluded Also INTERSECT DISTINCT to eliminate duplicates – Except returns the rows from RS1 that are not in RS2 Similar to symmetric difference join JOIN TO GET COLUMNS FROM TWO OR MORE TABLES UNION/EXCEPT/INTERSECT TO GET ROWS RS1 RS1 RS2 RS2 11 NEW SQL data data dataX data dataX dataX data data SKIP LOCKED DATA • Rows with incompatible locks held by others are skipped • SQL Clause available – On SELECT INTO, PREPARE, searched UPDATE, searched DELETE, and UNLOAD, so far – Effective only whenISOLATION = CS or RS – Effective only when data is locked at the row or page level • QW0018SK – Rows skipped due to incompatible lock held – Reported in IFCID 018, not in MSTR or user address space • Logic / Scenario – When a transaction needs to find work to do, regardless of order. – Messaging applications without strict ordering requirements expect to be able to skip over records that are locked by other transactions 12 NEW SQL TRUNCATE part 1 • Allows fast delete of all rows in base tables or declared global temporary tables – Simple, segmented, partitioned, or universal tablespaces – Use IMMEDIATE option – operation cannot be rolled back Allows reusing the allocated space immediately for subsequent insert operations in the same unit of work without committing. Not allowed if the table has in-flight modifications • Will Delete rows without firing DELETE triggers • Option to REUSE or DROP STORAGE – Useful for nightly refresh of summary tables, warehouses, etc. 13 NEW SQL TRUNCATE part 2 • Table cannot be TRUNCATEd if it is a parent in a defined referential constraint • Acts just like a mass DELETE (a DELETE with no WHERE clause) for tables with Change DataCapture, Multilevel Security VALIDPROC. • ROLLBACK: TRUNCATE IMMEDIATE: Other tables are rolled back. The truncated table will be empty. TRUNCATE: The truncate is rolled back, along with changes to other tables. • DELETE / ALTER, SYSADM, DBADM or table ownership privileges required. The ALTER privilege is needed for IGNORE DELETE TRIGGERS 14 NEW SQL Built-in Functions • RANK Generates a row number defining the rank as 1 plus the number of rows that precede the row. If two or more rows are not distinct with respect to the ordering, there will be one or more GAPS in the sequential rank numbering. This is also referred to as OLYMPIC RANKING. • DENSE_RANK Similar to RANK but ensures there are NO GAPS. Useful for statistical analysis Even though these ranking functions are ordered, cursors remain updatable. These functions do not make the cursor unambiguously read-only! 15 NEW SQL Built-in Functions • ROW_NUMBER DEFAULT DATATYPE = BIGINT – Creates a sequential row number that is computed for each row starting with 1. – No number skipping. SELECT SMALLINT(ROW_NUMBER() OVER (ORDER BY score DESC)) AS ROW_NUMBER, athlete, score FROM scores ORDER BY score DESC 16 SOUNDEX Scalar Function • Powerful scalar functions for name identification – The SOUNDEX function returns a 4 character code that represents the sound of the words in the argument. – The result can be used to compare with the sound of other strings. – The SOUNDEX function is useful for finding strings for which the sound is known but the precise spelling is not. SELECT athlete,SOUNDEX(athlete) – the 4 character code for the name - as snd_value FROM scores; SELECT empno,lastname FROM dsn8910.emp WHERE SOUNDEX(lastname) = SOUNDEX(‘Loucesy’) 17 18 Unicode SBCS (single-byte character set): An international character code for information processing that is designed to encode all characters that are used for written communication in a simple and consistent manner. The Unicode character encoding was originally established as a fixed-width, 16-bit encoding to provide enough code points for all the scripts and technical symbols in common usage around the world, plus some ancient scripts. 19 NEW SQL DIFFERENCE Scalar Function • A function that returns a value from 0 to 4 • Represents the difference between the 4-character sounds of two strings based on applying the SOUNDEX function to the strings. – A value of 4 is the best possible sound match. – A value of 0 is the worst possible sound match. SELECT DIFFERENCE(‘CONSTRAINT’,’CONSTANT’) AS DIFFERENCE1, DIFFERENCE(‘CONSTANT’, ‘CONSTRICT’) AS DIFFERENCE 2, SOUNDEX(‘CONSTRAINT’) AS CONSTRAINT, SOUNDEX(‘CONSTANT’) AS CONSTANT, SOUNDEX(‘CONSTRICT’) AS CONSTRICT FROM SYSIBM.SYSDUMMY1; DIFFERENCE1 DIFFERENCE2 CONSTRAINT CONSTANT CONSTRICT 4 2 C523 C523 C534 20 NEW SQL . Session Variables contain server and application process information . Builds on the 11 Session Variables introduced in V8 . Use GETVARIABLE to obtain the DB2 V9 zparm DSNHDECP value SYSIBM.APPLICATION_ENCODING_SCHEME SYSIBM.DSNHDECP_NAME SYSIBM.COBOL_STRING_DELIMITER SYSIBM.DYNAMIC_RULES SYSIBM.DATE_FORMAT SYSIBM.ENCODING_SCHEME SYSIBM.DATE_LENGTH SYSIBM.MIXED_DATA SYSIBM.DECIMAL_ARITHMETIC SYSIBM.NEWFUN SYSIBM.DECIMAL_POINT SYSIBM.PAD_NUL_TERMINATED SYSIBM.DEFAULT_DECFLOAT_ROUND_MODE SYSIBM.SQL_STRING_DELIMITER SYSIBM.DEFAULT_DEFAULT_SSID SYSIBM.SSID SYSIBM.DEFAULT_LANGUAGE SYSIBM.STANDARD_SQL SYSIBM.DEFAULT_LOCALE_LC_CTYPE SYSIBM.TIME_FORMAT SYSIBM.DISTRIBUTED_SQL_STRING_DELIMITER SYSIBM.TIME_LENGTH SET :HV1 = GETVARIABLE(SYSIBM.DECIMAL_POINT) 21 Native SQL Procedural Language • Eliminates generated C code and compilation • Fully integrated into the DB2 engine – Any SQL procedure created without the FENCED or EXTERNAL keywords are native SQL procedures • zIIP enabled for DRDA clients • Extensive support for versioning: – VERSION keyword on CREATE PROCEDURE – CURRENT ROUTINE VERSION special register – ALTER ADD VERSION – ALTER REPLACE VERSION – ALTER ACTIVATE VERSION • BIND PACKAGE with new DEPLOY keyword 22 NEW SQL REOPT BIND parameter – see next page for details V9 – REOPT(NONE) – REOPT(ALWAYS), AKA REOPT(VARS) • Dynamic & Static SQL – REOPT(ONCE) • Dynamic SQL 23 INDEX LOOKASIDE V8 the Clustering Index could use lookaside for SELECTs, INSERTs, and UPDATEs But No lookaside

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    38 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us