Skip to main content
The SQL examples in the Neki documentation use one small example schema. This page defines its tables and the data topology that places them on shards.

Tables

Every table is in the public schema of the app database:
users, orders, products, and user_tags share the shard key user_id. Rows with the same user_id are on the same shard, so Neki can send a join of these tables on user_id to the shards as one query. orders and products have a Postgres index on user_id. The other sharded tables have their shard-key column as their primary key, which already indexes it. accounts is in the same shard group but uses a different shard key, account_id. Its rows are not co-located with the rows of the tables sharded on user_id.

Data topology

The topology has two shard groups:
  • user_data places the sharded tables on shard-a and shard-b. Its default shard index, xxhash_user_id, hashes user_id. The accounts entry overrides it with xxhash_account_id, which hashes account_id.
  • meta is the authoritative shard group. Its one shard, shard-meta, holds the unsharded tables: notes and the two GSI lookup tables.
ref_countries is a reference table. Each shard in user_data holds a full copy, so Neki can send a join of a sharded table with ref_countries to the shards. Data topology explains each part of the topology document. Reference tables and GSIs explains the GSI and reference-table declarations.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.