IBM Support

IT29099: DB2 MAY RETURN INCORRECT RESULT WHEN EXECUTING QUERY WITH UNION VIEW INCLUDE MULTIPLE TABLES

Subscribe to this APAR

By subscribing, you receive periodic emails alerting you to the status of the APAR, along with a link to the fix after it becomes available. You can track this item individually or track all items by product.

Notify me when this APAR changes.

Notify me when an APAR for this component changes.

 

APAR status

  • Closed as program error.

Error description

  • Db2 may return incorrect result when executing query with union
    view include multiple tables.
    
    For example, the query reference a view V1.
    
    SELECT C1,
           C2,
           ...
    FROM   V1
    WHERE  C1 = constant
    AND    C2 = constant
    ;
    
    V1 looks like following, with Q1 including multiple subqueries
    and UNIONs which does OUTER JOIN with other tables including T3
    on column C1.
    
    CREATE VIEW V1
    AS
        SELECT
                Q1.C1,
                Q1.C2
                ...
        FROM (
                SELECT
                        T1.C3,
                        T1.C4,
                        ...
                        T2.C1,
                        T2.C2
                        ...
                FROM    T1
                        LEFT OUTER JOIN T2 ON (T1.C5 = T2.T5)
                WHERE
                        ...
                UNION ALL
                SELECT
                        T1.C3,
                        T1.C4,
                        ...
                        T2.C1,
                        T2.C2
                        ...
                FROM    T1
                        LEFT OUTER JOIN T2 ON (T1.C5 = T2.T5)
                WHERE
                        ...
    
                UNION ALL
                SELECT
                        T1.C3,
                        T1.C4,
                        ...
                        T2.C1,
                        T2.C2
                        ...
                FROM    T1
                        LEFT OUTER JOIN T2 ON (T1.C5 = T2.T5)
                WHERE
                        ...
            ) AS Q1
        LEFT OUTER JOIN T3
            ON (Q1.C1 = T3.C1 AND ...)
        ...
        LEFT OUTER JOIN T4
        ...
    
    Because there's an equal predicate on column C1, Db2 Rewrite
    pushes down a local predicate 'Q1.C1 = constant' under T3,
    which makes 'T3.C1 = constant'. During pushing down this
    predicate with other join predicates under the UNION,
    the predicate 'T3.C1 = constant' is removed in error and causing
    a wrong result.
    
    The workaround is to explicitly reference T3.C1 instead of Q1.C1
    as below:
    
    CREATE VIEW V1
    AS
        SELECT
                T3.C1,
                Q1.C2
    ...
    
    with this rewrite the predicate will not be removed.
    

Local fix

  • Rewrite the Query as per example in the Error Description.
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED:                                              *
    * ALL                                                          *
    ****************************************************************
    * PROBLEM DESCRIPTION:                                         *
    * See Error Description                                        *
    ****************************************************************
    * RECOMMENDATION:                                              *
    * Upgrade to Db2 11.1 Mod 4 Fixpack 5 or higher                *
    ****************************************************************
    

Problem conclusion

  • First fixed in Db2 11.1 Mod 4 Fixpack 5
    

Temporary fix

Comments

APAR Information

  • APAR number

    IT29099

  • Reported component name

    DB2 FOR LUW

  • Reported component ID

    DB2FORLUW

  • Reported release

    B10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    YesHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2019-05-10

  • Closed date

    2020-01-16

  • Last modified date

    2020-01-16

  • APAR is sysrouted FROM one or more of the following:

    IT28945

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    DB2 FOR LUW

  • Fixed component ID

    DB2FORLUW

Applicable component levels

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"11.1","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 January 2020