1 / 52

Transparent Gateway for DB2 a success story

Learn about the successful implementation of Transparent Gateway for DB2 in a geomarketing project. Understand how it works, the pre-processing and post-processing steps, gateway parameters, and lessons learned.

fupton
Download Presentation

Transparent Gateway for DB2 a success story

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Transparent Gateway for DB2 a success story Thomas NiewelOracle Deutschland GmbHThomas.Niewel@Oracle.com

  2. Agenda • The Geomarketing Project • TG4DB2 – How it works • Pre-Processing • Post-Processing • Gateway Parameters • Things to think about in a dB2 world • DB2 Locking Model • Predicates • Lessons we have learned

  3. The project – Geomarketing • The service center of a bank needed to provide a control instrument for marketing activities • The marketing actions should be controlled by spatial data and operational data • The requirements for the platforms were • Spatial Data should reside Windows • Operational Data is stored on DB2 for z/OS • There are existing DB2 for z/OS datawarehouseswhich should be used as source • There are 3 different LPARs with DB2 data • RACF should be used to autenticate users

  4. Web Browser The project – Geomarketing zSeries Windows TG4DB2 DB2 GIS-DB Server LPAR1 NET Oracle 8.1.7.4 TG4DB2 DB2 LPAR2 NET Integraph TG4DB2 DB2 LPAR3 NET

  5. The project – Geomarketing • A sample request • Show me all customers who live in the city of Fürstenfeldbruck which do not have any shares • The result is a Map of the city Fürstenfeldbruck where you can see the areas of the city combined with the result set of the request

  6. The project – Geomarketing

  7. The project – Geomarketing • Project plan • Suppliers had to build a prototype • The customer evaluated the prototypes • Performance was a key success factor • Performance also was the main challenge • DB2 had to be accessed with only little ressource consumtion • DB2 Utilities should not be interfered • Sometimes a great number of rows is transferred • Distributed Queries(Oracle/DB2) had to be used

  8. The Project – Geomarketing • The way how Transparent Gateway for DB2(TG4DB2) works had to be understood • Features which speed up Bulk Transfers with TG4DB2 had to be used • Efficient queries to access DB2 had to be developed • That means the DB2 Optimizer had to be known • The DB2 Locking behaviour had to be understood

  9. Transparent Gateway for DB2 How it works

  10. Problem areas • SQL Dialects • DB2 Locking Model • Query Performance • Transparency

  11. How does a Gateway work ? Oracle DB2 for z/OS Step 1 Step 2 Select Max(Salary) from tab1 Where Name= ‘MAIER‘ Select Max(Salary) from tab1@DB2 Where Name= ‘MAIER‘ Datatransfer Step 3 Step 4

  12. How does a Gateway work ? Oracle DB2 for z/OS Step 1 Step 2 Select Name,age from tab1 Where Value(Age,18)= 18 Select Name,age from tab1@DB2 Where NVL(Age,18)= 18 Datatransfer Step 3 Step 4

  13. How does a Gateway work ? Oracle DB2 for z/OS Step 2 Step 1 Select * from tab1 Select * from tab1@DB2 Where Soundex(Column1)= ‘Scott‘ Datatransfer Step 3 Select * from temptab Where Soundex(Column1)= ‘Scott‘ Step 4

  14. Gateway Performance • Compatible Functionalities • Good performance • Translated Functionalities • Gateway Pre-Processing • Good Performance • Compensated Functionalities • Gateway Post-Processing • Performance implications

  15. Gateway Performance • Compatible functions • AVG • CONCAT • COUNT (*) only • COUNT(DISTINCT expression) • MAX • MIN • SUM • .... • Translated functions • NVL – Value • .....

  16. How can Post-Processing be discovered • Bad response time (SQL Trace) • Gateway Trace • Explain Plan • UTLXPLAN • UTLXPLS • PLAN_TABLE

  17. Postprocessing - sample explain plan for select b.ename, b.empno from tniewel.emp@epg1 a, scott.emp@epg1 b where a.empno=b.empno and soundex(a.ename)='MAIER' /

  18. Postprocessing - sample ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 40 | 1 | | | | |* 1 | HASH JOIN | | 1 | 40 | 1 | | | | |* 2 | FILTER | | | | | | | | | 3 | REMOTE | | | | |E.,OM |SERIAL| | | 4 | REMOTE | | 1 | 20 | |E.,OM |SERIAL| | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("A2"."EMPNO"="A1"."EMPNO") 2 - filter(SOUNDEX("A2"."ENAME")='MAIER') Slave SQL Information (identified by operation id): --------------------------------------------------- 3 - SELECT "EMPNO", "ENAME" FROM "TNIEWEL"."EMP" 4 - SELECT "EMPNO", "ENAME" FROM "SCOTT"."EMP" Note: cpu costing is off

  19. Without Postprocessing explain plan for select b.ename, b.empno from tniewel.emp@epg1 a, scott.emp@epg1 b where a.empno=b.empno and a.ename='MAIER' /

  20. Without Postprocessing ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | | | | | 1 | REMOTE | | | | |E.,OM |SERIAL| | ----------------------------------------------------------------------------------------------- Slave SQL Information (identified by operation id): --------------------------------------------------- 1 - SELECT A1."ENAME", A1."EMPNO" FROM "TNIEWEL"."EMP" A2, "SCOTT"."EMP" A1 WHERE A2."EMP NO"=A1."EMPNO" AND A2."ENAME"='MAIER' Note: rule based optimization

  21. Distributed Joins – how can „splitted“ Queries be prevented explain plan for select a.ename from tniewel.emp a, tniewel.emp@epg1 b, scott.emp@epg1 c where a.ename=b.ename and b.ename=c.ename;

  22. Distributed Joins – how can „splitted“ Queries be prevented ------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib | ------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 21 | 3 | | | | |* 1 | HASH JOIN | | 1 | 21 | 3 | | | | | 2 | MERGE JOIN CARTESIAN| | 1 | 14 | 2 | | | | | 3 | REMOTE | | 1 | 7 | |E.,OM |SERIAL| | | 4 | BUFFER SORT | | 82 | 574 | 2 | | | | | 5 | TABLE ACCESS FULL | EMP | 82 | 574 | 2 | | | | | 6 | REMOTE | | 1 | 7 | |E.,OM |SERIAL| | ------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("A"."ENAME"="B"."ENAME" AND "B"."ENAME"="C"."ENAME") Slave SQL Information (identified by operation id): --------------------------------------------------- 3 - SELECT "ENAME" FROM "SCOTT"."EMP" 6 - SELECT "ENAME" FROM "TNIEWEL"."EMP"

  23. Distributed Joins – how can „splitted“ Queries be prevented explain plan for select a.ename from tniewel.emp a where a.ename = (select b.ename from tniewel.emp@epg1 b, scott.emp@epg1 c where b.ename=c.ename);

  24. Distributed Joins – how can „splitted“ Queries be prevented ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7 | 2 | | | | |* 1 | TABLE ACCESS FULL | EMP | 1 | 7 | 2 | | | | | 2 | REMOTE | | | | |E.,OM |SERIAL| | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("A"."ENAME"= (SELECT "A2"."ENAME" FROM "SCOTT"."EMP"@EPG1.DE.ORACLE.COM "A1")) Slave SQL Information (identified by operation id): --------------------------------------------------- 2 - SELECT A2."ENAME" FROM "TNIEWEL"."EMP" A2, "SCOTT"."EMP" A1 WHERE A2."ENAME"=A1."ENAM E" Note: cpu costing is off 22 Zeilen ausgewõhlt.

  25. Distributed Joins – how can „splitted“ Queries be prevented • Create views in DB2 – Be careful with View Materialization • View Merge vs. View Materialization • View Materialization is performed when a view is complex – e.g. when sorts need to be performed • Explain of the View • Use Filters

  26. Traces - Gateway Trace • Gateway Parameters • Tracelevel=4 • Dedicated Trace Gateway makes live easier

  27. Traces – Gateway Trace Gateway Trace //////////////////////////////////////////////////////////////////////////// Oracle for OS/390 Diagnostic Trace -- 2003/01/15 07:19:07.357 // System MVS08 Subsystem EPO3 Service EPG1 Session 16 PID 00020010////////////////////////////////////////////////////////////////////////////*** hoapars SQL : SELECT "NAME" FROM "SYSIBM"."SYSTABLES"fdsapi:SQL statement follows. Length=39SELECT "NAME" FROM "SYSIBM"."SYSTABLES"*** hoapars SQL : SELECT "EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO" FROM "TNIEWEL"."EMP"fdsapi:SQL statement follows. Length=95SELECT "EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO" FROM "TNIEWEL"."EMP"

  28. SQL Trace • Prerequisite: timed_statistics=true; • user action - Connect • Select sid, serial#, osuser, username from V$session • 1. SQL> select sid, serial#, osuser, username from v$session; • SID SERIAL# OSUSER USERNAME • --------- --------- -------------------------- ---------------------- • .... • 7 38 SYSTEM • 9 70 TNIEWEL2 • exec sys.dbms_system.set_sql_trace_in_session(9, 70,TRUE) user action – Work with Application • exec sys.dbms_system.set_sql_trace_in_session(9, 70,FALSE) • Format Trace Files with TKPROF

  29. Gateway Parameters • HS_RPC_FETCH_SIZE=40000 • DB2_STATS=YES • IDLE_TIMEOUT

  30. Important – Gateway Parameters

  31. Parameter DB2STATS=YES • DB2 catalog Statistics are used influence the Execution plan • Table Cardinality • Key Column Cardinality • What are the results of that setting • Join Sequence may change • Small remote-DB2-Tables are completely transferred

  32. Parameter DB2STATS=YES • Sample Plan_table output • Sysibm.Systables, Sysibm.Syscolumns (Only Key Columns) • Column: Cardf • Select * from tniewel.emp@epg1 ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10000 | 566K| | | | | | 1 | REMOTE | | 10000 | 566K| |E.,OM |SERIAL| | ----------------------------------------------------------------------------------------------- Slave SQL Information (identified by operation id): --------------------------------------------------- 1 - SELECT "EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO" FROM "TNIE WEL"."EMP"

  33. DB2 Locking • IRLM (Internal Ressource Lock Manager) • Row Locks possible - Page Locks were used because of performance reasons • Lock Escalation

  34. DB2 Locking DB2 Locking is behaviour is determined by the Isolation Level of the Gateway Plan CS – Cursor Stability RR – Repeatable Read RS – Read StabilityUR – Uncommitted Read

  35. Uncommitted Read Read Stability Cursor Stability Repeatable Read share locks Locked Locked Locked Locked DB2 Locking Nothing Qualifying Row All Rows Row accessed Read

  36. DB2 Locking - Problems • Problem at the customer site: • The Gateway holds Locks ! Our Batches Abend with SQLCODE –911 • Is this really a gateway problem ?

  37. DB2 Locking Duration of Page and Row Locks: If a page or row is locked, DB2 acquires the lock only when it is needed. When the lock is released depends on many factors, but it is rarely held beyond the next commit point. ..... Commit Work as Soon as Is Practical: To avoid unnecessary lock contentions, issue a COMMIT statement as soon as possible after reaching a point of consistency, even in read-only applications.To prevent unsuccessful SQL statements (such as PREPARE) from holding locks, issue a ROLLBACK statement after a failure. Quelle: DB2 Version 7 Administration Guide

  38. DB2 - SQL – Tuning Hints • Use Functions on columns in where condition which are also available in DB2 • Predicates in DB2 • Indexable • Index can be used • Stage 1 • Predicates, which are not of Type „Stage 1“ are evaluated by the RDS(Relational Data System) which is more expensive

  39. Predicates – Source DB2 Administration Guide

  40. Predicates – Source DB2 Administration Guide

  41. Predicates – Source DB2 Administration Guide

  42. Predicates – Source DB2 Administration Guide

  43. Lessons we have learned

  44. Lessons we have learned • DB2 Locking • Commit´s – also after Read operations • If Consistency doesn´t matter • Bind TG4DB2 Plan with Isolation Level UR (TG4DRDA (DRDA_ISOLATION_LEVEL=NC) • Hanging Sessions • Alter Session Close Database Link xxx • Should be executed when a logical application unit is finished.

  45. Lessons we have learned • Try to make bulk transfers „small“ • use as much filters as possible on remote DB • The split of distributed joins (Oracle / DB2) sometimes is more efficient

  46. Lessons we have learned • Oracle functions in SQL can produce a lot of overhead • Sample: • Select a.*,b.* from testtn1@epg1 a, testtn2@epg1 b where • a.c3 between to_char(sysdate-1,'YYYY-MM-DD')||'-00.00.00.000000' • and to_char(sysdate,'YYYY-MM-DD')||'-00.00.00.000000' and • a.c2=b.c2 • The use of Bind variables improves the performance

  47. More... • Gateway Passthrough • Allows input of native DB2 Syntax without Gateway Pre- and Postprocessing • Call of DB2 Stored Procedures • Allows the use of static SQL • DB2 Stored Procedure result sets are not supported

  48. Passthrough DECLARE CRS binary_integer; RET binary_integer; VAL VARCHAR2(10);AGE Number BEGIN CRS:=DBMS_HS_PASSTHROUGH.OPEN_CURSOR@gtwlink; DBMS_HS_PASSTHROUGH.PARSE@gtwlink(CRS,’SELECT NAME, AGE FROM PT_TABLE’); BEGIN RET:=0; WHILE (TRUE) LOOP RET:=DBMS_HS_PASSTHROUGH.FETCH_ROW@gtwlink (CRS,FALSE); DBMS_HS_PASSTHROUGH.GET_VALUES@gtwlink (CRS,1,VAL); DBMS_HS_PASSTHROUGH.GET_VALUES@gtwlink (CRS,2,AGE); INSERT INTO PT_TABLE_LOCAL VALUES (VAL); END LOOP; EXCEPTION WHEN NO_DATA_FOUND THEN BEGIN DBMS_OUTPUT.PUT_LINE(’END OF FETCH’); DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@gtwlink(CRS) ; END; END; ......

  49. DB2 Stored Procedures Can be called from PL/SQL DECLARE INPUT VARCHAR2(15); RESULT NUMBER(8,2); BEGIN INPUT := ‘JOHN SMYTHE’; SYSPROC.REVISE_SALARY@DB2(INPUT, RESULT); UPDATE EMP SET SAL = RESULT WHERE ENAME = INPUT; END; ....

More Related