Skip to content

[BUG] - Incorrect join elimination optimization #986

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

Closed
belovaf opened this issue Apr 8, 2025 · 1 comment
Closed

[BUG] - Incorrect join elimination optimization #986

belovaf opened this issue Apr 8, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@belovaf
Copy link
Contributor

belovaf commented Apr 8, 2025

Jimmer Version

0.9.72

JDK Version

23

Database

Postgres, H2

OS

Mac

Expected behavior

Jimmer generates valid sql.

Actual behavior

Jimmer generated sql with missing alias.

Description

Jimmer incorrectly eliminates join with table if !fetchType(JOIN_ALWAYS) is used.

Reproduction steps

Model:

@MappedSuperclass
interface SerialId {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long
}

@Entity
interface A : SerialId {
    @OneToOne(mappedBy = "a")
    val b: B?

    @OneToOne(mappedBy = "a")
    val c: C?

    val name: String
}

@Entity
interface B : SerialId {
    @OneToOne
    val a: A

    val name: String
}
@Entity
interface C : SerialId {
    @OneToOne
    val a: A

    val name: String
}

Code:

sql.executeQuery(B::class) {
            where(table.id eq 1)
            select(
                table.a.fetch(newFetcher(A::class).by {
                    c(fetchType = ReferenceFetchType.JOIN_ALWAYS) {
                        name()
                    }
                }),
            )
        }

Generated SQL

select tb_2_.ID, tb_3_.ID, tb_3_.NAME
from public.B tb_1_
left join public.C tb_3_ on tb_2_.ID = tb_3_.A_ID
where tb_1_.ID = ?
@belovaf belovaf added the bug Something isn't working label Apr 8, 2025
babyfish-ct added a commit that referenced this issue Apr 9, 2025
@babyfish-ct
Copy link
Owner

Try 0.9.73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants