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

fix: count & orderBy on one2m with multiple fks #2145

Merged
merged 3 commits into from Aug 12, 2021

Conversation

Weakky
Copy link
Member

@Weakky Weakky commented Aug 11, 2021

Overview

Fixes prisma/prisma#7299
Fixes prisma/prisma#7331

This PR also fixes an orderByRelation issue (7331 above) which is using the compute_one2m_join function that I batched fixed in this PR as the root cause was exactly the same as the count aggregation one.

Changes

LEFT JOIN in charge of computing the count aggregation changes from (pseudo-sql):

  LEFT JOIN (
      SELECT fk_1, fk_2, COUNT(*) FROM ... GROUP BY fk_1, fk_2
  ) AS aggr ON (
    fk_1 = "aggr"."fk1",
    fk_2 = "aggr"."fk2"
  )

to:

  LEFT JOIN (
      SELECT fk_1, fk_2, COUNT(*) FROM ... GROUP BY fk_1, fk_2
  ) AS aggr ON (
    fk_1 = "aggr"."fk1" AND
    fk_2 = "aggr"."fk2"
  )

@Weakky Weakky added this to the 2.30.0 milestone Aug 11, 2021
@Weakky Weakky changed the title fix: count on one2m with multiple fks fix: count & orderBy on one2m with multiple fks Aug 11, 2021
@Weakky Weakky merged commit 6a90cd8 into master Aug 12, 2021
@Weakky Weakky deleted the fix/rel-count-one2m-many-fks branch August 12, 2021 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants