The incorrect result HASH / MERGE JOIN in the fields of type VARCHAR with a 
trailing space
------------------------------------------------------------------------------------------

                 Key: CORE-4909
                 URL: http://tracker.firebirdsql.org/browse/CORE-4909
             Project: Firebird Core
          Issue Type: Bug
    Affects Versions: 3.0 Beta 2, 2.5.4
            Reporter: Simonov Denis


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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to