1 SQL Best Coding Practice in PeopleTools 7.x David Kurtz Go-Faster Consultancy Ltd.

Slides:



Advertisements
Similar presentations
1 TITLE OF THE ARTICLE Author (Institution) Co-Author (Institution) .
Advertisements

Oracle 10g & 11g for Dev Virtual Columns DML error logging
ER Modeling Case Studies
1 February 8 th, 2006 February 8 th, Benefits of EF Benefits of EF Faster payment on electronic claims. Electronic transactions.
Slide 1 Insert your own content. Slide 2 Insert your own content.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 3.1 Chapter 3.
Quest ion 1? A.) answer B.) answer C.) correct answerD.) answer L C.) correct answer F.
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
The creation of "Yaolan.com" A Site for Pre-natal and Parenting Education in Chinese by James Caldwell DAE Interactive Marketing a Web Connection Company.
Introduction to C Programming
12 Copyright © 2005, Oracle. All rights reserved. Query Rewrite.
Using the Set Operators
  Refresher 5(2x - 3) Solving Equations 2x + 5 = x + 10 x + 5 = 10
Successful Job Interviews
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Teacher Name Class / Subject Date A:B: Write an answer here #1 Write your question Here C:D: Write an answer here.
Addition Facts
CS4026 Formal Models of Computation Running Haskell Programs – power.
Empty Box Problems Subtraction = 3 If you start on 6 and jump back 3 spaces you land on
1 Beyond 20/20 Web Data Server ESDS International MIMAS, University of Manchester.
HR7.5 Department Security Tree Tuning
Sorting Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Construct a query to sort a results set in ascending.
1 SQL Best Coding Practice in PeopleTools 7.x David Kurtz Go-Faster Consultancy Ltd.
Report Card P Only 4 files are exported in SAMS, but there are at least 7 tables could be exported in WebSAMS. Report Card P contains 4 functions: Extract,
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
1 nVision Performance Tuning David Kurtz Go-Faster Consultancy Ltd.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Displaying Data from Multiple Tables
Go-Faster Consultancy Ltd.1 Experiences of Global Temporary Tables in Oracle 8.1 David Kurtz Go-Faster Consultancy Ltd.
State of Connecticut Core-CT Project Query 8 hrs Updated 6/06/2006.
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
O X Click on Number next to person for a question.
© S Haughton more than 3?
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
1 Directed Depth First Search Adjacency Lists A: F G B: A H C: A D D: C F E: C D G F: E: G: : H: B: I: H: F A B C G D E H I.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Margins.
UKOUG DBMS SIG www.go-faster.co.uk1 Materialized Views: Simple Replication? David Kurtz Go-Faster Consultancy Ltd.
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Limits (Algebraic) Calculus Fall, What can we do with limits?
Properties of Exponents
Addition 1’s to 20.
25 seconds left…...
1 ORACLE DATABASE Salim Phone: YM: talim_bansal.
44238: Dynamic Web-site Development Working with a Remote Database Ian Perry Room:C48 Extension:7287
Graphing AWR Data in Excel
Global Payroll Performance Optimisation - I David Kurtz Go-Faster Consultancy Ltd.
Test B, 100 Subtraction Facts
Click your mouse to move the card ahead! Work with a buddy using two Abacuses. First click and follow along using your abacus. After each click talk about.
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
Bottoms Up Factoring. Start with the X-box 3-9 Product Sum
O X Click on Number next to person for a question.
Go-Faster Consultancy Ltd.1 Single Table Clusters, an alternative to partitioning? David Kurtz Go-Faster Consultancy Ltd.
Emissions to date as a % of 09/10 emissions (minus 10%) Percentage of 09/10 emissions (minus 10%) not yet used Pan Government emissions PAN GOVERNMENT.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Unicode Oddity. from a Unicode PeopleSoft Database SELECT emplid, name, LENGTH(name), BLENGTH(name) FROMps_personal_data WHEREemplid = '007’ ; EMPLID.
June 7, 2005EIS – Developer –Meta-Data PeopleSoft Meta-Data & Oracle Data Dictionary EIS Developer Meeting June 7, 2005.
Top Tips for Better TSQL Stored Procedures
Developing a Model-View-Controller Component for Joomla Part 3
Engine Part ID Part 1.
Engine Part ID Part 2.
Engine Part ID Part 2.
Presentation transcript:

1 SQL Best Coding Practice in PeopleTools 7.x David Kurtz Go-Faster Consultancy Ltd.

2 Who are you? Familiar with SQL not necessarily the DBA Might be –Application developer –Team Leader

3 So Where is all the SQL? Views Scrollxxx() PeopleCode SQLExec() PeopleCode Mass Change Application Engine PS/Query / Crystal SQR Stored Statements

4 Views

5 Scrollxxx() PeopleCode

6 SQLExec() PeopleCode

7 Mass Change

8 Application Engine

9 PS/Query / Crystal

10 SQR

11 Stored Statements

12 Simplicity As simple as possible As complicated as necessary Data Model Avoid excessive I/O

13 SQL Coding Standard Implicit Type Conversion Sorts Indexes Sub-queries

14 Coding Standards Be explicit –Make it readable Indent sub-queries and brackets –Use table aliases Lower parse time Less unexpected results without error messages –Avoid implicit type conversion –Avoid possible Y2K issue Explicitly specify Y2K compliant date formats

15 Readability CREATE TABLE PS_GEN_JOB_TBL(...) AS SELECT DISTINCT... FROM PS_PERSONAL_DATA A, PS_JOB B, PS_PERS_NID ND, PS_NID_TYPE_TBL NDT WHERE A.EMPLID=B.EMPLID ANDA.EMPLID=ND.EMPLID ANDB.EMPLID=ND.EMPLID ANDND.NATIONAL_ID_TYPE=NDT.NATIONAL_ID_TYPE AND (B.EFFDT>=%CURRENTDATEIN OR (B.EFFDT=(SELECTMAX(B2.EFFDT) FROM PS_JOB B2 WHERE B2.EMPLID=B.EMPLID ANDB2.EMPL_RCD#=B.EMPL_RCD# AND B2.EFFDT<=%CURRENTDATEIN) ANDB.EFFSEQ=(SELECTMAX(B3.EFFSEQ) FROM PS_JOB B3 WHERE B3.EMPLID=B.EMPLID AND B3.EMPL_RCD#=B.EMPL_RCD# ANDB3.EFFDT=B.EFFDT)))

16 Minimum table aliases SELECT COUNT(*) FROM PS_JOB B WHERE (EFFDT=(SELECTMAX(B1.EFFDT) FROM PS_JOB B1 WHERE B.EMPLID=EMPLID ANDB.EMPL_RCD#=EMPL_RCD# AND B.EFFDT<=%CURRENTDATEIN) ANDEFFSEQ=(SELECT MAX(B2.EFFSEQ) FROM PS_JOB B2 WHERE B.EMPLID=EMPLID AND B.EMPL_RCD#=EMPL_RCD# ANDB.EFFDT=EFFDT))

17 Maximum table aliases SELECT COUNT(*) FROM PS_JOB B WHERE (B.EFFDT=(SELECTMAX(B1.EFFDT) FROM PS_JOB B1 WHERE B1.EMPLID=B.EMPLID ANDB1.EMPL_RCD#=B.EMPL_RCD# AND B1.EFFDT<=%CURRENTDATEIN) ANDB.EFFSEQ=(SELECT MAX(B2.EFFSEQ) FROM PS_JOB B2 WHERE B2.EMPLID=B.EMPLID AND B2.EMPL_RCD#=B.EMPL_RCD# ANDB2.EFFDT=B.EFFDT))

18 Wrong table alias SELECT COUNT(*) FROM PS_JOB B WHERE (EFFDT=(SELECTMAX(B1.EFFDT) FROM PS_JOB B1 WHERE B.EMPLID=EMPLID ANDB.EMPL_RCD#=EMPL_RCD# AND B.EFFDT<=%CURRENTDATEIN) ANDEFFSEQ=(SELECT MAX(B2.EFFSEQ) FROM PS_JOB B2 WHERE B2.EMPLID=EMPLID AND B2.EMPL_RCD#=EMPL_RCD# ANDB2.EFFDT=EFFDT))

19 Implicit Type Conversion SELECT * FROM PS_JOB WHERE EMPLID=8001 SELECT * FROM PS_JOB WHERE EMPLID=8001

20 Implicit Type Conversion SELECT * FROM PS_JOB WHERE EMPLID=8001 TABLE ACCESS (FULL) OF 'PS_JOB why did this not use the index? SELECT * FROM PS_JOB WHERE EMPLID=8001 INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE)

21 Implicit Type Conversion SELECT * FROM PS_JOB WHERE EMPLID=8001 TABLE ACCESS (FULL) OF 'PS_JOB why did this not use the index? SELECT * FROM PS_JOB WHERE TO_NUMBER(EMPLID)=8001 SELECT * FROM PS_JOB WHERE EMPLID=8001 INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE)

22 Sorts Updating indexed columns Distinct Order by Group by Union -v- Union All

23 Indexes >~ 200 rows <~ 10% –Very rough guidelines –Avoid updating indexed columns –Sometimes, even very small tables, that fit in a single block can benefit from a suitable index.

24 Distinct Sorts whole select list Can drive the join order of the tables Avoid distinct & order by –Order one way for the distinct –Order another way for the order by

25 Distinct SELECTDISTINCT A,B,C,D FROMtable ORDER BY A,B,C Order by clause is necessary –Update Mar 2009 – Up to Oracle 9i,DISTINCT and GROUP BY used a sort operation, so on non-partitioned tables the rows were returned in that order. In Oracle 10g these commands use a hash operation. If you want the rows in a particular order you should say so!

26 Distinct Instead of SELECTDISTINCT A,B,C,D FROMtable ORDER BY A,C,B Do not rely on this SELECT DISTINCT A,C,B, D FROMtable

27 Group by Instead of SELECTA,B,C, SUM(D) FROMtable GROUP BY A,B,C ORDER BY A,C,B Do not rely on this SELECT A,C,B, SUM(D) FROMtable GROUP BY A,C,B

28 But if hash operation disabled Instead of SELECTA,B,C, SUM(D) FROMtable GROUP BY A,B,C ORDER BY A,C,B Match the group and order clauses SELECT A,C,B, SUM(D) FROMtable GROUP BY A,C,B ORDER A,C,B

29 Union -v- Union All Union –Each query is distinct, and so is sorted Hash operation possible in Oracle 10g –Duplicates are eliminated Union All –One query followed by the next

30 Union -v- Union All SELECT1 FROMdual UNION SELECT 1 FROM dual Returns Dummy SELECT 1 FROMdual UNION ALL SELECT1 FROMdual Returns Dummy

31 Union -v- Union All SELECT2 FROMdual UNION SELECT 1 FROM dual Returns Dummy SELECT 2 FROMdual UNION ALL SELECT1 FROMdual Returns Dummy

32 Disabling Indexes Functions on columns Index disabled –TO_CHAR(column,DD-MM-YYYY) = :bind Index enabled –column = TO_DATE(:bind, DD-MM-YYYY) Oracle syntax, generic principle

33 Use all indexed columns Specify all indexed columns –Cannot exact scan column unless exact scan all previous columns

34 Use all indexed columns SELECT… FROMPS_JOB B WHEREEMPLID = :1 ANDEFFSEQ = ( SELECTMAX(EFFSEQ) FROM PS_JOB B1 WHEREB1.EMPLID = B.EMPLID ANDB1.EFFDT = B.EFFDT) SELECT… FROMPS_JOB B WHEREEMPLID = :1 ANDEFFDT = ( SELECTMAX(EFFSEQ) FROM PS_JOB B1 WHEREB1.EMPLID = B.EMPLID ANDB1.EMPL_RCD# = B.EMPL_RCD# ANDB1.EFFDT = B.EFFDT)

35 High Water Marks (Oracle) Oracle specific Delete -v- Truncate DELETE FROM table; TRUNCATE TABLE table; –Full Scans - HWM

36 Sub-queries Correlated –executed once per parent row –(because PeopleSoft recommend disabling _UNNEST_SUBQUERY from Oracle 9i). Not Correlated –executed once in advance

37 Sub-queries –Correlated DELETE FROM table1 t1 WHERE EXISTS( SELECTx FROMtable2 t2 WHERE t1.keycolumn = t2.keycolumn) –Non-Correlated DELETE FROM table1 t1 WHERE t1.keycolumn IN( SELECT t2.keycolumn FROM table2 t2)

38 Sub-queries (Oracle) Oracle specific DELETE FROM table1 t1 WHERE (t1.keycolumn1, t1.keycolumn2) IN( SELECT t2.keycolumn1, t2.keycolumn2 FROM table2 t2)

39 ROWID (Oracle) Oracle specific physical address of row

40 Sub-queries (Oracle) Oracle specific DELETE FROM table1 t1 WHERE t1.rowid IN( SELECTt1b.rowid FROM table1 t1b, table2 t2 WHERE t1b.keycolumn1 = t2.keycolumn2 ANDt1b.keycoulmn2 = t2.keycolumn2)

41 Order of From clause (Oracle) Oracle specific Rule Based Optimiser –backwards Cost Based Optimiser –doesnt matter CBO + Ordered Hint –Forwards –But use LEADING hint from 10g

42 Summary Lots of places to write SQL Code should be –efficient –simple –readable –explicit

43 SQL Best Coding Practice in PeopleTools 7.x David Kurtz Go-Faster Consultancy Ltd.