All skills
planetscale avatar

/vitess

@51f2d4b official

Vitess best practices, query optimization, and connection troubleshooting for PlanetScale Vitess databases. Load when working with Vitess databases, sharding, VSchema configuration, keyspace management, or MySQL scaling issues.

Use this Skill: https://skilld.dev/gh/planetscale/database-skills/vitess

This session only. Nothing lands on disk.

referencesvschema.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

VSchema Design and Configuration

Contents

The VSchema (Vitess Schema) tells VTGate how to route queries. It defines how tables map to keyspaces/shards, which columns determine shard placement (vindexes), and how tables relate across shards.

Reference: https://vitess.io/docs/23.0/user-guides/vschema-guide/

VSchema structure

{ "sharded": true, "vindexes": { ... }, "tables": { ... } }

For unsharded keyspaces: { "tables": { "product": {}, "my_seq": { "type": "sequence" } } }

Vindexes

A vindex maps a column value to a keyspace ID (determines shard placement). Every sharded table needs a Primary Vindex which must be unique and is immutable after insert.

Vindex Type Use For
xxhash Any column type (most common)
unicode_loose_xxhash Text columns needing case-insensitive hashing
binary_md5 Any column type (MD5-based alternative)

Choosing a primary vindex column: pick the column most used in high-QPS WHERE clauses, that enables join co-location (tables joined frequently should shard on the same column), keeps transactions single-shard, and has high cardinality for even distribution.

Example

{
  "sharded": true,
  "vindexes": { "xxhash": { "type": "xxhash" } },
  "tables": {
    "customer": { "column_vindexes": [{ "column": "customer_id", "name": "xxhash" }] },
    "orders":   { "column_vindexes": [{ "column": "customer_id", "name": "xxhash" }] }
  }
}

Both tables shard on customer_id (shared vindex), so rows with the same customer_id land on the same shard, enabling single-shard joins and transactions.

Lookup vindexes

Provide secondary routing to avoid scatter queries on non-primary-vindex columns. Backed by a separate lookup table mapping column values to keyspace IDs. Lookup vindexes are expensive — consider schema redesign or alternative access patterns before using.

"customer_email_lookup": {
  "type": "consistent_lookup",
  "params": { "table": "product.customer_email_lookup", "from": "email", "to": "keyspace_id" },
  "owner": "customer"
}

Use consistent_lookup (or consistent_lookup_unique if strictly needed, though database-level uniqueness enforcement is a scalability anti-pattern). The owner table maintains the lookup. Backfill existing data with vtctldclient LookupVindex create ... (see vtctldclient LookupVindex --help for required args).

Sequences

Replace MySQL AUTO_INCREMENT for sharded tables (per-shard auto-increment produces duplicates). A sequence is a single-row table in an unsharded keyspace.

CREATE TABLE customer_seq (id BIGINT, next_id BIGINT, cache BIGINT, PRIMARY KEY (id)) COMMENT 'vitess_sequence';
INSERT INTO customer_seq (id, next_id, cache) VALUES (0, 1, 1000);

Register in unsharded VSchema: { "customer_seq": { "type": "sequence" } }

Link to sharded table:

"customer": {
  "column_vindexes": [{ "column": "customer_id", "name": "xxhash" }],
  "auto_increment": { "column": "customer_id", "sequence": "product.customer_seq" }
}

Sequence gaps from caching/restarts are expected and harmless.

Discovering existing VSchema

Retrieve the current VSchema for a keyspace via CLI or SQL:

# Full VSchema JSON for a keyspace
vtctldclient GetVSchema <keyspace>

# List all vindexes defined in a keyspace
vtctldclient GetVSchema <keyspace> | jq '.vindexes'
-- From a VTGate MySQL session
SHOW VSCHEMA TABLES;           -- list tables known to the VSchema
SHOW VSCHEMA VINDEXES;         -- list vindexes and their types
SHOW CREATE TABLE <table>;     -- includes vindex column info in comments

Use SHOW VSCHEMA TABLES to quickly confirm whether a table is recognized by VTGate routing. Use GetVSchema for the full JSON when you need to inspect vindex params, sequences, or advanced properties.

Sharding guidelines

Optimal shard size depends on hardware (CPUs, RAM, disk I/O) and workload characteristics — there is no universal number. Highest-QPS query's WHERE clause dictates primary vindex. Co-locate joined tables; keep transactions local. For multi-tenant apps, use multi-column vindexes. MoveTables can change sharding keys later.

Advanced properties

auto_increment (link to sequence), type: "reference" (copied to all shards), pinned (pin to shard), column_list_authoritative (planner only trusts columns explicitly listed in VSchema).

Troubleshooting scatter queries

Check: is WHERE filtering on primary vindex? Is a lookup vindex configured for that column? Use VEXPLAIN PLAN to see routing. For deeper performance debugging, use VEXPLAIN ALL to include MySQL query plans and VEXPLAIN TRACE to see metrics on how many rows are passed between parts of the query. Primary vindex column updates are blocked; use MoveTables to re-shard.

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides comprehensive documentation and best practices for Vitess and PlanetScale databases. It consists entirely of informational markdown files without executable scripts, dependencies, or network operations outside of referencing official vendor resources.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    5/6 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 51f2d4b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 7 months ago
Other metadata
metadata
{
  "author": "planetscale",
  "version": "1.0.0",
  "organization": "PlanetScale",
  "date": "February 2026"
}
  • Database
  • vitess
  • planetscale
  • mysql
  • sharding
  • vschema
  • connection-pooling
  • schema-migrations

README badge

README badge for planetscale/database-skills/vitess

Guides query routing, sharding strategy, schema migration, and MySQL compatibility for Vitess databases on PlanetScale. Covers VSchema configuration, keyspace management, cross-shard query performance, and Online DDL workflows.

Generated from the current SKILL.md.

Does Vitess support stored procedures and triggers?
No. Stored procedures, triggers, and events are not supported through VTGate. Application logic must handle these operations.
What should I use for generating IDs on sharded tables?
Use Vitess Sequences (a global counter in an unsharded keyspace) or app-generated IDs like UUIDs or snowflakes to avoid collisions across shards.
Are cross-shard joins supported?
Yes, but they are expensive scatter-gather operations. Filter by the vindex column to force single-shard routing and avoid cross-shard joins when possible.
How do I apply schema changes in production on PlanetScale?
Use PlanetScale deploy requests, which implement non-blocking Online DDL migrations across all shards without disrupting workloads.
Does Vitess support foreign keys?
Foreign keys have limited support in Vitess. Prefer application-level referential integrity checks on sharded keyspaces.

Generated from the current SKILL.md. These answers refresh after source changes.