why prisma do lots of unrelated queries on updatin...
# mongodb
p
why prisma do lots of unrelated queries on updating a single field?
Copy code
Prisma.user.update({
  where: {
    id,
  },
  data: {
    name: newName
  }
});
results in lots of additional requests like
Copy code
prisma:query db.AuthTokens.aggregate([ { $match: { $expr: { $and: [ { }, { $and: [ { $in: [ "$userId", [ "62530b0f4556cced19ce20c8", ], ], }, { $or: [ { $ne: [ { $ifNull: [ "$userId", null, ], }, null, ], }, { $eq: [ "$userId", null, ], }, ], }, ], }, ], }, }, }, { $project: { _id: 1, userId: 1, }, }, ])
prisma:query db.Posts.aggregate([ { $match: { $expr: { $and: [ { }, { $and: [ { $in: [ "$userId", [ "62530b0f4556cced19ce20c8", ], ], }, { $or: [ { $ne: [ { $ifNull: [ "$userId", null, ], }, null, ], }, { $eq: [ "$userId", null, ], }, ], }, ], }, ], }, }, }, { $project: { _id: 1, userId: 1, }, }, ])
I have one extra aggregation per every related collections. What's the purpose of that? Feels like it just slows the DB with no reason.
j
Prisma is currently optimized to return the correct data, not to use the optimal query to do that.
For Prisma Client queries where you have additional, unexpected queries under the hood, just open an issue and we will get to that sooner or later when we are happy that most queries are correct and we want to start to optimize performance.
(Sometimes the issue also tells us that we are doing stupid things and need to fix this asap)