Skip to content

deleteMany optimisation #8239

Closed
prisma/prisma-engines
#4249

Description

@ryands17

Problem

Currently deleteMany fetches the rows to be deleted and then deletes the rows that results in two queries. Probably this was implemented due to cascade deletes not working.

Suggested solution

deleteMany should use only a single query that deletes the specified items.

Additional context

Related discussion: #8211

Activity

  1. ecker00 commented on Jan 14, 2023

    @ecker00

    Any updates on this? Notice that it's rather slow to end up running a raw query instead.

  2. baptisteArno commented on Feb 16, 2023

    @baptisteArno

    Is there already someone working on this? I'd be willing to contribute! Or would it be too complicated?

  3. tbell511 commented on Apr 1, 2023

    @tbell511

    Are there any updates on this?

  4. Jacse commented on May 8, 2023

    @Jacse

    This is a crazy way to implement a delete with a filter. If I want to delete a lot of rows, it will run out of memory and crash. Why would the client want to fetch all that data to only pick the ids and run a query that could as easily have been run directly with the where clauses?

  5. njpearman commented on Aug 2, 2023

    @njpearman

    +1 on the Prisma team addressing this ASAP. Our app had OOMs and timeouts for very large batch deletes because Prisma hauls back all of the rows that need to be deleted to then use in an IN clause when it just needs a filtered DELETE command. I have to say the current approach is a bonkers bad way of doing a filtered DELETE for any large amount of data. In the mean time, we're using prisma.$executeRaw.

  6. added this to the 5.4.0 milestone on Sep 29, 2023
  7. Jolg42 commented on Oct 9, 2023

    @Jolg42
    Contributor

    The optimization is now available since 5.4.0, for more details check out the bottom part of the release notes:
    https://github.com/prisma/prisma/releases/tag/5.4.0

    Screenshot 2023-10-09 at 10 33 07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions