fix: allow omnisharded reads with a shard directive inside transactions - #1510
Merged
levkk merged 2 commits intoSep 10, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
rlittlefield
force-pushed
the
omni-read-with-directive-in-tx
branch
from
September 9, 2026 16:41
ece8532 to
be05e4d
Compare
rlittlefield
force-pushed
the
omni-read-with-directive-in-tx
branch
from
September 9, 2026 21:30
cd57575 to
3858dc2
Compare
rlittlefield
force-pushed
the
omni-read-with-directive-in-tx
branch
from
September 10, 2026 14:31
3858dc2 to
0f66203
Compare
rlittlefield
marked this pull request as ready for review
September 10, 2026 14:34
levkk
approved these changes
Sep 10, 2026
levkk
left a comment
Collaborator
There was a problem hiding this comment.
Got to love PRs where number of test lines exceeds the actual change by a factor of 10. Thank you sir!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A plain SELECT from an omnisharded table inside a read/write transaction failed with cannot write to an omnisharded table with a shard directive whenever a directive was present, whether
/* pgdog_shard */,/* pgdog_sharding_key */, orSET pgdog.shard. The guard usedRoute::is_write()to decide whether a statement mutates, but under the conservative read/write strategy every statement in a read/write transaction is marked a write so it runs on the primary. Any application that keys its transactions and reads a replicated table inside one hit this on a multi-shard cluster.Route now carries a statement-intrinsic mutates flag: DML, DDL, data-modifying CTEs, locking clauses, write functions and advisory locks. The omnisharded coverage check uses it; read is unchanged and still drives primary/replica placement. The guard is per statement, so a later omni write in the same pinned transaction is still rejected.
This finishes the fix for #1374. #1384 and #1398 diagnosed the same false positive and relaxed the check when schema sharding is used exclusively, leaving the mixed
sharded_schemas+sharded_tablescase for later ("the error will still throw ... I also added a test for that for later"). Scoping the exemption by statement kind instead of by config covers that case: a plain read of a pinned shard is correct whether the table is omnisharded or schema-sharded. The "invalid cases" test inintegration/rust/tests/integration/cross_shard_omni_check.rs, which asserted the pinned read fails, now checks the read succeeds and that an INSERT into an omnisharded table in the same pinned transaction is still rejected.Covered by parser and route unit tests plus engine tests against Postgres for reads inside pinned transactions.