MERGE / HASH JOINs produce incorrect results when VARCHAR join keys differ only by trailing spaces [CORE4909] #5201
Labels
affect-version: 2.1.5 Update 1
affect-version: 2.1.6
affect-version: 2.1.7
affect-version: 2.5.0
affect-version: 2.5.1
affect-version: 2.5.2 Update 1
affect-version: 2.5.2
affect-version: 2.5.3 Update 1
affect-version: 2.5.3
affect-version: 2.5.4
affect-version: 3.0 Alpha 1
affect-version: 3.0 Alpha 2
affect-version: 3.0 Beta 1
affect-version: 3.0 Beta 2
component: engine
fix-version: 2.5.5
fix-version: 3.0 RC1
priority: major
qa: done successfully
type: bug
Submitted by: @sim1984
RECREATE TABLE T (
V VARCHAR(10),
X INTEGER
);
INSERT INTO T (V, X) VALUES ('ww', 1);
INSERT INTO T (V, X) VALUES ('ww ', 2);
COMMIT;
--CREATE INDEX IDX_T_V ON T(V); -- If you remove the comment behavior changes
select
REPLACE(T1.V, ' ', '0') AS V1,
T1.X AS X1,
REPLACE(T2.V, ' ', '0') AS V2,
T2.X AS X2
from T T1 join T T2 on T1.V = T2.V
Firebird 3.0 Beta 2
PLAN HASH (T2 NATURAL, T1 NATURAL)
V1 X1 V2 X2
ww 1 ww 1
ww0 2 ww0 2
Firebird 2.5.5
PLAN MERGE (SORT (T2 NATURAL), SORT (T1 NATURAL))
V1 X1 V2 X2
ww 1 ww 1
ww0 2 ww0 2
Is replaced by the LEFT JOIN. There is only the optimizer can use NESTED LOOP
select
REPLACE(T1.V, ' ', '0') AS V1,
T1.X AS X1,
REPLACE(T2.V, ' ', '0') AS V2,
T2.X AS X2
from T T1 left join T T2 on T1.V = T2.V
Firebird 3.0 Beta 2 AND 2.5.5
PLAN JOIN (T1 NATURAL, T2 NATURAL)
V1 X1 V2 X2
ww 1 ww 1
ww 1 ww0 2
ww0 2 ww 1
ww0 2 ww0 2
If you uncomment the creation of the index, the result is the same as for a LEFT JOIN, well, except for the plan.
Commits: 125a332 47979ea 6131cf1 FirebirdSQL/fbt-repository@f5567d7 FirebirdSQL/fbt-repository@2f3a8e2 FirebirdSQL/fbt-repository@5cdfb4b
The text was updated successfully, but these errors were encountered: