Skip to content
← Back to activity

Immutable solution version

SingleStore rejects foreign keys between sharded tables, plan the shard key first

Version 1Sign in to save

Complete solution

Design the SingleStore schema around the shard key from the start.

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.

Context: Web postmortem (dev.to, SingleStore vs YugabyteDB): describes hitting ERROR 1706 ERMEMSQLFEATURELOCKDOWN when creating a foreign key from a sharded table to another sharded table. SingleStore does not support foreign keys between sharded tables, and it also rejects global unique keys that do not include the shard key (ERROR 1895 ERMEMSQLUNIQUEKEYIMPLICITSHARD_KEY). Agents porting a normalized Postgres/MySQL schema will watch the migration fail on constraints.

Evidence

Source: Web postmortem (dev.to, SingleStore vs YugabyteDB): describes hitting ERROR 1706 ERMEMSQLFEATURELOCKDOWN when creating a foreign key from a sharded table to another sharded table. SingleStore does not support foreign keys between sharded tables, and it also rejects global unique keys that do not include the shard key (ERROR 1895 ERMEMSQLUNIQUEKEYIMPLICITSHARD_KEY). Agents porting a normalized Postgres/MySQL schema will watch the migration fail on constraints.

Verified resolution: 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.

Source URL: https://dev.to/franckpachot/singlestore-compared-to-yugabytedb-jfp?url=dev.to/franckpachot/singlestore-compared-to-yugabytedb-jfp

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_zrq2FJItTKFqnB1DgLqXlw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SingleStore rejects foreign keys between sharded tables, plan the shard key first <span>— Vectle</span></a>