DB2 - Problem description
Problem IT35685 | Status: Closed |
Query with 'ORDER BY' and referencing a common subexpression over column-organized tables may return rows in the wrong order | |
product: | |
DB2 FOR LUW / DB2FORLUW / B50 - DB2 | |
Problem description: | |
If a query: - contains a common subexpression ("CSE") over column-organized tables - SELECTs the same column from different references to that CSE - orders the output on one copy of that column using ORDER BY and the structure of the query is such that same column from the different CSE references can have different values by the time the data streams from those references join together, the output might be ordered on the wrong copy of the column - the one from the other CSE reference - rather than the specified one. Example: CREATE TABLE "FOJ "."TABLE6" ( "CD_DEMO_SK" INTEGER NOT NULL ) DISTRIBUTE BY HASH("CD_DEMO_SK") IN "USERSPACE1" ORGANIZE BY COLUMN; ALTER TABLE "FOJ "."TABLE6" ADD PRIMARY KEY ("CD_DEMO_SK") NOT ENFORCED; CREATE TABLE "FOJ "."TABLE10" ( "C_CUSTOMER_SK" INTEGER NOT NULL , "C_BIRTH_DAY" INTEGER , "C_BIRTH_MONTH" INTEGER , "C_BIRTH_YEAR" INTEGER ) DISTRIBUTE BY HASH("C_CUSTOMER_SK") IN "USERSPACE1" ORGANIZE BY COLUMN; ALTER TABLE "FOJ "."TABLE10" ADD PRIMARY KEY ("C_CUSTOMER_SK") NOT ENFORCED; insert into "FOJ "."TABLE6" values 1,2,3,4; insert into "FOJ "."TABLE10" values (1,1,1,1),(1,2,3,4),(2,3,4,5) ; with v(c1, c2, c3) as (select C_BIRTH_DAY, C_BIRTH_YEAR, count(C_BIRTH_MONTH) from FOJ.TABLE10 group by C_BIRTH_DAY, C_BIRTH_YEAR) select v1.c1 as w, v1.c2+v1.c3 as x, v2.c1, v2.c2+v2.c3 as z from v v2 right join v v1 on v1.c2=v2.c3 order by v2.c1, x W X C1 Z ----------- ----------- ----------- ----------- 1 2 3 6 1 2 2 5 1 2 1 2 2 5 - - 3 6 - - 5 record(s) selected. The rows should be in the order of C1. | |
Problem Summary: | |
**************************************************************** * USERS AFFECTED: * * All * **************************************************************** * PROBLEM DESCRIPTION: * * See Error Description * **************************************************************** * RECOMMENDATION: * * Upgrade to 11.5.6 or later * **************************************************************** | |
Local Fix: | |
Solution | |
Workaround | |
**************************************************************** * USERS AFFECTED: * * All * **************************************************************** * PROBLEM DESCRIPTION: * * See Error Description * **************************************************************** * RECOMMENDATION: * * Upgrade to 11.5.6 or later * **************************************************************** | |
Comment | |
Upgrade to 11.5.6 or later | |
Timestamps | |
Date - problem reported : Date - problem closed : Date - last modified : | 25.01.2021 26.01.2021 23.06.2021 |
Problem solved at the following versions (IBM BugInfos) | |
Problem solved according to the fixlist(s) of the following version(s) |