home clear 64x64
en blue 200x116 de orange 200x116 info letter User
suche 36x36
Latest versionsfixlist
11.1.0.7 FixList
10.5.0.9 FixList
10.1.0.6 FixList
9.8.0.5 FixList
9.7.0.11 FixList
9.5.0.10 FixList
9.1.0.12 FixList
Have problems? - contact us.
Register for free anmeldung-x26
Contact form kontakt-x26

DB2 - Problem description

Problem IC98964 Status: Closed

SCALAR SUBQUERIES ARE NOT PUSHED DOWN THROUGH UNION ALL LEADING TO POOR
PERFORMANCE

product:
DB2 FOR LUW / DB2FORLUW / A10 - DB2
Problem description:
When the following conditions are true, scalar subqueries will 
not be pushed down through UNION ALL. 
1. UNION ALL contains one or more correlated subqueries 
2. UNION All view has a predicate referencing a SQL scalar UDF 
3. The UDF has a function body that is a simple RETURN 
fullselect 
 
 
As an example please find following statement: 
 
CREATE VIEW VIEW1 (EMPNO, DEPTNO, ISRESP) as ( 
 SELECT A.EMPNO, A.WORKDEPT, 
  CASE WHEN NOT EXISTS ( SELECT 1 FROM project B WHERE A.EMPNO = 
B.RESPEMP ) 
   THEN 0 
   ELSE 1 
   END 
  AS ISRESP FROM employee A ) 
 UNION ALL 
 SELECT MGRNO, ADMRDEPT, 0 FROM DEPARTMENT 
 
 
and function used as predicate for EMPNO: 
 
CREATE OR REPLACE FUNCTION SCALAR_FUNCTION ( EMPNO int ) 
  RETURNS INTEGER 
  DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION 
  RETURN VALUES ( 
   CASE WHEN EMPNO < 100 
    THEN EMPNO 
    ELSE 9999 
   END 
  ) 
 
 
Once you generate explain plan for the execution, you will 
notice: 
 
 
Access Plan: 
----------- 
    Total Cost:        27.3384 
    Query Degree:        1 
 
             Rows 
            RETURN 
            (   1) 
             Cost 
              I/O 
               | 
             2.24 
            NLJOIN 
             (   2) 
            27.3384 
               4 
          /---+-------\ 
         1                2.24 
     TBSCAN         FILTER 
       (   3)            (   4) 
  1.6532e-005     13.7274 
        0                   2 
        |                   | 
        1                  56 
TABFNC: SYSIBM   UNION 
     GENROW          (   5) 
                         13.7139 
                             2 
                  /-------+--------\ 
                 14                     42 
         TBSCAN                   NLJOIN 
           (   6)                      (   7) 
         6.81553                   6.89572 
              1                           1 
             |                      /----+-----\ 
           14                   42                 1 
     TABLE: MBASTER   TBSCAN        TBSCAN 
       DEPARTMENT       (   8)             (   9) 
           Q1               6.82217         0.00690429 
                                   1                  0 
                                   |                  | 
                                  42             0.47619 
                        TABLE: MBASTER     SORT 
                             EMPLOYEE         (  10) 
                                 Q6           0.00667615 
                                                      0 
                                                      | 
                                                 0.47619 
                                                 IXSCAN 
                                                  (  11) 
                                               0.00619229 
                                                      0 
                                                      | 
                                                     20 
                                           INDEX: MBASTER 
                                                  XPROJ2 
                                                     Q3 
 
 
Predicate on EMPNO is applied on FILTER 4: 
 
        Predicates: 
        ---------- 
        2) Residual Predicate, 
            Comparison Operator:        Equal (=) 
            Subquery Input Required:    No 
            Filter Factor:            0.04 
 
            Predicate Text: 
            -------------- 
            (DECFLOAT(Q8.$C0, 34, '.') = Q10.$C0) 
 
 
 
Presence of correlation: 
 
CASE WHEN NOT EXISTS ( 
 SELECT 1 FROM project B WHERE A.EMPNO = B.RESPEMP ) 
 THEN 0 
 ELSE 1 
 END AS ISRESP FROM employee A ) 
 
prevents the scalar predicate push down through the UNION ALL.
Problem Summary:
**************************************************************** 
* USERS AFFECTED:                                              * 
* ALL                                                          * 
**************************************************************** 
* PROBLEM DESCRIPTION:                                         * 
* See Error Description                                        * 
**************************************************************** 
* RECOMMENDATION:                                              * 
* Upgrade to DB2 version DB2 version 10.1 fixpack 5            * 
****************************************************************
Local Fix:
In order to workaround the problem, you need to remove VALUE 
modifier from the function used as a predicate: 
 
 
CREATE OR REPLACE FUNCTION NONSCALAR_FUNCTION (EMPNO int) 
  RETURNS INTEGER 
  DETERMINISTIC CONTAINS SQL NO EXTERNAL ACTION 
  RETURN ( CASE WHEN EMPNO < 100 THEN EMPNO ELSE 9999 
    END 
  ); 
 
Once you generate explain plan for the execution, you will 
notice that predicate on EMPNO is applied on TBSCAN: 
 
 
        Predicates: 
        ---------- 
        3) Sargable Predicate, 
            Comparison Operator:        Equal (=) 
            Subquery Input Required:    No 
            Filter Factor:            0.04 
 
            Predicate Text: 
            -------------- 
            (DECFLOAT(Q6.EMPNO, 34, '.') = 20) 
 
 
Further, we can also apply additional predicate on IXSCAN due 
to correlation A.EMPNO = B.RESPEMP : 
 
        Predicates: 
        ---------- 
        2) Sargable Predicate, 
                Comparison Operator:            Equal (=) 
                Subquery Input Required:        No 
                Filter Factor:                  0.0228571 
 
                Predicate Text: 
                -------------- 
                (DECFLOAT(Q1.MGRNO, 34, '.') = 20)
Solution
Problem was first fixed in DB2 version 10.1 fixpack 5
Workaround
not known / see Local fix
Comment
The suggested alternate behavior has been entered into IBM 
internal record wsdbu01234386. If you need further information, 
please contact IBM Support.
BUG-Tracking
forerunner  : APAR is sysrouted TO one or more of the following: IC99022 IC99023 IC99024 
follow-up : 
Timestamps
Date  - problem reported    :
Date  - problem closed      :
Date  - last modified       :
24.01.2014
28.07.2015
28.07.2015
Problem solved at the following versions (IBM BugInfos)
Problem solved according to the fixlist(s) of the following version(s)
10.1.0.5 FixList