vitess

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Vitess

Vitess

Vitess is a MySQL-compatible, cloud-native database system originally built at YouTube to scale MySQL. PlanetScale runs Vitess as a managed service. Core capabilities:
  • Horizontal sharding: Built-in sharding transparent to the application — no sharding logic in app code.
  • Connection pooling: VTGate multiplexes client connections, scaling concurrent connections far beyond native MySQL limits.
  • High availability: Automatic primary failure detection and repair. Resharding and data migrations with near-zero downtime.
  • Query rewriting and caching: VTGate rewrites and optimizes queries before routing to shards.
  • Schema management: Apply schema changes across all shards consistently, in the background, without disrupting workloads.
  • Materialized views and messaging: Cross-shard materialized views and publish/subscribe messaging via VStream.
Vitess是一款兼容MySQL的云原生数据库系统,最初由YouTube开发用于扩展MySQL。PlanetScale将Vitess作为托管服务运行。核心功能:
  • Horizontal sharding:内置分片机制,对应用程序透明,无需在应用代码中实现分片逻辑。
  • Connection pooling:VTGate多路复用客户端连接,可支持的并发连接数远超原生MySQL的限制。
  • High availability:自动检测主节点故障并完成修复。分片重配置和数据迁移几乎不会导致停机。
  • Query rewriting and caching:VTGate在将查询路由到分片前会进行重写和优化。
  • Schema management:在后台跨所有分片一致地应用schema变更,不会中断业务负载。
  • Materialized views and messaging:跨分片物化视图,以及通过VStream实现的发布/订阅消息机制。

Key concepts

Key concepts

ConceptWhat it is
KeyspaceLogical database mapping to one or more shards. Analogous to a MySQL schema.
ShardA horizontal partition of a keyspace, each backed by a separate MySQL instance.
VSchemaConfiguration defining how tables map to shards, vindex (sharding) keys, and routing rules.
VindexSharding function mapping column values to shards (
hash
,
unicode_loose_xxhash
,
lookup
).
VTGateStateless proxy that plans and routes queries to the correct shard(s).
Online DDLNon-blocking schema migrations. On PlanetScale, use deploy requests for production changes.
Concept定义
Keyspace映射到一个或多个分片的逻辑数据库,类似于MySQL的schema。
ShardKeyspace的水平分区,每个分片由独立的MySQL实例提供支持。
VSchema定义表如何映射到分片、vindex(分片键)以及路由规则的配置文件。
Vindex将列值映射到分片的分片函数(如
hash
unicode_loose_xxhash
lookup
)。
VTGate无状态代理,负责规划并将查询路由到正确的分片。
Online DDL无阻塞的schema迁移。在PlanetScale中,生产环境变更需使用部署请求(deploy requests)。

PlanetScale specifics

PlanetScale专属特性

  • Branching: Git-like database branches for development; deploy requests for production schema changes.
  • Connections: MySQL protocol, port
    3306
    (direct) or
    443
    (serverless). SSL always required.
  • Branching:类Git的数据库分支,用于开发环境;生产环境schema变更需通过部署请求完成。
  • Connections:支持MySQL协议,端口为
    3306
    (直连)或
    443
    (无服务器模式)。始终要求SSL加密。

SQL compatibility

SQL兼容性

Vitess supports nearly all MySQL syntax — most applications work without query changes. Standard DML, DDL, joins, subqueries, CTEs (including recursive CTEs as of v21+), window functions, and common built-in functions all work as expected.
Known limitations:
  • Stored procedures / triggers / events: Not supported through VTGate.
  • LOCK TABLES
    /
    GET_LOCK
    : Not supported through VTGate.
  • SELECT ... FOR UPDATE
    : Works within a single shard; cross-shard locking is not atomic.
  • Cross-shard joins: Supported but expensive (scatter-gather). Filter by vindex column for single-shard routing.
  • Correlated subqueries: May fail or perform poorly cross-shard. Rewrite as joins when possible.
  • AUTO_INCREMENT: Sequences are per-shard. Use vindexes or app-generated IDs (UUIDs, snowflake) to avoid collisions on sharded tables.
  • Aggregations on sharded tables:
    GROUP BY
    /
    ORDER BY
    /
    LIMIT
    merge in VTGate memory. Large result sets can be slow.
  • Foreign keys: Limited support. Prefer application-level referential integrity on sharded keyspaces.
Vitess几乎支持所有MySQL语法——大多数应用无需修改查询即可正常运行。标准DML、DDL、连接查询、子查询、CTE(包括v21+版本支持的递归CTE)、窗口函数以及常用内置函数均能按预期工作。
已知限制:
  • 存储过程/触发器/事件:无法通过VTGate使用。
  • LOCK TABLES
    /
    GET_LOCK
    :无法通过VTGate使用。
  • SELECT ... FOR UPDATE
    :在单个分片内可正常工作;跨分片锁不具备原子性。
  • 跨分片连接查询:支持但性能开销大(分散-聚合模式)。建议通过vindex列过滤以实现单分片路由。
  • 关联子查询:跨分片场景下可能执行失败或性能低下。尽可能重写为连接查询。
  • AUTO_INCREMENT:序列按分片独立生成。在分片表上,建议使用vindex或应用生成的ID(如UUID、雪花算法ID)避免冲突。
  • 分片表上的聚合操作
    GROUP BY
    /
    ORDER BY
    /
    LIMIT
    操作在VTGate内存中合并。结果集过大会导致性能缓慢。
  • 外键:支持有限。在分片Keyspace中,建议优先在应用层实现引用完整性。

References

参考资料

TopicReferenceUse for
VSchemareferences/vschema.mdVSchema design, vindexes, sequences, sharding strategies
Schema Changesreferences/schema-changes.mdOnline DDL, managed migrations, ddl strategies, migration lifecycle
VReplicationreferences/vreplication.mdMoveTables, Reshard, Materialize, VDiff, VStream
Architecturereferences/architecture.mdVTGate, VTTablet, Topology Service, VTOrc, component interactions
Query Servingreferences/query-serving.mdQuery routing, MySQL compatibility, cross-shard performance, EXPLAIN
主题参考链接适用场景
VSchemareferences/vschema.mdVSchema设计、vindex、序列、分片策略
Schema变更references/schema-changes.mdOnline DDL、托管迁移、DDL策略、迁移生命周期
VReplicationreferences/vreplication.mdMoveTables、Reshard、Materialize、VDiff、VStream
架构references/architecture.mdVTGate、VTTablet、拓扑服务、VTOrc、组件交互
查询服务references/query-serving.md查询路由、MySQL兼容性、跨分片性能、EXPLAIN