fix: allow batching of more than one query inside interactive transactions#25571
Conversation
Hi @LucianBuzzo, thanks for this PR! Do you think you can maybe add a few tests for this improvement in https://github.com/prisma/prisma/tree/main/packages/client/tests/functional/batching? You can run tests locally by cd'ing to You can set |
|
@jkomyno No problem, I've added tests to check the base case of batching, and batching with multiple models queried. |
4322bb9 to
d963e26
Compare
587d609 to
87c83a1
Compare
|
@LucianBuzzo could you suggest the easiest way to monkeypatch prisma while this fix is on the way? We're facing a very similar issue with our own graphql+rls server unfortunately… |
|
@SAGV You can see the patching operation here https://github.com/cerebruminc/yates/blob/v3.6.3/src/index.ts#L245 |
|
@LucianBuzzo wow, huge thanks! 👍🏻 👍🏻 👍🏻 I've tried so many things yesterday trying to figure out why the batching is broken inside transactions… The patch has just made our graphql requests 10x faster! @aqrln even if there are 2 queries, it's still insanely faster… |
…tions Fixes: prisma#25570 This change fixes an issue where running different queries inside an interactive transaction in the same tick would not be batched together automatically by the engine. By accounting for the protocolQuery when batching interactive transactions, the engine can optimize the queries correctly, as the queries will be batched by both the transaction ID and the query.
c2fd912 to
4e9c491
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRequestHandler.batchBy now groups interactive-transaction (itx) requests using a batch identifier derived from protocolQuery; test schema adds a Comment model and tests are extended to instrument and assert engine batching behavior for interactive transactions (PostgreSQL-only). Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4f9b6d9 to
f2d25c3
Compare
Co-authored-by: jacek-prisma <malec@prisma.io>
…tions (#25571) Fixes: #25570 This change fixes an issue where running different queries inside an interactive transaction in the same tick would not be batched together automatically by the engine. By accounting for the protocolQuery when batching interactive transactions, the engine can optimize the queries correctly, as the queries will be batched by both the transaction ID and the query. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Batching for interactive transactions now groups requests by transaction and protocol batch identifier when available for more precise execution. * **Database** * Added a Comment model and a comments relation on User for test scenarios. * **Tests** * Expanded interactive-transaction batching tests with detailed engine/batch metrics and PostgreSQL-only scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: jacek-prisma <malec@prisma.io>

Fixes: #25570
This change fixes an issue where running different queries inside an interactive transaction in the same tick would not be batched together automatically by the engine.
By accounting for the protocolQuery when batching interactive transactions, the engine can optimize the queries correctly, as the queries will be batched by both the transaction ID and the query.
Summary by CodeRabbit
Improvements
Database
Tests