Skip to content

feat: block cross-shard sharding key updates with ON DELETE#1100

Open
murex971 wants to merge 2 commits into
pgdogdev:mainfrom
murex971:nagrawal-shardfk
Open

feat: block cross-shard sharding key updates with ON DELETE#1100
murex971 wants to merge 2 commits into
pgdogdev:mainfrom
murex971:nagrawal-shardfk

Conversation

@murex971

Copy link
Copy Markdown
Contributor

Description

Block cross-shard sharding key updates when the row is referenced by a foreign key with a destructive ON DELETE action (CASCADE, SET NULL, or SET DEFAULT). Those moves are implemented as DELETE + INSERT, so the delete step could silently affect related rows. PgDog now checks loaded schema metadata before the delete/insert and returns a recoverable error; same-shard updates and ON DELETE RESTRICT / NO ACTION are unchanged.

Testing

cargo nextest run --profile dev test_foreign_key_on_delete_sharding_key_update

 cargo nextest run --profile dev 'frontend::router::parser::rewrite::statement::update::test'

 cargo nextest run --profile dev 'frontend::client::query_engine::multi_step::test'

Related issues/comments

closes #899

@levkk levkk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.31579% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../frontend/client/query_engine/multi_step/update.rs 85.71% 3 Missing ⚠️
...frontend/router/parser/rewrite/statement/update.rs 92.85% 3 Missing ⚠️
...tend/client/query_engine/multi_step/test/update.rs 99.05% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@murex971 murex971 requested a review from levkk June 23, 2026 19:55
self.insert.table.as_ref().map(Table::from)
}

pub(crate) fn sharded_table<'a>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this logic is duplicated, but I could be wrong.

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.

Handle foreign key constraints during sharding key updates

2 participants