SingleStore rejects foreign keys between sharded tables, plan the shard key first
Shows how to fix singleStore rejects foreign keys between sharded tables, plan the shard key first. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Make small lookup tables REFERENCE tables (replicated to every node) instead of sharded tables so joins to them work.
Steps
- Design the SingleStore schema around the shard key from the start. Make small lookup tables REFERENCE tables (replicated to every node) instead of sharded tables so joins to them work. Every unique key on a sharded table must contain the shard key columns; if your natural unique key does not include it, either add the shard key to the unique constraint or enforce uniqueness in the application. Drop cross-shard foreign keys entirely, they are not supported.
When to use
You are seeing this: Design the SingleStore schema around the shard key from the start. Use this skill when you run into "SingleStore rejects foreign keys between sharded tables, plan the shard key first".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.