03 Coding Convention - SQL

download 03 Coding Convention - SQL

of 37

description

bhbhhbsadiias sjhdahhdaw hdasjhdhjbS jasbdjsauwjh shhdjkhaudswjhda djhshduawu dhushxh8uwioqui sjhjdha zhnn shhau uuwyai auhww7yw uwyduhasuhd ahduasdhuas dhszj chasuhduausyduuaw88syyG xxgzHG

Transcript of 03 Coding Convention - SQL

  • 1/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    3. SQL Coding Convention

    1. Coding Styles

    The SQL description style should comply with the following rules in the interest of maintainability.

    a. Use upper case capital letters

    All description should be written in upper case capital letters including database objects such as the table name, field name, view name and SQL functions.

    However, use lower case for variables used in embedded SQL such as bind variables.

    * Any field names must not be used as variable names

    b. Insert carriage return appropriately to divide lines.

    When listing fields, use separate lines for each field and indent appropriately.

    Use separate lines for each formula for a WHERE clause

    Use separate lines for each table in a FROM clause

    Use separate lines for each assignment expression for an UPDATE clause.

    However, when there are many lines and the above rules make the program difficult to read, a line saving style can be used.

    c. Define an alias for each table

    However, it is not always necessary in a SQL statement with a single table.

    The alias should be defined in the FROM clause. The first table should be called T1 and followed by T2, T3, T4, .etc..

    If there are any abbreviation already determined by each application team, those name may be used.

  • 2/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    d. The field names should be described as table_name.field_name format.

    However, it is not always necessary in a SQL statement with a single table.

    e. Confirm the execution plan to determine the order of the table association.

    f. Reserved words for nodes in DML statements should be aligned to the right.

    Example)SELECT T1.LASTNAME, T2.NAME, MAX(T3.SALARY) BEST_SALARY FROM EMPLOYEE T1, COMPANY T2, SALHISTORY T3 WHERE T1.COMPANYID = T2.COMPANYID AND T1.EMPID = T3.EMPID AND T1.HIREDATE > ADD_MONTHS(SYSDATE, -60).....;

    UPDATE EMPLOYEE SET HIREDATE = SYSDATE, TERMDATE = NULL WHERE DEPTID = 105;

    INSERT INTO EMPLOYEE (EMPID,.....) VALUES (105,....);

  • 3/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    2. Coding Rules

    2.1. Rules on Inquiry Processing

    a. Obtaining the execution plan

    Always obtain and evaluate the execution plan (EXPLAIN) for all SQL used.

    Note that the access path may drastically change by the number of rows in a table if the Optimizer is configured on a cost basis.

    b. Prohibition on use of sub-queries

    In principle, sub-queries should be replaced by association operations as much as possible. They may only be used when the sub-query returns only a few rows.

    - In-line view

    A sub-query which describes a SELECT clause within a FROM clause.

    In principle, this use is prohibited ; replace with an association.

    - Nested query

    A sub-query in a WHERE clause. A nested sub-query is prohibited.

    - Correlation sub-queries

    A sub-query which queries fields on a table which is also queried by the sub-query's parent statement.

    In principle, this use is prohibited. Use only for tuning sub-queries.

    c. An ORDER BY and GROUP BY clause should not target any non-key fields.

    An ORDER BY and GROUP BY should be carried out on the key fields.

    When unavoidable, monitor the performance and request for index configuration if necessary.

    d. Prohibition of complex query syntax

    In principle, CONNECT BY, INTERSECT and MINUS should not be used and should be replaced by logics.

    When it is unavoidable, consult the database manager (= the DBA in each application team)

    e. Prohibition on use of SQL statements for complex conditional branching.

    * Pro*COBOL R9.2.0 does not support a CASE formula as an embedded SQL statement (supported by Pro*C/C++ R9.2.0)

  • 4/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    f. HAVING clause

    Use a WHERE clause for a selection operation where possible.

    Use HAVING only when specifying a selection condition against the result from a set operation such as BY.

    g. Prohibition on use of view association operations

    A view should not be associated with other views and tables. Configure a new view when the configuration of an existing view is insufficient.

    Also, the use of a view in a sub-query is prohibited.

    h. Prohibition of implicit type conversion

    Do not use an implicit type conversion for field value comparison and assignment operations ; always convert explicitly.

    Especially for the date type, a TO_DATE/TO_CHAR function should be used and specify and convert the date format explicitly.

    i. The usage of index from a WHERE clause

    Note that indexes are not used for the following cases.

    - When a function or arithmetic operator is used for the index field.

    WHERE TCFROM = TO_DATE('20030101', 'YYYYMMDD')

    WHERE TO_CHAR(TCFROM, 'YYYYMMDD') = '20030101'

    - Comparison using a NOT condition (!=)

    WHERE PARTSNUM != 0

    - When a NULL is specified for a search condition

    WHERE STATUS IS NULL

    - If anything else but a front concordance is specified in a part concordance search using a LIKE operator

    WHERE ADDRESS LIKE 'FUKU%'

    WHERE ADDRESS LIKE '%OKA'

    Obtain and valuate the execution plan because the usage of indexes changes by various conditions.

    j. Prohibition on use of SELECT *

    Always specify field names for the field list in a SELECT statement

  • 5/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    k. Restriction on the number of tables for an association

    The number of tables for an association operation should be limited to 3.

    Associating many tables may impact performance. Consider denormalization and use of the Materialized View.

    When it is considered that use of the Materialized View is necessary, consult the database managers.

    l. Range query using a BETWEEN clause.

    Use BETWEEN when specifying a search condition (.e. equal and more, equal and less, and less), and it is implicitly understood that there are

    an upper limit and lower limit, ,

    m. Optimize the path when associating multiple tables.

    In a SQL sentences which JOIN multiple tables using different fields for association and search conditions, and also if those conditions can be

    specified equally in a multiple JOIN, specify the condition on a table with less rows.

    n. External association

    Pro*C/C++ R9.2.0 and Pro*COBOL R9.2.0 do not support ANSI association syntax as an embedded SQL statement.

    o. Restriction on use of hints

    In principle, hints should not be used.

    When it is considered that the use of hints is necessary, consult the database managers.

    p. Restriction on use of ROWID

    A ROWID para-field should only be used when there is a problem in performance.

    Also, descriptions which are depending on the ROWID internal format is prohibited.

    q. Use of SQL cache

    The following are the rules to re-use SQL statements which are cached in the shared buffer.

    - Strictly follow the coding rules.

    - Avoid using dynamic SQL. Also avoid SQL statement generation by linking character arrays.

    Use PreparedStatement for Java (JDBC)

    Use bind variables for an embedded SQL.

  • 6/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    - Frequently used SQL statements should be made into views.

  • 7/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    r. Use of the ANSI SQL:1999 association syntax

    * Pro*C/C++ R9.2.0 and Pro*COBOL R9.2.0 do not support the ANSI combined syntax in embedded SQL statements.

  • 8/37Phase Project Name TMAP Standard Page

    Block Name TMAP Development Standard Function Name 2.2 Developer Guide Created 3/9/2006 By Teguh

    Document Name Title 2.2.4.3 Coding Convention - SQL Updated 7/3/2007 By Dani

    2.2. Rules on Update Processing

    a. Acquisition of an execution plan is essential

    Obtain the execution plan and carry out the tuning on sub-queries in the INSERT clause and UPDATE clause as well as the SELECT clause.

    b. Field specification in an INSERT clause

    Always specify the target fields in INSERT clauses. Avoid using SELECT * FROM in sub-queries and specify the field names.

    c. Deleting entire table

    Use a TRUNCATE clause when deleting all rows in a table.

    d. Updatable ResultSet should not be used (JDBC).

    Always issue a SQL statement (INSERT/UPDATE/DELETE) for a ResultSet update for better performance.

    C.2.3. Transaction Rules

    a. Avoiding explicit locks

    It is desirable to regulate competition between applications in order to run processes within the ORACLE default lock mechanism.

    b. Strictly follow the lock order

    Reduce the possibility of a deadlock by establishing a rule for the order to lock tables.

    However, note that a lock is activated when the table is accessed rather than when it is specified.

    c. NOWAIT for locks

    Always specify the NOWAIT option when an explicit lock is used.

    d. Use of table locks

    Table locks should not be used unless most of the data in a table is subject to an update.

  • PL/SQL & SQL Tips

    *** 1. Specify column name in an insert.

    INSERT INTO emp VALUES(1, 'abc'); ---- NG!INSERT INTO emp(id, nm) VALUES(1, 'abc'); ---- OK!

    *** 2. Code "ROLLBACK" at first in exception.

    EXCEPTION EXCEPTION WHEN OTHERS THEN WHEN OTHERS THEN Pk_Logger.writeDetailToDB(..... ->

    Pk_Logger.writeDetailToDB(..... END; END;

    * 3. Do not specify columns, when using "EXISTS" condition.It's enough by fixed value.

    SELECT e.id, e.name SELECT e.id, e.name FROM emp e FROM emp e WHERE EXISTS -> WHERE EXISTS

    FROM dept d FROM dept d WHERE e.dept_cd = d.dept_cd); WHERE e.dept_cd = d.dept_cd);

    * 4. Let's use CASE. (new function of Oracle9)

    IF rec.ID = 'A' product_code := 10;ELSIF rec.ID = 'B' product_code := 20;ELSIF rec.ID = 'C' product_code := 30; -> END CASE;ELSE OR product_code := 40; product_code :=END IF;

    ROLLBACK;

    ROLLBACK;

    (SELECT d.dept_cd -- no need (SELECT 'x'

    CASE rec.ID WHEN 'A' THEN product_code := 10; WHEN 'B' THEN product_code := 20; WHEN 'C' THEN product_code := 30; ELSE product_code := 40;

    CASE rec.ID WHEN 'A' THEN 10 WHEN 'B' THEN 20 WHEN 'C' THEN 30

    Rank

  • END; ELSE 40

  • *** 5. Use Index

    ---- OK!(Uses index)

    ---- OK!(Uses index)

  • 7. Try to avoid wildcard characters at the beginning of a word while searching using the LIKE keyword.

  • SELECT id, name FROM emp WHERE dept like '%ASC';SELECT id, name FROM emp WHERE dept like 'T%C'; ---- OK!(Uses index seek)

    8. Use 'Derived tables' wherever possible, as they perform better.

    SELECT MIN(salary) SELECT MIN(salary)FROM emp FROMWHERE id IN (( -> SELECT TOP 10 salarySELECT TOP 10 id FROM empFROM emp ORDER BY salary DESCORDER BY salary DESC ) AS A)

    9. Use Temporary Tables to to improve the performance of queries performing complex summarization or comparisonA GLOBAL TEMPORARY table has a persistent definition but data is not persistent and the global temporary table generates no redo or rollback information.

    for (j=0; j< arList.size(); j++) { if ( == ) { This kind of processing will have performance problem if TB_R_GL have bulk of data.

    INSERT INTO TB_R_GL -> Each Insert Transaction will have an overhead specially if there is already a lot(col1, col2col[n]) VALUES of data or extents, thus performance might be slower than before.(val1, decode(val2, "Yes", "0", "No", "1", val2), val[n]);

    }}

    create global temporary table TB_T_GL (col1 varchar2(20), This is how to create global temporary table.col2 number (2,0), -> The on commit preserve rows clause tells the SQL engine that when a transaction is committed the table should be cleared but not drop.

    col[n] varchar2(50))on commit preserve rows;

    This is a sample way of how to populate temp. tables. If you notice, in the examplefor (j=0; j< arList.size(); j++) { above we use the actual TB_R_GL tables. But since this transaction table is a growing table, there is a possibility that time will come wherein processing on if ( == ) { -> this actual table would be slower than it was before. This is because of the growing data.

    INSERT INTO TB_T_GL(col1, col2col[n]) VALUES On the other hand, if we use temporary table, we can put only the data we really need to

    ---- NG!(tendency to use table/index scan )

    Note : Text in BLUE font is the derived table

  • (val1, decode(val2, "Yes", "0", "No", "1", val2), val[n]); process minus the burden of other data that we dont need. We can also perform other needed data manipulation or computation before inserting it in the actual table.

  • }}

    INSERT INTO TB_R_GL (col1, col2 col[n]) -> Once we are done with the other needed process, we can then transfer the final outputSELECT (col1, col2 col[n]) from TB_T_GL from temp. table to the actual table using the Bulk Insert.

    10. Using Hints to Change Execution Plans

    With hints one can influence the optimizer. The usage of hints (with exception of the RULE-hint) causes Oracle to use the Cost Based optimizer.Optimizer HINT is usually used in those rare cases where the optimizer makes an incorrect decision about the execution plan; or there is a reasonthat altering the statistics of execution plan is preferred or needed.(Note : This is usually used as a last resort only )

    The following syntax is used for hints: An example using the commonly used INDEX hint, forcing execution plan to use index.

    select /*+ HINT */ namefrom emp from empwhere id =1; where id =1;

    Where HINT is replaced by the hint text.When the syntax of the hint text is incorrect, the hint text is ignored and will not be used.There are a lot Oracle Hint Text, some of which are documented, while others are not. You can obtain commonly used hint text from Oracle documentation.For those non-documented hints, you may find them through the internet.

    11. Avoid using joins that requires the DISTINCT qualifier on the SELECT list in queries

    FROM TB_R_AR_H ar,TB_R_CUST_INV_H inv DISTINCT means that results are generated and then sorted

    WHERE ar.doc_no = inv.doc_no and filter out duplicate values.

    SELECT DISTINCT ar.acc_period, ar.doc_no, ar.post_dtFROM TB_R_AR_H ar ---- OK!

    EXISTS makes the query faster because when the subquery has been satisfied once, SELECT 'X' FROM TB_R_CUST_INV_H inv there is no need to proceed further and the next matching row can be fetched. WHERE ar.doc_no = inv.doc_no )

    12. Avoid including a HAVING clause in SELECT statements.

    FROM TB_R_GL

    select /*+ index(t2 t2_i1) */ name

    SELECT DISTINCT ar.acc_period, ar.doc_no, ar.post_dt---- NG!(In this case, DISTINCT have more overhead)

    WHERE EXISTS (

    SELECT acct_cd, SUM(debit_amt), SUM(credit_amt) ---- NG!

  • GROUP BY acct_cd The HAVING clause filters selected rows only after all rows have been fetched.HAVING doc_no = 'doc123'

  • AND doc_type = 'IN'

    FROM TB_R_GL ---- OK!Using a WHERE clause helps reduce overheads like sorting, summing, etc.

    AND doc_type = 'IN'GROUP BY acct_cd

    SELECT header_idFROM TB_R_SAP_JOURNAL ---- OK!WHERE biz_scn_cd = 'OEM_EXP_ICS_RGR_GL' HAVING clauses should only be used when columns with summary operations AND post_sts = 'N' applied to them are restricted by the clause.

    13. Use NOT EXISTS instead of NOT IN whenever possible.

    SELECT id, nameFROM emp In this case, Oracle will perform full table scan on table 'emp'. For each record in 'emp', the subquery will be executed.

    Since the subquery does not have a 'where' clause, it will perform a full table scan for every record in the full table SELECT id FROM dept) scan of 'emp'.

    SELECT id, nameFROM emp e ---- OK!

    In NOT EXISTS, nested index scans will be used in the subquery for each row in the 'emp' table.SELECT 'X' FROM dept dWHERE d.id = e.id)

    14. Use multi-table insert if there is a need to insert data from one source to different target table.

    INSERT INTO emp (id, name, age) INSERT ALL INTO emp(id, name, age) Using multi-table Insert, we canSELECT id, name, age In conventional way, VALUES (id, name, age) -> use one SQL statement to InsertFROM tmpTable; we opt to use several INTO dept (id, mgr) VALUES (id, mgr) data in several tables from one

    -> Insert statement if we SELECT id, name, age, mgr source table. This will reduceINSERT INTO dept (id, mgr) need to Insert data in FROM tmpTable table scans.SELECT id, mgr more than 1 table.FROM tmpTable;

    SELECT acct_cd, SUM(debit_amt), SUM(credit_amt)

    WHERE doc_no = 'doc123'

    HAVING COUNT(1) = 3

    ---- NG! (NOT IN does not use a limiting condition.)

    WHERE id NOT IN (

    WHERE NOT EXISTS (

  • How to check SQL by PL/SQL Developer

    1. Open Explain Window.[File] - [New] - [Explain Plan Window]

    2. Paste SQL to Window

    How to check SQL by script

    Execute the following script in SQL*Plus

    DELETE FROM PLAN_TABLE; QUERY-------------------------------------------------------

    EXPLAIN PLAN FOR SELECT STATEMENT COST=select * from Z_TEST_TBL2 -> 2.1 TABLE ACCESS BY INDEX ROWID Z_TEST_TBL2 where DEPT_CD = 1 and NAME = 'SMITH' and AGE = 25;

    SELECT DECODE(ID,0,'',LPAD(' ',2*(LEVEL-1))||LEVEL||'.'||POSITION)|| ' '||OPERATION|| ' '||OPTIONS|| ' '||OBJECT_NODE|| ' '||OBJECT_NAME|| ' '||OBJECT_TYPE|| ' '||DECODE(ID,0,'COST='||POSITION) QUERYFROM PLAN_TABLECONNECT BY PRIOR ID = PARENT_IDSTART WITH ID = 0ORDER BY ID;

    DELETE FROM PLAN_TABLE; QUERY-------------------------------------------------------

    EXPLAIN PLAN FOR SELECT STATEMENT COST=

    3.1 INDEX RANGE SCAN IX_Z_TEST_TBL2 NON-UNIQUE

    Inex search

    CHECK SQL

  • select * from Z_TEST_TBL2->

    SELECT DECODE(ID,0,'',LPAD(' ',2*(LEVEL-1))||LEVEL||'.'||POSITION)|| ' '||OPERATION|| ' '||OPTIONS|| ' '||OBJECT_NODE|| ' '||OBJECT_NAME|| ' '||OBJECT_TYPE|| ' '||DECODE(ID,0,'COST='||POSITION) QUERYFROM PLAN_TABLECONNECT BY PRIOR ID = PARENT_IDSTART WITH ID = 0ORDER BY ID;

    * 6. Use ROWID

    SELECT empno, sal FROM EMP WHERE id = :id WHERE id = :id FOR UPDATE NOWAIT; FOR UPDATE NOWAIT;

    : -> :: :

    UPDATE EMP SET sal = sal * 1.2 UPDATE EMP SET sal = sal * 1.2 WHERE ID = id;

    *** 7. Use CURRENT OF

    DECLARE DECLARE CURSOR c1 IS SELECT empno, job, sal CURSOR c1 IS SELECT empno, job, sal FROM emp FOR UPDATE; FROM emp FOR UPDATE;

    : :: :

    BEGIN -> BEGIN OPEN c1; OPEN c1;LOOP LOOP FETCH c1 INTO rec ... FETCH c1 INTO rec ... ... ... UPDATE emp SET sal = new_sal UPDATE emp SET sal = new_sal WHERE empno = rec.empno;END LOOP; END LOOP;

    2.1 TABLE ACCESS FULL Z_TEST_TBL2 where DEPT_CD = 1 and NAME = 'SMITH' or AGE = 25;

    SELECT empno, sal, rowid FROM EMP

    WHERE rowid = :rowid;

    WHERE CURRENT OF c1;

    Table full scan!

    CHECK SQL

  • * 8. BULK BIND INSERT

    CREATE TABLE TEST_TBL( C1 NUMBER(4), C2 VARCHAR2(10))

    DECRARE DECRARE TYPE TYP_C1 IS TABLE OF TEST_TBL.C1%TYPE INDEX BY BINARY_INTEGER; TYPE TYP_C2 IS TABLE OF TEST_TBL.C2%TYPE INDEX BY BINARY_INTEGER; :

    : tbl_c1 TYP_C1; : tbl_c2 TYP_C2; :

    BEGIN BEGIN FOR i IN 1..10000 LOOP tbl_c1(i) := i; : tbl_c2(i) := 'name-' || TO_CHAR(i); -> : END LOOP; :

    -- NORMAL INSERT ----------------------- -- BULK BIND INSERT ---------------------- FOR i IN tbl_c1.FIRST..tbl_c1.LAST LOOP INSERT INTO TEST_TBL(c1, c2) VALUES(tbl_c1(i), tbl_c2(i)); INSERT INTO TEST_TBL(c1, c2) VALUES(tbl_c1(i), tbl_c2(i)); END LOOP;

    COMMIT; COMMIT;END; END;

    22 second 1 second

    * 9. MERGE

    Use "MERGE", when insert or update to table from other table.

    ex) By emp_no TOTAL_SALE is inserted or updated.

    TODAY_SALES MONTH_SALES MONTH_SALESEMP_NO SALES EMP_NO SALES EMP_NO SALES

    1 10,000 -> 1 210,000 -> 1 220,000

  • 4 30,000 3 340,000 3 340,0004 30,000
  • CURSOR LOOP MERGE CURSOR c1 IS SELECT * FROM TODAY_SALES;

    BEGIN -> FOR rec IN c1 LOOP BEGIN INSERT INTO MONTH_SALES VALUES (t.EMP_NO, t.SALES); (EMP_NO, SALES) VALUES(rec.EMP_NO, rec.SALES);

    EXCEPTION

    UPDATE MONTH_SALES SET SALES = SALES + rec.SALES WHERE EMP_NO = rec.EMP_NO; END; END LOOP;

    MERGE INTO MONTH_SALES m USING TODAY_SALES t ON (m.EMP_NO = t.EMP_NO) WHEN MATCHED THEN UPDATE SET m.SALES = m.SALES + t.SALES WHEN NOT MATCHED THEN INSERT (EMP_NO, SALES)

    WHEN DUP_VAL_ON_INDEX THEN

  • 25/37Phase MA Project Name TMT Application Maintenance Page

    Block Name ICS Function Name Stock Movement Report Created 4/3/2007 By FSBT) Ado

    Document Name Title Updated 4/23/2007 By FSBT) Ado

    A20061215_01 DB Connection

    SQL Query takes too long to finish its execution. It takes more than 5 hours.

    Modified and optimized the SQL Query. The execution time, from more than 5 hours, is now 6 - 7 seconds. Avoided, as much as possible, the joining of

    multiple tables. Used a column-referencing individual query.

    SELECT PARTMOD.POSTING_DATE, SELECT X.POSTING_DATE,

    PARTMOD.ORDER_TYPE, X.ORDER_TYPE,

    PARTMOD.MVMT_TYPE, X.MVMT_TYPE,

    PARTMOD.SHIPMENT_MODULE_NO, X.SHIPMENT_MODULE_NO,

    SUM(PARTMOD.PART_QTY) PART_QTY, SUM(X.PART_QTY) PART_QTY,

    SUM(PARTMOD.STD_COST) STD_COST SUM(X.STD_COST) STD_COST

    FROM (SELECT OEMEXPSDOC.ORDER_TYPE, FROM (SELECT (SELECT OEMEXPSDOC.ORDER_TYPE

    OEMEXPMOD.SHIPMENT_MODULE_NO, FROM TB_B_OEM_EXP_SDOCS OEMEXPSDOC

    OEMEXPSDOC.MVMT_TYPE, WHERE OEMEXPMOD.OEM_SDOC_ID = OEMEXPSDOC.ID

    OEMEXPSDOC.POSTING_DATE, AND OEMEXPSDOC.IS_COMMERCIAL = 'Y'

    OEMEXPITEM.PART_QTY, AND EXISTS (SELECT 0

    OEMEXPITEM.STD_COST, FROM TB_B_AC_PERIODS ACPRD

    OEMEXPITEM.PARENT_PART_ID, WHERE ACPRD.ID = 173 AND

    OEMEXPITEM.PART_ID, ACPRD.TYPE_CD = 2 AND

    OEMLOC.LOC_ID OEMEXPSDOC.POSTING_DATE BETWEEN ACPRD.START_DATE AND ACPRD.END_DATE)

    AND ROWNUM = 1) ORDER_TYPE,

    Action Sheet

    ProblemExplanation

    Action Explanation

    Bad / Not Recommended Sample Recommended Sample

  • 26/37Phase MA Project Name TMT Application Maintenance Page

    Block Name ICS Function Name Stock Movement Report Created 4/3/2007 By FSBT) Ado

    Document Name Title Updated 4/23/2007 By FSBT) AdoAction Sheet

  • 27/37Phase MA Project Name TMT Application Maintenance Page

    Block Name ICS Function Name Stock Movement Report Created 4/3/2007 By FSBT) Ado

    Document Name Title Updated 4/23/2007 By FSBT) AdoAction Sheet

    FROM TB_B_OEM_EXP_SDOCS OEMEXPSDOC, OEMEXPMOD.SHIPMENT_MODULE_NO,

    TB_B_OEM_EXP_SDOC_MODULE_ITEMS OEMEXPITEM, (SELECT OEMEXPSDOC.MVMT_TYPE

    TB_B_OEM_EXP_SDOC_MODULE_ITEMS OEMEXPITEM, FROM TB_B_OEM_EXP_SDOCS OEMEXPSDOC

    TB_B_OEM_LOCATIONS OEMLOC, WHERE OEMEXPMOD.OEM_SDOC_ID = OEMEXPSDOC.ID

    TB_B_AC_PERIODS ACPRD AND OEMEXPSDOC.IS_COMMERCIAL = 'Y'

    WHERE ACPRD.ID = 173 AND AND EXISTS (SELECT 0

    ACPRD.TYPE_CD = 2 AND FROM TB_B_AC_PERIODS ACPRD

    OEMEXPMOD.PACK_LOC_ID = OEMLOC.ID AND WHERE ACPRD.ID = 173 AND

    OEMEXPMOD.OEM_SDOC_ID = OEMEXPSDOC.ID AND ACPRD.TYPE_CD = 2 AND

    OEMEXPITEM.SDOC_MOD_ID = OEMEXPMOD.ID AND OEMEXPSDOC.POSTING_DATE BETWEEN ACPRD.START_DATE AND OEMEXPSDOC.POSTING_DATE BETWEEN ACPRD.START_DATE AND ACPRD.END_DATE)

    ACPRD.END_DATE AND AND ROWNUM = 1) MVMT_TYPE,

    OEMEXPMOD.PACK_LOC_ID IN (SELECT OEMEXPSDOC.POSTING_DATE

    (SELECT ID FROM TB_B_OEM_EXP_SDOCS OEMEXPSDOC

    FROM TB_B_OEM_LOCATIONS OEMLOC1 WHERE OEMEXPMOD.OEM_SDOC_ID = OEMEXPSDOC.ID

    WHERE OEMLOC1.LOC_ID = OEMLOC.LOC_ID) AND AND OEMEXPSDOC.IS_COMMERCIAL = 'Y'

    OEMEXPSDOC.IS_COMMERCIAL = 'Y') PARTMOD, AND EXISTS (SELECT 0

    TB_B_PARTS PART, FROM TB_B_AC_PERIODS ACPRD

    TB_B_PART_MINV PMINV WHERE ACPRD.ID = 173 AND

    WHERE PARTMOD.PART_ID = PART.ID AND ACPRD.TYPE_CD = 2 AND

    PMINV.PART_ID = PARTMOD.PARENT_PART_ID AND OEMEXPSDOC.POSTING_DATE BETWEEN ACPRD.START_DATE AND

    PMINV.ACPRD_ID = 173 AND ACPRD.END_DATE)

    PMINV.STATUS = 'FGO' AND ROWNUM = 1) POSTING_DATE,

    GROUP BY OEMEXPITEM.PART_QTY,

    PARTMOD.POSTING_DATE, OEMEXPITEM.STD_COST

    PARTMOD.ORDER_TYPE, FROM TB_B_OEM_EXP_SDOC_MODULES OEMEXPMOD,

    PARTMOD.MVMT_TYPE, TB_B_OEM_EXP_SDOC_MODULE_ITEMS OEMEXPITEM

    PARTMOD.SHIPMENT_MODULE_NO WHERE OEMEXPITEM.SDOC_MOD_ID = OEMEXPMOD.ID) X

    WHERE X.POSTING_DATE IS NOT NULL

    avoid using multiple tables for joining, especially large tables

    avoid using "IN" clause

    minimal joining tables

    use "EXIST" clause

    use column referencing from smaller tables

  • 28/37Phase MA Project Name TMT Application Maintenance Page

    Block Name ICS Function Name Stock Movement Report Created 4/3/2007 By FSBT) Ado

    Document Name Title Updated 4/23/2007 By FSBT) AdoAction Sheet

  • 29/37Phase MA Project Name TMT Application Maintenance Page

    Block Name ICS Function Name Stock Movement Report Created 4/3/2007 By FSBT) Ado

    Document Name Title Updated 4/23/2007 By FSBT) AdoAction Sheet

    AND X.ORDER_TYPE IS NOT NULL

    AND X.MVMT_TYPE IS NOT NULLGROUP BY X.POSTING_DATE,

    X.ORDER_TYPE,

    X.MVMT_TYPE,

    X.SHIPMENT_MODULE_NO

  • 30/37Phase MA Project Name TMT Application Maintenance Page

    Block Name FISM Function Name Aggregation Created 6/18/2007 By FSBT) Rhose

    Document Name Title Updated 6/18/2007 By FSBT) Rhose

    A20070618_01 DB Connection

    ORA-01795: maximum number of expressions in a list is 1000

    During the time this exception occurred, String 'sAccPeriod' in example contains almost 1200 concatenated parameters.

    Modified and optimized the SQL Query. If you have to compare String values with the field values, if you are not sure on how long the length of your String

    value will be, use EXISTS instead of IN clause.

    create global temporary table TB_T_ACC_PERIOD

    (

    ACC_PERIOD VARCHAR2(20))

    on commit preserve rows;

    String sAccPeriod = new String();

    for (int j = 0; j < arrAcctPeriod.size(); j++) INSERT INTO TB_T_ACC_PERIOD(ACC_PERIOD)

    { VALUES (?) if (j == 0)

    {

    sAccPeriod = "'" + arrAcctPeriod.get(j) + "'"; if (arrAcctPeriod.size() > 0)

    } else { {

    sAccPeriod += ", '" + arrAcctPeriod.get(j) + "'"; dao.keepAccPeriod(conn, arrAcctPeriod);

    } }

    }

    Action Sheet

    ProblemExplanation

    Action Explanation

    Bad / Not Recommended Sample Recommended Sample

    shows how the String parameters are concatenated or formed

    this is the query of keepAccPeriod method where '?' is substituted by the parameter 'arrAcctPeriod' value

    this shows how to populate the temporary table

    shows how to create global temporary table. Note that on global temporary table, records will be deleted upon commit or rollback

  • 31/37Phase MA Project Name TMT Application Maintenance Page

    Block Name FISM Function Name Aggregation Created 6/18/2007 By FSBT) Rhose

    Document Name Title Updated 6/18/2007 By FSBT) RhoseAction Sheet

  • 32/37Phase MA Project Name TMT Application Maintenance Page

    Block Name FISM Function Name Aggregation Created 6/18/2007 By FSBT) Rhose

    Document Name Title Updated 6/18/2007 By FSBT) RhoseAction Sheet

    UPDATE TB_R_GL UPDATE TB_R_GL GL_TB

    SET STS = 1 , SET STS = 1 ,

    OUTBOUND_IF_NAME = 'GL_OEM_EXP_ICS_RGR_JV_20070607181026_D' , OUTBOUND_IF_NAME = 'GL_OEM_EXP_ICS_RGR_JV_20070607181026_D' ,

    UPDATE_DT = sysdate , UPDATE_DT = sysdate ,

    UPDATE_BY = 'uusfi00' UPDATE_BY = 'uusfi00'

    WHERE BIZ_SCN_CD = 'OEM_EXP_ICS_RGR_GL' WHERE GL_TB.BIZ_SCN_CD = 'OEM_EXP_ICS_RGR_GL'

    AND PART_RECEIVED_DT = '05/26/2007' AND GL_TB.PART_RECEIVED_DT = '05/26/2007'

    AND COMPANY_CD = 'F4775' AND GL_TB.COMPANY_CD = 'F4775'

    AND ACCOUNT_CD = '5161110' AND GL_TB.ACCOUNT_CD = '5161110'

    AND COST_CENTER = '00000000' AND GL_TB.COST_CENTER = '00000000'

    AND BIZ_CD = '000' AND GL_TB.BIZ_CD = '000'

    AND PROJECT_CD = '0000' AND GL_TB.PROJECT_CD = '0000'

    AND INTER_COMPANY_CD = '00000' AND GL_TB.INTER_COMPANY_CD = '00000'

    AND BUDGET_NO = '00000' AND GL_TB.BUDGET_NO = '00000'

    AND FUTURE1 = '00000' AND GL_TB.FUTURE1 = '00000'AND FUTURE2 = '00000' AND GL_TB.FUTURE2 = '00000'

    AND ACC_PERIOD IN (sAccPeriod.trim()); AND EXISTS (SELECT 0 FROM TB_T_ACC_PERIOD

    WHERE ACC_PERIOD = GL_TB.ACC_PERIOD);

    avoid using the 'IN' clause or 'INSTR' clause if you are not sure what will be the maximum length or number of your String parameter.

    use "EXIST" clause on temporary table instead

  • 33 / 37Phase External Design Project name GSPS/A-TOP PageBlock name C Common Function name Common Created 2003/5/14 By FJCL) IshikawaDocument name SQL Standards Title SQL Standards Updated 2003/11/05 By FJ Tsukamoto

    2. SQL Standards

    SQL standards are defined in the following table. In cases where it is not possible to adhere to the GSPS/A-TOP standards, the impact on areas such as response time should be investigated and approval obtained from CIT.TMC details of DB2 standards are provided in the document "Revised DB2 Standards.doc".

    No. GSPS/A-TOPS standards Revised DB2 Standards.doc1 EXPLAIN check results EXPLAIN access path check (standard)

    Where SQL has been chosen, EXPLAIN must be obtained in the stand-alone test phase to check Where SQL has been chosen, EXPLAIN must be obtained in the stand-alone test phase to check the access path. the access path.The results of the EXPLAIN check should satisfy the following conditions. Where the following conditions are met on the basis of the EXPLAIN check, an SQL review is

    normally required. ACCESSTYPE=I and MATCHCOLS=0 ACCESSTYPE=R (except for very small tables and external tables)

    SQL is normally modified in order to change PREFETCH=L to either PREFETCH=S or 'None'. Where PLAN/PACKAGE is bound in the actual environment, the EXPLAIN(YES) option must be used for BIND processing, to obtain and store access path information.

    Where PLAN/PACKAGE is bound in the actual environment, the EXPLAIN(YES) option must be used for BIND processing, to obtain and store access path information.

    2 As per right-hand column Where the same SQL statement is used more than one time in a program, rather than writing multiple SQL statement descriptions, the same statement should be re-used.

    3 As per right-hand column SQL statement descriptions should be no larger than 25 KB including blank portions.

    4 If there is only one applicable record (or less) and exclusion is not required following extraction If there is only one applicable row (or less), use a single SELECT rather than FETCH. (deletion/update not performed), use stand-alone SELECT.

    5 UPDATE processing when there is only one applicable record (or less) should be performed directly Where UPDATE processing does not require cursor positioning, update directly using using single UPDATE. a single UPDATE.

    6 As per right-hand column For read-only processes, specify 'FETCHONLY' in the cursor declaration.

    7 Where update can be performed based on the cursor, specify the 'FORUPDATEOF' in the Where update can be performed based on the cursor, specify 'FORUPDATEOF' cursor declaration. in the cursor declaration.The COLUMN name for the UPDATE should be specified after the 'OF'. The cursor used for DELETE is FOR UPDATE OF COL name 1 (COL name 1 is not an index item. An arbitrary item is specified.)

    8 As per right-hand column To obtain some rather than all applicable rows, specify OPTIMIZE for n ROWS.

    9 Where column functions are used, these must be coordinated among individual applications The use of column functions should be well considered and thoroughly discussed beforehand beforehand and CIT approval must be obtained. among individual application development teams.Normally, only restricted column functions such as MIN, MAX and COUNT should be used. MIN, MAX may only be used in the following cases:

    Where DB2 searches 10 records or less in order to identify MIN, MAX (e.g.: When finding the "latest data validity start time", all KEY items should be specified as equal sign conditions in the WHERE clause, and there should be no more than 10 records with "different data validity start times".)

    If COUNT is used, convention 1 must be satisfied.

    ACCESSTYPE=I (or I1)ACCESSTYPE=N requires DBA approval) MATCHCOLS0 METHOD3 must conform to ORDER BY conventions (A-TOP standard No.11)

    Any JOIN other than METHOD=1 (Nested Loop Join) must be approved by DBA

    Where MIN, MAX can be obtained using ACCESSTYPE=I1

  • 34 / 37Phase External Design Project name GSPS/A-TOP Page Block name C Common Function name Common Created 2003/5/14 By FJCL) IshikawaDocument name SQL Standards Title SQL Standards Updated 2003/11/05 By FJ Tsukamoto

    No. GSPS/A-TOP standards Revised DB2 standards.doc10 Where JOIN is used, EXPLAIN results must be obtained and submitted beforehand. The following standards are normally applied to join processing:

    The following standards are normally used for join processing: N:M join in non-unique columns can be used for up to two tablesN:M join in non-unique columns can be used for up to two tables 1:1 joins for unique columns can be used for up to three tables1:1 joins for unique columns can be used for up to three tables Joined columns must be index columns.Joined columns must be index columns. Conditions for Joined columns must be specified.Conditions for Joined columns must be specified. All join types may be used (FULL,LEFT,RIGHT-OUTER,INNER).INNER JOIN should be normally used.LEFT OUTER is normally not allowed.RIGHT-OUTER/FULL-OUTER is never allowed.

    11 ORDER BY is normally used in accordance with the following standards. ORDER BY is normally used in accordance with the following standards:ORDER BY on cluster index columns

    Online ORDER BY usage standards where cluster index is not used BATCH and online ORDER BY usage standards where cluster index is not used- Sum of column sizes for extracted data -- maximum 200 bytes Sum of column sizes for extracted data -- maximum 200 bytes

    - Number of records sorted maximum 100 records Number of records sorted maximum 100 records(Note that the number of records sorted is the ANSERSET (searched rows) number, not the FETCH record.)

    ORDER BY in BATCH prohibited except for above

    12 As per right-hand column Holding FETCH cursor across commit should be implemented using the SQL WITHHOLD clause rather than by application program logic.

    13 As per right-hand column Use UNCOMMITEDREAD for read-only processes where practicable.

    14 The UNION processing is not normally allowed. Where UNION is used, EXPLAIN results UNION processing allowed where necessary.must be obtained and submitted beforehand.

    15 As per right-hand column The column name must be explicitly stated for INSERT process.

    16 As per right-hand column When joining multiple conditions using AND, start with conditions that have a higher filtering ratio.

    17 As per right-hand column When joining multiple conditions using OR, start with conditions that have a lower filtering ratio.

    18 As per right-hand column 'IN(sub-query)' must be performed using JOIN.However, the SQL obtained as a result of rewrite using "JOIN" clause must conform to JOIN rules SELECT A FROM TB1 WHERE B IN(A-TOP standard No. 10). (SELECT C FROM TB2 WHERE D=:HOSTVAR)

    SELECT A FROM TB1,TB2WHERE TB1.B=TB2.C AND TB2.D=:HOSTVAR

    ORDER BY on cluster index columns, where DB2 internal SORT (METHOD) does not occur

    - Sum of column sizes for SORT key items -- maximum 200 bytes Sum of column sizes for SORT key items -- maximum 200 bytes

  • 35 / 37Phase External Design Project name GSPS/A-TOP PageBlock name C Common Function name Common Created 2003/5/14 By FJCL) IshikawaDocument name SQL Standards Title SQL Standards Updated 2003/11/05 By FJ Tsukamoto

    No. GSPS/A-TOP standards Revised DB2 standards.doc19 As per right-hand column OR join for equal sign predicate in same row is written with IN.

    SELECT COUNT(*) FROM TB1WHERE A='10' OR A='20' OR A='30'SELECT COUNT(*) FROM TB1WHERE A IN('10','20','30')

    20 UNION processing is not normally allowed. Where UNION is used, EXPLAIN results must be OR join for non-equal sign predicate in same row is written with UNION.obtained and submitted beforehand. SELECT * FROM TB1

    UNION

    21 Same as right-hand column when rewriting with UNION ALL UNION is used for OR join of index rows and non-index rows.SELECT * FROM TB1WHERE A=:HOSTVAR1 OR B=:HOSTVAR2

    For UNION, DISTINCT is performed within DB2 to prevent duplicate rows being returned.This should be avoided because SORT is executed for DISTINCT, increasing SQL costs. WHERE A=:HOSTVAR1For UNION ALL, DISTINCT is not performed, so where return of duplicate rows is not a problem, UNIONUNION ALL is used. SELECT * FROM TB1

    WHERE B=:HOSTVAR2

    22 As per right-hand column LIKE description should be replaced with IN predicate or BETWEEN predicate wherever possible.SELECT COUNT(*) FROM TB1WHERE A LIKE 'IBM%'

    SELECT COUNT(*) FROM TB1WHERE A IN('IBM1','IBM2','IBM3','IBM4','IBM5','IBM6','IBM7','IBM8','IBM9')orSELECT COUNT(*) FROM TB1WHERE A BETWEEN 'IBM1' AND 'IBM9'

    23 As per right-hand column BETWEEN is used for range predicate; AND join of non-equal sign conditions is not used.

    WHERE A BETWEEN '100' AND '200'When the search condition is '> OR

  • 36 / 37Phase External Design Project name GSPS/A-TOP Page Block name C Common Function name Common Created 2003/5/14 By FJCL) IshikawaDocument name SQL Standards Title SQL Standards Updated 2003/11/20 By IBM Shimizu

    No. GSPS/A-TOP standards24 Where UPDATE or INSERT is used, the department, user ID, and time of update (TIMESTAMP) must be updated.

    TIMESTAMP update is performed using CURRENT TIMESTAMP as follows:UPDATE tablename SET MTTMSP = CURRENT TIMESTAMP WHERE (MTTIME is COLUMNNAME for time of update)

    (Either BLANK or UNDERSCORE ('_') may be used between CURRENT and TIMESTAMP.)

    25 The cursor used to extract records selected with SQL should be closed immediately when no longer required.(This releases LOCKs where possible, and allows other programs waiting for LOCK to begin processing.)

    26 Error checking should be performed on all SQL statements, including OPEN and CLOSE as well as FETCH and UPDATE/INSERT/SELECT.

    27 The column name must be explicitly stated for SELECT process (SELECT * not allowed).Specify only necessary fetch items to be obtained by the program using SELECT and UPDATE.

    28 During batch updating, commit should be performed every 1000 records.Online updates are normally restricted to up to 100 records.

    29 Column and host variable attributes must match.

    30 NOT may not be used in conditional statements.

    31 BETWEEN low-val AND high-val may not be used in 1st MATCHCOLS item.

    32 SUBSTR and COLUMN CONCAT should be avoided in predicate.

    33 KEY-UPDATE for cluster index and type keys should not be permitted -- DELETE/INSERT used instead.

    34 NULL may not be used. If there is no data, a SPACE consisting of at least 1 BLANK should be inserted.

    35 DISTINCT is normally not allowed.

    36 TABLE ACCESS order must be followed.

    37 Update order for RECORDs in TABLE is as per CLUSTER order within each UOW.Necessary for exclusion control, and also to prevent DEADLOCK.Applies to all BATCH/ONLINE DELETE/INSERT/UPDATE operations.CLUSTER order us updated when updating RECORD after searching with secondary index.

    38 DELETE/UPDATE for multiple rows is not performed using direct DELETE/UPDATE.Select rows using SELECT FOR UPDATE, then perform DELETE/UPDATE CURRENT OF CURSOR.

    Main KEY must be used to designate rows for exclusion control and to prevent DEADLOCK. The above rules must be followed in order to adhere to the 1000 records COMMIT requirement.

    Using direct DELETE/UPDATE for multiple row DELETE/UPDATE can cause the number of updates to exceed 1,000 records without warning.In the worst-case scenario, the DB2 system control value (NUMLKUS = 10,000 records) is exceeded, causing ABEND.LOCK for update rows is held in DB2 REGION MEMORY.NUMLKUS is the limit value used to prevent applications from obtaining excessively large LOCK quantities, thus ensuring concurrency among applications.The 1000 records COMMIT rule is a gentlemen's agreement built into applications as a means of ensuring that the NUMLKUS value is not accidentally exceeded. Applications that do not observe the 1000 records COMMIT rule put pressure on shared DB2 MEMORY resources, which affects other applications.

    39 Sub-queries are not normally allowed. DBA approval is required before using sub-queries.

  • 37 / 37Phase External Design Project name GSPS/A-TOP PageBlock name C Common Function n Common Created 2003/5/14 By FJCL) IshikawaDocument name SQL Standards Title SQL Standards Updated 2003/11/20 By IBM Shimizu

    No. GSPS/A - TOP standard1 Results of EXPLAIN check EXPLAIN access path check (standard)

    Where SQL has been chosen, EXPLAIN must be obtained in the stand-alone test phase to check Where SQL has been chosen, EXPLAIN must be obtained in the stand-alone test phase to check the access path. the access path. Based on the results of the EXPLAIN check, the following conditions should be satisfied. Where the following conditions are met on the basis of the EXPLAIN check, an SQL review is

    normally required. Index SCAN and #Key Columns = 0

    Where PLAN/PACKAGE is bound in the actual environment, the EXPLAIN(YES) option must be or None. used for BIND processing, to obtain and store access path information.

    Where PLAN/PACKAGE is bound in the actual environment, the EXPLAIN(YES) option must be used for BIND processing, to obtain and store access path information.

    9 Where column functions are used, these must be coordinated among individual applications Where column functions are used, these must be coordinated among individual beforehand and CIT approval must be obtained. applications beforehand. Normally, only restricted column functions such as MIN, MAX and COUNT must be used. MIN, MAX may only be used in the following cases:

    (e.g.: When finding the "latest data validity start time", all KEY items should be specified as equal sign conditions in the WHERE clause, and there should be no more than 10 records with "different data validity start times".)

    If COUNT is used, convention 1 must be satisfied. 11 The following standards are normally used for ORDER BY. The following standards are normally used for ORDER BY:

    is not generated for ORDER BY on cluster index columns BATCH and online ORDER BY usage standards where cluster index is not used Online ORDER BY usage standards where cluster index is not used Sum of column sizes for extracted data -- maximum 200 bytes

    - Sum of column sizes for extracted data -- maximum 200 bytesNumber of records sorted maximum 100 records

    - Number of records sorted maximum 100 records(Note that the number of SORTs is the ANSERSET (searched rows) number, not the FETCH number.

    38 DELETE/UPDATE for multiple rows is not performed using direct DELETE/UPDATE.Define the rows using SELECT FOR UPDATE, then execute DELETE/UPDATE CURRENT OF CURSOR.

    Main KEY must be used to designate rows for exclusion control and to prevent DEADLOCK. The above rules must be followed in order to adhere to the 1000 records COMMIT requirement.

    LOCK for update rows is held in Database Global Memory.

    LOCK restrictions are specified in the database configuration parameters LOCKLIST and MAXLOCKS.

    - MAXLOCKS: Percentage of LOCKs per application that can be acquired within the LOCKLIST limit, standard value = 15

    Applications should be designed to prevent lock escalation and preserve application concurrency.If an investigation determines that a lock escalation has occurred, the lock range should be coordinated among applications (including SQL review). The 1000 COMMIT rule is considered a gentlemen's agreement between applications designed to avoid the possibility of lock escalation due to simple errors.An application that does not conform to the 1000 records COMMIT rule puts pressure on shared DB2 MEMORY resources, which affects other applications.

    Must be Index SCAN #Key Columns0 If SORT is generated, ORDER BY conventions (A-TOP standard No.11) must be satisfied Table SCAN (except for very small tables and external tables)

    SQL is normally modified in order to change list PREFETCH to either sequential PREFETCH

    Any JOIN other than Nested Loop Join must be approved by DBA

    Where MIN, MAX can be limited using Index SCAN Where DB2 searches 10 records or less in order to determine MIN, MAX

    Where DB2 internal SORT (determined by Insert Into Sorted Temp Table keywords in Explain) ORDER BY for cluster index columns

    Sum of column sizes for SORT key items -- maximum 200 bytes- Sum of column sizes for SORT key items -- maximum 200 bytes

    ORDER BY in BATCH prohibited except for above

    The LOCK for the entire database holds up to 10,000 records (the maximum number of records is 1,500 per application).

    - LOCKLIST: number of LOCKs that can be held in the database (number of pages @ 4 KB per page), standard value = 100/150 (32/64 bit UDB)

    When applications attempt to acquire more LOCKs than the MAXLOCKS limit, a lock escalation occurs and locks are assigned to individual tables (the LOCKLIST is released).

    3.13.23.2.2App A - SqlTipsApp A - SqlTips (Action Sheet)App A - SqlTips (Action Sheet)2App B - SQL StandardsApp B - SQL Standards (2)App B - SQL Standards (3)App B - SQL Standards (4)App B - SQL Standards (5-UDB)