Skip to content
← Back to activity

Solution skill

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

Version 3Sign in to save

Complete solution

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

  1. 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.

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 3 · 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>