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

feat: support createManyAndReturn #4842

Merged
merged 10 commits into from May 3, 2024
Merged

feat: support createManyAndReturn #4842

merged 10 commits into from May 3, 2024

Conversation

Weakky
Copy link
Member

@Weakky Weakky commented Apr 26, 2024

Overview

Adds a new top-level operation called createManyAndReturn which supports returning the data that was just created. This operation is only exposed when the ConnectorCapability::InsertReturning is present for a connector. That means only Postgres, CockroachDB and SQLite support this new operation.

This bit of work is not preview-feature gated.

Important bits

  • Only inlined to-one relations are exposed on the output types. That is because relations that aren't inlined cannot be created in the first place.
  • When relations are selected, an additional RelatedRead is sent for every single selected relation.
  • relationLoadStrategy: join is not supported.

Schema design

model Parent {
  id Int @id
  name String?

  children Child[]
}

model Child {
  id Int @id
  name String?

  parentId Int?
  parent Parent? @relation(fields: [parentId], references: [id])
}
mutation {
  createManyParentAndReturn(data: [ParentCreateManyInput]): CreateManyParentAndReturnOutputType
  createManyChildAndReturn(data: [ChildCreateManyInput]): CreateManyChildAndReturnOutputType
}

type CreateManyParentAndReturnOutputType {
  id: Int
  name: String
}

type CreateManyChildAndReturnOutputType {
  id: Int
  name: String
  parent: Parent
}

input ParentCreateManyInput {
  # same as `createManyParent`
}

input ParentCreateManyInput {
  # same as `createManyChild`
}

closes: https://github.com/prisma/team-orm/issues/1112

@Weakky Weakky requested a review from a team as a code owner April 26, 2024 13:09
@Weakky Weakky requested review from laplab and removed request for a team April 26, 2024 13:09
Copy link
Contributor

github-actions bot commented Apr 26, 2024

WASM Query Engine file Size

Engine This PR Base branch Diff
Postgres 2.141MiB 2.137MiB 4.022KiB
Postgres (gzip) 842.258KiB 840.811KiB 1.448KiB
Mysql 2.109MiB 2.107MiB 2.485KiB
Mysql (gzip) 828.824KiB 827.978KiB 866.000B
Sqlite 2.002MiB 1.998MiB 4.033KiB
Sqlite (gzip) 789.520KiB 787.576KiB 1.945KiB

Copy link

codspeed-hq bot commented Apr 26, 2024

CodSpeed Performance Report

Merging #4842 will degrade performances by 6.81%

Comparing feat/create-many-and-return (31c187d) with main (264f24c)

Summary

❌ 2 regressions
✅ 9 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main feat/create-many-and-return Change
build (large) 25.9 ms 27.8 ms -6.81%
build (medium) 12.8 ms 13.5 ms -5.35%

Copy link
Contributor

github-actions bot commented Apr 26, 2024

🚀 WASM query-engine performance will improve by 2.66%

Full benchmark report
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/bench?schema=imdb_bench&sslmode=disable" \
node --experimental-wasm-modules query-engine/driver-adapters/executor/dist/bench.mjs
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
cpu: AMD EPYC 7763 64-Core Processor
runtime: node v18.20.2 (x64-linux)

benchmark                   time (avg)             (min … max)       p75       p99      p999
-------------------------------------------------------------- -----------------------------
• movies.findMany() (all - ~50K)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     285 ms/iter       (282 ms … 289 ms)    288 ms    289 ms    289 ms
Web Assembly: Latest       372 ms/iter       (370 ms … 377 ms)    373 ms    377 ms    377 ms
Web Assembly: Current      372 ms/iter       (367 ms … 377 ms)    375 ms    377 ms    377 ms
Node API: Current          196 ms/iter       (195 ms … 196 ms)    196 ms    196 ms    196 ms

summary for movies.findMany() (all - ~50K)
  Web Assembly: Current
   1.9x slower than Node API: Current
   1.3x slower than Web Assembly: Baseline
   1x faster than Web Assembly: Latest

• movies.findMany({ take: 2000 })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline  11'664 µs/iter (11'525 µs … 12'580 µs) 11'661 µs 12'580 µs 12'580 µs
Web Assembly: Latest    15'219 µs/iter (15'066 µs … 16'459 µs) 15'201 µs 16'459 µs 16'459 µs
Web Assembly: Current   15'131 µs/iter (14'937 µs … 16'795 µs) 15'108 µs 16'795 µs 16'795 µs
Node API: Current        8'056 µs/iter   (7'917 µs … 8'414 µs)  8'097 µs  8'414 µs  8'414 µs

summary for movies.findMany({ take: 2000 })
  Web Assembly: Current
   1.88x slower than Node API: Current
   1.3x slower than Web Assembly: Baseline
   1.01x faster than Web Assembly: Latest

• movies.findMany({ where: {...}, take: 2000 })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline   1'831 µs/iter   (1'736 µs … 2'927 µs)  1'816 µs  2'705 µs  2'927 µs
Web Assembly: Latest     2'446 µs/iter   (2'326 µs … 3'954 µs)  2'425 µs  3'705 µs  3'954 µs
Web Assembly: Current    2'400 µs/iter   (2'311 µs … 4'079 µs)  2'392 µs  3'132 µs  4'079 µs
Node API: Current        1'384 µs/iter   (1'288 µs … 1'653 µs)  1'404 µs  1'605 µs  1'653 µs

summary for movies.findMany({ where: {...}, take: 2000 })
  Web Assembly: Current
   1.73x slower than Node API: Current
   1.31x slower than Web Assembly: Baseline
   1.02x faster than Web Assembly: Latest

• movies.findMany({ include: { cast: true } take: 2000 }) (m2m)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     545 ms/iter       (540 ms … 560 ms)    545 ms    560 ms    560 ms
Web Assembly: Latest       807 ms/iter       (797 ms … 825 ms)    824 ms    825 ms    825 ms
Web Assembly: Current      756 ms/iter       (749 ms … 775 ms)    762 ms    775 ms    775 ms
Node API: Current          465 ms/iter       (446 ms … 485 ms)    481 ms    485 ms    485 ms

summary for movies.findMany({ include: { cast: true } take: 2000 }) (m2m)
  Web Assembly: Current
   1.63x slower than Node API: Current
   1.39x slower than Web Assembly: Baseline
   1.07x faster than Web Assembly: Latest

• movies.findMany({ where: {...}, include: { cast: true } take: 2000 }) (m2m)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline  75'837 µs/iter (75'674 µs … 75'973 µs) 75'956 µs 75'973 µs 75'973 µs
Web Assembly: Latest       113 ms/iter       (113 ms … 113 ms)    113 ms    113 ms    113 ms
Web Assembly: Current      106 ms/iter       (106 ms … 106 ms)    106 ms    106 ms    106 ms
Node API: Current       60'308 µs/iter (59'759 µs … 61'218 µs) 60'479 µs 61'218 µs 61'218 µs

summary for movies.findMany({ where: {...}, include: { cast: true } take: 2000 }) (m2m)
  Web Assembly: Current
   1.76x slower than Node API: Current
   1.4x slower than Web Assembly: Baseline
   1.07x faster than Web Assembly: Latest

• movies.findMany({ take: 2000, include: { cast: { include: { person: true } } } })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     969 ms/iter       (958 ms … 988 ms)    982 ms    988 ms    988 ms
Web Assembly: Latest     1'293 ms/iter   (1'281 ms … 1'323 ms)  1'314 ms  1'323 ms  1'323 ms
Web Assembly: Current    1'253 ms/iter   (1'246 ms … 1'268 ms)  1'258 ms  1'268 ms  1'268 ms
Node API: Current          849 ms/iter       (822 ms … 878 ms)    878 ms    878 ms    878 ms

summary for movies.findMany({ take: 2000, include: { cast: { include: { person: true } } } })
  Web Assembly: Current
   1.48x slower than Node API: Current
   1.29x slower than Web Assembly: Baseline
   1.03x faster than Web Assembly: Latest

• movie.findMany({ where: { ... }, take: 2000, include: { cast: { include: { person: true } } } })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     135 ms/iter       (134 ms … 135 ms)    135 ms    135 ms    135 ms
Web Assembly: Latest       180 ms/iter       (179 ms … 182 ms)    180 ms    182 ms    182 ms
Web Assembly: Current      174 ms/iter       (173 ms … 174 ms)    174 ms    174 ms    174 ms
Node API: Current          103 ms/iter       (102 ms … 104 ms)    104 ms    104 ms    104 ms

summary for movie.findMany({ where: { ... }, take: 2000, include: { cast: { include: { person: true } } } })
  Web Assembly: Current
   1.68x slower than Node API: Current
   1.29x slower than Web Assembly: Baseline
   1.04x faster than Web Assembly: Latest

• movie.findMany({ where: { reviews: { author: { ... } }, take: 100 }) (to-many -> to-one)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     864 µs/iter     (816 µs … 1'386 µs)    865 µs  1'333 µs  1'386 µs
Web Assembly: Latest     1'207 µs/iter   (1'133 µs … 1'941 µs)  1'199 µs  1'807 µs  1'941 µs
Web Assembly: Current    1'204 µs/iter   (1'134 µs … 1'915 µs)  1'203 µs  1'764 µs  1'915 µs
Node API: Current          763 µs/iter     (690 µs … 1'022 µs)    787 µs    925 µs  1'022 µs

summary for movie.findMany({ where: { reviews: { author: { ... } }, take: 100 }) (to-many -> to-one)
  Web Assembly: Current
   1.58x slower than Node API: Current
   1.39x slower than Web Assembly: Baseline
   1x faster than Web Assembly: Latest

• movie.findMany({ where: { cast: { person: { ... } }, take: 100 }) (m2m -> to-one)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline     855 µs/iter     (816 µs … 1'369 µs)    857 µs  1'240 µs  1'369 µs
Web Assembly: Latest     1'193 µs/iter   (1'138 µs … 1'527 µs)  1'200 µs  1'485 µs  1'527 µs
Web Assembly: Current    1'191 µs/iter   (1'146 µs … 1'538 µs)  1'195 µs  1'465 µs  1'538 µs
Node API: Current          761 µs/iter     (703 µs … 1'080 µs)    786 µs    937 µs  1'080 µs

summary for movie.findMany({ where: { cast: { person: { ... } }, take: 100 }) (m2m -> to-one)
  Web Assembly: Current
   1.56x slower than Node API: Current
   1.39x slower than Web Assembly: Baseline
   1x faster than Web Assembly: Latest

After changes in 31c187d

@Weakky Weakky added this to the 5.14.0 milestone Apr 26, 2024
@Jolg42
Copy link
Member

Jolg42 commented May 2, 2024

I unlocked the pipeline in Buildkite, there is now an integration PR here prisma/prisma#24060

Jolg42 added a commit to prisma/prisma that referenced this pull request May 2, 2024
@Weakky Weakky merged commit 5446571 into main May 3, 2024
208 of 209 checks passed
@Weakky Weakky deleted the feat/create-many-and-return branch May 3, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants