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

Update operation includes multiple where statements for the same fields #16864

Closed
dev-ish opened this issue Dec 16, 2022 · 2 comments · Fixed by prisma/prisma-engines#4084
Closed
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: performance/queries topic: postgresql topic: $transaction Related to .$transaction(...) Client API
Milestone

Comments

@dev-ish
Copy link

dev-ish commented Dec 16, 2022

Bug description

When triggering the update on the prisma model inside an transaction, it will run 3 queries where only 2 should be necessary. And the update query contains multiple where statements for the same field

Returned queries from log

SELECT "public"."table_name"."id" WHERE ("public"."table_name"."id" = $1 AND 1=1)
UPDATE "public"."table_name" SET "status" = $1, "updatedAt" = $2 WHERE ("public"."table_name"."id" IN ($3) AND ("public"."table_name"."id" = $4 AND 1=1))
SELECT * FROM "public"."table_name" WHERE "public"."table_name"."id" = $1 LIMIT $2 OFFSET $3

How to reproduce

prisma.$transaction(tx => {
        tx.modelName.update({
          where: {
            id: "id",
          },
          data: {
            status: to,
          },
        })
      })

Expected behavior

When update is triggered i would expect 2 queries to have been executed. And the update query to only contain the where statement provided

UPDATE "public"."table_name" SET "status" = $1, "updatedAt" = $2 WHERE  ("public"."table_name"."id" = $3 AND 1=1))
SELECT * FROM "public"."table_name" WHERE "public"."table_name"."id" = $1 LIMIT $2 OFFSET $3

Prisma information

enum EnumStatus {
  NEW
  PENDING
}

model ModelName {
  id         String                   @id @default(dbgenerated("uuid_generate_v1()")) @db.Uuid
  status     EnumStatus     @default(NEW)
  createdAt  DateTime                 @default(now())
  updatedAt  DateTime?                @updatedAt

  @@map(name: "table_name")
}
prisma.modelName.update({
        where: {
          id: "id",
        },
        data: {
          status: "PENDING",
        },
      })

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v16.17.1

Prisma Version

prisma                  : 4.7.1
@prisma/client          : 4.7.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 272861e07ab64f234d3ffc4094e32bd61775599c (at ../../node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 272861e07ab64f234d3ffc4094e32bd61775599c (at ../../node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 272861e07ab64f234d3ffc4094e32bd61775599c (at ../../node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 272861e07ab64f234d3ffc4094e32bd61775599c (at ../../node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.1-1.272861e07ab64f234d3ffc4094e32bd61775599c
Default Engines Hash    : 272861e07ab64f234d3ffc4094e32bd61775599c
Studio                  : 0.477.0
Preview Features        : tracing, postgresqlExtensions
@dev-ish dev-ish added the kind/bug A reported bug. label Dec 16, 2022
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: $transaction Related to .$transaction(...) Client API topic: postgresql topic: performance/queries labels Dec 16, 2022
@mcbethio mcbethio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Feb 15, 2023
@mcbethio
Copy link

I have a confirmed reproduction in 4.10.1

@Weakky
Copy link
Member

Weakky commented Aug 1, 2023

Hey, this should be now available for Postgres & CockroachDB on the latest Prisma 5.1. Have a look at the release notes for more information! Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: performance/queries topic: postgresql topic: $transaction Related to .$transaction(...) Client API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants