Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Oracle style to ANSI JOIN transformation result, depending on predicate order #10983

Closed
lukaseder opened this issue Nov 19, 2020 · 1 comment

Comments

@lukaseder
Copy link
Member

As reported here:
https://blog.jooq.org/2020/11/17/automatically-transform-oracle-style-implicit-joins-to-ansi-join-using-jooq/#comment-404345

Consider these input queries, which are equivalent, and differ only in the lexical order of predicates:

select *
from A, B
where (A.ID = B.ID(+) AND B.ID = 1);

select *
from A, B
where (B.ID = 1 AND A.ID = B.ID(+));

Transforming the Oracle style to ANSI JOIN yields different results:

select *
from A
  join B
    on A.ID = B.ID
where B.ID = 1;

select *
from A
  left outer join B
    on A.ID = B.ID
where B.ID = 1;

Both are correct. The one that produces an inner join applies an optimisation that seems not to be applied otherwise. Perhaps, the optimisation isn't worth it, given that:

  • it seems to be tricky to apply independently of predicate ordering
  • it doesn't matter in cases like these, as the RDBMS will perform the optimisation anyway
  • without the optimisation, the user "intent" is reflected more clearly
  • there may be an edge case where the optimisation produces wrong SQL?
@lukaseder
Copy link
Member Author

Fixed in jOOQ 3.15.0 and 3.14.4 (#10995)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

1 participant