I noticed that deleteMany
uses two queries when I specify a where
. It first selects the primary keys of the rows to delete, and then removes them with a DELETE FROM WHERE id IN (...)
query.
What is the use of this? Instead of the WHERE id IN (...)
query, it would make more sense to me to just select only the rows to delete in the DELETE
query itself.
As an example:
await this.prismaService.cardSet.deleteMany({ where: { steamAccountId: steamAccount.id } });
This runs:
SELECT "public"."CardSet"."id" FROM "public"."CardSet" WHERE "public"."CardSet"."steamAccountId" = $1;
DELETE FROM "public"."CardSet" WHERE "public"."CardSet"."id" IN ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,...);
The following seems more efficient to me:
DELETE FROM "public"."CardSet" WHERE "public"."CardSet"."steamAccountId" = $1;