A List of  DB2 Top Ten Lists In which we ponder numerous DB2 topics for learning and amusement Craig S. Mullins VP, Data S...
The Top Ten Lists <ul><li>And now, from the home office in </li></ul><ul><li>Sugar Land, Texas… a series of </li></ul><ul>...
Top Ten SQLCODEs to Memorize 1.  000 / +100 successful / “no more rows” 2.  -904  resource unavailable 3.  -818  timestamp...
Top Ten DB2 V8 Features <ul><li>1.  Multi-row FETCH and INSERT </li></ul><ul><li>2.  2M SQL Limit </li></ul><ul><li>3.  Pa...
Top Ten DB2 9  for z/OS  Features <ul><li>1.  Universal Table Spaces    and no more creation of simple table spaces (still...
Top Ten Significant Features of  DB2’s First 20+ Years <ul><li>Packages (V2.3) </li></ul><ul><li>Data Sharing (V4) </li></...
Top Ten Most Common DB2 Performance Problems <ul><li>PEBCAK </li></ul><ul><li>Poorly coded SQL </li></ul><ul><li>Improper ...
Top Ten Steps to Proper Indexing <ul><li>Index by workload, not by object </li></ul><ul><li>Build indexes based on predica...
Top Ten Most Common Physical  DB2 Database Design Mistakes  <ul><li>Relying on the defaults </li></ul><ul><li>Not basing t...
Top Ten Most Common  Misunderstandings About DB2 <ul><li>“ There’s a problem with DB2!” </li></ul><ul><li>Using nulls can ...
Top Ten Most Under-Utilized  Features of DB2 <ul><li>Real Time Stats </li></ul><ul><li>CASE statements </li></ul><ul><li>T...
Top Ten Extinct* DB2 Features <ul><li>Type 1 indexes </li></ul><ul><li>The RCT </li></ul><ul><li>Host variables w/o a colo...
Top Ten DB2 Annoyances  <ul><li>Changing the SQL Terminator for Triggers </li></ul><ul><li>No EXPLAIN parameter for CREATE...
Top Ten SQL Mistakes  <ul><li>Syntax </li></ul><ul><li>The “flat file” mentality  </li></ul><ul><li>Ignorance of  New  Fea...
What’s Wrong With This SQL? <ul><ul><li>SELECT  LAST_NAME,  FIRST_NAME,    JOB_CODE,  DEPT,  PHONENO FROM  DSN8810.EMP WHE...
Top Ten SQL Mistakes  <ul><li>Syntax </li></ul><ul><li>The “flat file” mentality  </li></ul><ul><li>Ignorance of  New  Fea...
Top Ten Buffer Pool  Tuning Steps  <ul><li>Do not use one large BP0 –  spread the wealth! </li></ul><ul><li>Use BP0 for sy...
Top Ten DBA Excuses <ul><li>It depends. </li></ul><ul><li>RTFM </li></ul><ul><li>“ Did you fill out the form?” </li></ul><...
Top Ten Programmer Excuses <ul><li>“ There’s something wrong with DB2!” </li></ul><ul><li>“ But I copied that from another...
Top Ten Management Excuses <ul><li>“ We’re over-budget.” </li></ul><ul><li>“ The project is under-funded.” </li></ul><ul><...
Top Ten Database Trends <ul><li>From Many to “3” </li></ul><ul><li>Open Source </li></ul><ul><li>The Giant Sucking Sound <...
Top Ten Types of DB2 Tools <ul><li>Change Manager </li></ul><ul><li>Catalog Visibility </li></ul><ul><li>SQL Performance M...
Top Ten Sources for  DB2 Information  <ul><li>IBM manuals </li></ul><ul><li>IDUG </li></ul><ul><li>Local DB2 user groups <...
Top Ten Books for  DB2 Professionals <ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><...
Craig S. Mullins NEON Enterprise Software, Inc. [email_address] http://www.craigsmullins.com © Copyright, Craig S. Mullins...
Upcoming SlideShare
Loading in …5
×

Download

445 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
445
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • -530 23503 Invalid foreign key value specified for the specified constraint name. -532 23504 Deletion violates the named referential constraint. -811 is returned when a singleton SELECT returns more than one row
  • Other interesting features not in the TOP TEN: Non-padded indexes Separate partitioning and clustering Variable CI size Multi-level security INSERT within a SELECT Improvements to identity columns Scalar fullselect Multiple DISTINCTs per statement Refreshing the dynamic statement cache using RUNSTATS REPORT NO UPDATE NONE
  • PBCAK – Problem Between Chair and Keyboard Bachelor Programming Syndrome – Fear of COMMITing; every batch program should have a COMMIT strategy. Copied code syndrome – I copied this from another program and it works there
  •  
  • By kludging, I mean trying to avoid a certain feature/function so using something in a way it was not intended… e.g.) avoiding NULLs at all costs, storing numbers in CHAR columns, storing dates in CHAR columns, etc.
  • LOBs are on the lemon because there are reasons they are under-utilized – namely, the IBM utilities are limited in how they work with LOBs. Dynamic SQL is dropping because more folks are using it than ever before. ODBC and JDBC as well as access via some gateways require using dynamic SQL. Also, dynamic statement caching helps to improve performance by avoiding re-preparation, so more shops are inclined to consider it these days. Stored procedures would have been on this list a year or two ago, but they are being used more and more these days.
  • LOB Probs! A REORG of a LOB table space does not reclaim physical space. Why do you have to create the unique index? No columns are specified and the index is mandatory? If the total length of the LOB column and the base table row is less than 32KB, you can use the LOAD utility to populate the data into DB2. If the LOB column is greater in size you must use INSERT or UPDATE statements. SQL examples: better examples needed for CASE statements and table expressions, for example DSNZPARMs are not well-documented: have to go to the appendix in the Installation Guide then follow the links to the descriptions in the manual V8 to the rescue though: non-padded indexes, partitioning, cluster/part separation
  • Fear factor – somewhat the opposite of ignorance is fear; knowing about new features but being afraid to use them is just as bad! Existence checking – if all you care about is whether a particular value/row exists, don’t make DB2 return the data to you, just use EXISTS, NOT EXISTS to return TRUE or FALSE (EXISTS does not return any values) Returns “True” for at least one row qualified Returns “False” when no rows qualified The most efficient SQL statement is the one that isn’t executed! Don’t make DB2 do re-work. If you can pass through the data once, do it! If you can save off data needed twice in a program, then do it. The Never-Ending Story – forgetting to terminate each SQL statement in a batch (SPUFI, DSNTEP2, etc.); also a big problem when creating TRIGGERs – you need to define a different SQL termination character than “;”, which is used to terminate SQL statements embedded in the TRIGGER DDL
  • Fear factor – somewhat the opposite of ignorance is fear; knowing about new features but being afraid to use them is just as bad! Existence checking – if all you care about is whether a particular value/row exists, don’t make DB2 return the data to you, just use EXISTS, NOT EXISTS to return TRUE or FALSE (EXISTS does not return any values) Returns “True” for at least one row qualified Returns “False” when no rows qualified The most efficient SQL statement is the one that isn’t executed! Don’t make DB2 do re-work. If you can pass through the data once, do it! If you can save off data needed twice in a program, then do it. The Never-Ending Story – forgetting to terminate each SQL statement in a batch (SPUFI, DSNTEP2, etc.); also a big problem when creating TRIGGERs – you need to define a different SQL termination character than “;”, which is used to terminate SQL statements embedded in the TRIGGER DDL
  • The biggest thing you can do as a DB2 application programmer is to research and understand any issue before you go running to the DBA. If your program fails, find the SQLCODE and reason, see if you can fix it yourself. If you don’t understand something, read the manual before going to the DBA. There is NO REASON why everyone shouldn’t have their own DB2 manuals – they can be downloaded for free over the IBM web site!
  • DB2 Developer’s Guide SAMS Publishing 4 th edition, (October 2000) 5 th edition (May 2004) ISBN: 0672318288 ISBN : 0672326132 www.craigsmullins.com/cm-book.htm Database Administration: The Complete Guide to Practices and Procedures Addison-Wesley Professional 1st edition (June 14, 2002) ISBN: 0201741296 www.craigsmullins.com/dba_book.htm From Book News, Inc. Combining tutorial and reference elements, this guide provides a non- product-based description of database administration techniques and practices. It defines the job of the database administrator (DBA), underscoring the necessity of a DBA for a database management system (DBMS) implementation to succeed, then proceeds chronologically through every task the DBA is likely to encounter. The book can be used as a text for database administration, as the basis for setting up a DBA group, to augment a DBMS-specific text or manual, and to help upper-level management explain why the DBA position is necessary.
  • Download

    1. 1. A List of DB2 Top Ten Lists In which we ponder numerous DB2 topics for learning and amusement Craig S. Mullins VP, Data Strategy NEON Enterprise Software http://www.neon.com http://www.CraigSMullins.com
    2. 2. The Top Ten Lists <ul><li>And now, from the home office in </li></ul><ul><li>Sugar Land, Texas… a series of </li></ul><ul><li>DB2 Top Ten lists about various </li></ul><ul><li>topics ranging across the </li></ul><ul><li>following subjects: </li></ul><ul><li>Performance </li></ul><ul><li>Coding </li></ul><ul><li>Design </li></ul><ul><li>Administration </li></ul><ul><li>Management </li></ul><ul><li>Features </li></ul><ul><li>Tools </li></ul>
    3. 3. Top Ten SQLCODEs to Memorize 1. 000 / +100 successful / “no more rows” 2. -904 resource unavailable 3. -818 timestamp mismatch 4. -101 SQL statement too complex 5. -104 illegal symbol in SQL stmt. 6. -530 / -532 RI constraint violation 7. -803 unique violation (duplicate data) 8. -913 deadlock or timeout 9. -922 authorization failure 10. -805 program not found in plan
    4. 4. Top Ten DB2 V8 Features <ul><li>1. Multi-row FETCH and INSERT </li></ul><ul><li>2. 2M SQL Limit </li></ul><ul><li>3. Partitioning changes up to 4096 Partitions, table-based partitioning, clustering separation </li></ul><ul><li>4. Stage 1 for Unlike Data Types </li></ul><ul><li>5. Data Partitioned Secondary Indexes </li></ul><ul><li>6. Sequences </li></ul><ul><li>7. Materialized Query Tables </li></ul><ul><li>8. Dynamic Scrollable Cursors </li></ul><ul><li>9. Recursive SQL </li></ul><ul><li>10. Online Schema Change </li></ul>
    5. 5. Top Ten DB2 9 for z/OS Features <ul><li>1. Universal Table Spaces and no more creation of simple table spaces (still supported if you have them tho’) </li></ul><ul><li>2. Rows arranged for variable data </li></ul><ul><li>3. Index on Expressions </li></ul><ul><li>4. ORDER BY and FETCH FIRST on Subselects </li></ul><ul><li>5. Clone Tables </li></ul><ul><li>6. Not Logged Table Space …but beware </li></ul><ul><li>7. BINARY / VARBINARY …at last, a true binary data type! </li></ul><ul><li>8. Native SQL Procedure Language …no more C compiler </li></ul><ul><li>9. SELECT from UPDATE, DELETE, MERGE </li></ul><ul><li>10. Implicitly Hidden Columns </li></ul><ul><li>11. And, OK, I guess I have to include it, pureXML </li></ul>http://www.db2portal.com/blog.html
    6. 6. Top Ten Significant Features of DB2’s First 20+ Years <ul><li>Packages (V2.3) </li></ul><ul><li>Data Sharing (V4) </li></ul><ul><li>Referential Integrity (V2.3) </li></ul><ul><li>Type 2 Indexes (V4) </li></ul><ul><li>Segmented Table Spaces (V2.3) </li></ul><ul><li>Triggers and UDFs (V6) </li></ul><ul><li>Stored Procedures (V4) </li></ul><ul><li>Multiple Buffer Pools (V3…) </li></ul><ul><li>Breaking many limits (V8) </li></ul><ul><li>DATE / TIME data types (V1.3) </li></ul>
    7. 7. Top Ten Most Common DB2 Performance Problems <ul><li>PEBCAK </li></ul><ul><li>Poorly coded SQL </li></ul><ul><li>Improper indexing </li></ul><ul><li>Bad program design </li></ul><ul><li>Bachelor programming syndrome </li></ul><ul><li>Improperly defined buffer pools </li></ul><ul><li>Index / table space needs to be reorganized </li></ul><ul><li>Improperly designed database structures </li></ul><ul><li>Copied code syndrome </li></ul><ul><li>RUNSTATS not up-to-date (or not even run) </li></ul>
    8. 8. Top Ten Steps to Proper Indexing <ul><li>Index by workload, not by object </li></ul><ul><li>Build indexes based on predicates </li></ul><ul><li>Index most-heavily used queries </li></ul><ul><li>Index important queries </li></ul><ul><li>Index to avoid sorting (GROUP BY, ORDER BY) </li></ul><ul><li>Create indexes for uniqueness (PK, U) </li></ul><ul><li>Create indexes for foreign keys </li></ul><ul><li>Consider adding columns for IXO access </li></ul><ul><li>Don’t arbitrarily limit number of indexes </li></ul><ul><li>Be aware of I/U/D implications </li></ul>
    9. 9. Top Ten Most Common Physical DB2 Database Design Mistakes <ul><li>Relying on the defaults </li></ul><ul><li>Not basing the physical on a logical model </li></ul><ul><li>Over-relying on logical design </li></ul><ul><li>Normalization problems (Over-normalized or too denormalized) </li></ul><ul><li>Not enough indexes </li></ul><ul><li>Indexing by table, not by workload </li></ul><ul><li>Too much (or not enough) free space </li></ul><ul><li>Failing to plan for data purging or archiving </li></ul><ul><li>Failure to share data (not Data Sharing, but sharing data!) </li></ul><ul><li>Kludging </li></ul>
    10. 10. Top Ten Most Common Misunderstandings About DB2 <ul><li>“ There’s a problem with DB2!” </li></ul><ul><li>Using nulls can save space </li></ul><ul><li>DB2 is a “database” </li></ul><ul><li>DB2 is self-managing! </li></ul><ul><li>SQL is simple to learn and code ( properly ) </li></ul><ul><li>If it uses an index it doesn’t need ORDER BY </li></ul><ul><li>Extents don’t matter anymore </li></ul><ul><li>Using BP0 only performs OK </li></ul><ul><li>PIECESIZE matches up IX and TS partitions </li></ul><ul><li>It depends! </li></ul>
    11. 11. Top Ten Most Under-Utilized Features of DB2 <ul><li>Real Time Stats </li></ul><ul><li>CASE statements </li></ul><ul><li>Table Expressions </li></ul><ul><li>Distinct Types </li></ul><ul><li>LOBs </li></ul><ul><li>zIIPs </li></ul><ul><li>User-Defined Functions </li></ul><ul><li>Triggers </li></ul><ul><li>Recursive SQL </li></ul><ul><li>Date/Time Data Types </li></ul>
    12. 12. Top Ten Extinct* DB2 Features <ul><li>Type 1 indexes </li></ul><ul><li>The RCT </li></ul><ul><li>Host variables w/o a colon </li></ul><ul><li>SROD </li></ul><ul><li>Data set passwords </li></ul><ul><li>Simple table spaces </li></ul><ul><li>Manual stored procedure registration </li></ul><ul><li>Non-DRDA distribution </li></ul><ul><li>Hiperpools (and VPs in data spaces) </li></ul><ul><li>Denormalization (because of MQTs?) </li></ul>V8 V9 * or soon to be extinct
    13. 13. Top Ten DB2 Annoyances <ul><li>Changing the SQL Terminator for Triggers </li></ul><ul><li>No EXPLAIN parameter for CREATE TRIGGER </li></ul><ul><li>Fumbling thru the SQL Reference for Syntax (specifically for SELECT) </li></ul><ul><li>SQL examples are too simple in the manuals </li></ul><ul><li>Lack of 100% Platform Compatibility </li></ul><ul><li>Managing Tables with LOBs </li></ul><ul><li>DSNZPARM documentation </li></ul><ul><li>Utilities cost extra </li></ul><ul><li>The database object is strangely implemented </li></ul><ul><li>It is so good that people take it for granted! </li></ul>LOAD, UNLOAD with LOBs V7 V8 : PK22910
    14. 14. Top Ten SQL Mistakes <ul><li>Syntax </li></ul><ul><li>The “flat file” mentality </li></ul><ul><li>Ignorance of New Features (such as CASE and table expressions) </li></ul><ul><li>Fear factor </li></ul><ul><li>Copied code syndrome </li></ul><ul><li>Not coding for performance (ignorance of Stage 1/Stage 2, indexing, etc.) </li></ul><ul><li>Too many columns! . </li></ul><ul><li>Not running the most efficient SQL statement </li></ul><ul><li>Improper “existence” checking </li></ul><ul><li>The Never-Ending Story! </li></ul>
    15. 15. What’s Wrong With This SQL? <ul><ul><li>SELECT LAST_NAME, FIRST_NAME, JOB_CODE, DEPT, PHONENO FROM DSN8810.EMP WHERE JOB_CODE = ‘A’ AND DEPT = ‘MIS’; </li></ul></ul>
    16. 16. Top Ten SQL Mistakes <ul><li>Syntax </li></ul><ul><li>The “flat file” mentality </li></ul><ul><li>Ignorance of New Features (such as CASE and table expressions) </li></ul><ul><li>Fear factor </li></ul><ul><li>Copied code syndrome </li></ul><ul><li>Not coding for performance (ignorance of Stage 1/Stage 2, indexing, etc.) </li></ul><ul><li>Too many columns! </li></ul><ul><li>Not running the most efficient SQL statement </li></ul><ul><li>Improper “existence” checking </li></ul><ul><li>The Never-Ending Story! </li></ul>
    17. 17. Top Ten Buffer Pool Tuning Steps <ul><li>Do not use one large BP0 – spread the wealth! </li></ul><ul><li>Use BP0 for system objects only </li></ul><ul><li>Separate BP for indexes and table spaces </li></ul><ul><li>Set DWQT to enable trickle writing </li></ul><ul><li>Separate random and sequential </li></ul><ul><li>Use VPSEQT to control sequential usage (increase for sequential, decrease for random) </li></ul><ul><li>“ Peg” (small) frequently used tables in memory </li></ul><ul><li>Assign DSNDB07 to BP7 – tune it for sorting </li></ul><ul><li>Do not undersize hiperpool if you use them (ROT: setup HP to be 2x – 3x the size of the VP it backs up) </li></ul><ul><li>Consider dedicated buffer pools (for “special” table spaces) </li></ul>
    18. 18. Top Ten DBA Excuses <ul><li>It depends. </li></ul><ul><li>RTFM </li></ul><ul><li>“ Did you fill out the form?” </li></ul><ul><li>“ I’m busy.” </li></ul><ul><li>“ It’s working as designed – leave me alone.” </li></ul><ul><li>IBM says… </li></ul><ul><li>You couldn’t possibly understand why… </li></ul><ul><li>“ That’s what they said in class.” </li></ul><ul><li>“ Our standards say we do it this way.” </li></ul><ul><li>“ Because I’m the DBA, that’s why!” </li></ul>
    19. 19. Top Ten Programmer Excuses <ul><li>“ There’s something wrong with DB2!” </li></ul><ul><li>“ But I copied that from another program.” </li></ul><ul><li>“ It worked yesterday.” </li></ul><ul><li>“ Isn’t there something you can do to make it work?” </li></ul><ul><li>“ But I can do that better in C; Java; etc.” </li></ul><ul><li>“ It works that way in Oracle; Access; etc.” </li></ul><ul><li>“ It’s too late in the project to re-write that.” </li></ul><ul><li>“ But I heard somewhere it works this way.” </li></ul><ul><li>“ Why do I have to BIND every time?” </li></ul><ul><li>“ DB2 is a hog.” </li></ul>
    20. 20. Top Ten Management Excuses <ul><li>“ We’re over-budget.” </li></ul><ul><li>“ The project is under-funded.” </li></ul><ul><li>“ Work smarter, not harder.” </li></ul><ul><li>“ You better work overtime on that.” </li></ul><ul><li>“ This comes from upper-level management.” </li></ul><ul><li>“ We’re running behind schedule on this.” </li></ul><ul><li>“ You can’t be out of the office that long.” </li></ul><ul><li>“ I read somewhere that isn’t how it works.” </li></ul><ul><li>“ When I was a DBA/programmer/etc. … </li></ul><ul><li>“ That is no longer strategic.” </li></ul>
    21. 21. Top Ten Database Trends <ul><li>From Many to “3” </li></ul><ul><li>Open Source </li></ul><ul><li>The Giant Sucking Sound </li></ul><ul><li>Complexity </li></ul><ul><li>Heterogeneity </li></ul><ul><li>Autonomic/Self-managing </li></ul><ul><li>Lies, lies, lies, yeah! </li></ul><ul><li>The Checkbox Wars </li></ul><ul><li>From VLDB to VHDB </li></ul><ul><li>Application Centricity </li></ul>Marketing
    22. 22. Top Ten Types of DB2 Tools <ul><li>Change Manager </li></ul><ul><li>Catalog Visibility </li></ul><ul><li>SQL Performance Monitor </li></ul><ul><li>BIND and Access Path Analysis </li></ul><ul><li>System Performance Monitor </li></ul><ul><li>DBA Automation / Utility Automation </li></ul><ul><li>Table Editor </li></ul><ul><li>Log Analysis </li></ul><ul><li>Database Structure Analysis </li></ul><ul><li>Application Restart Control </li></ul>
    23. 23. Top Ten Sources for DB2 Information <ul><li>IBM manuals </li></ul><ul><li>IDUG </li></ul><ul><li>Local DB2 user groups </li></ul><ul><li>DB2 Magazine(s) </li></ul><ul><li>Vendor web sites/webinars (neonesoft.com, etc.) </li></ul><ul><li>DB2 books </li></ul><ul><li>Web portals (DB2portal.com, SearchDataManagement.com) </li></ul><ul><li>IBM DB2 Developer’s Domain </li></ul><ul><li>Consultant web sites </li></ul><ul><li>Your co-workers! </li></ul>
    24. 24. Top Ten Books for DB2 Professionals <ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul><ul><li>DB2 Developer’s Guide </li></ul>
    25. 25. Craig S. Mullins NEON Enterprise Software, Inc. [email_address] http://www.craigsmullins.com © Copyright, Craig S. Mullins 2009 www.craigsmullins.com/cm-book.htm DB2 Developer’s Guide, 5ed Available Now DBA: Practices & Procedures www.craigsmullins.com/dba_book.htm

    ×