vitess
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVitess
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
| Concept | What it is |
|---|---|
| Keyspace | Logical database mapping to one or more shards. Analogous to a MySQL schema. |
| Shard | A horizontal partition of a keyspace, each backed by a separate MySQL instance. |
| VSchema | Configuration defining how tables map to shards, vindex (sharding) keys, and routing rules. |
| Vindex | Sharding function mapping column values to shards ( |
| VTGate | Stateless proxy that plans and routes queries to the correct shard(s). |
| Online DDL | Non-blocking schema migrations. On PlanetScale, use deploy requests for production changes. |
| Concept | 定义 |
|---|---|
| Keyspace | 映射到一个或多个分片的逻辑数据库,类似于MySQL的schema。 |
| Shard | Keyspace的水平分区,每个分片由独立的MySQL实例提供支持。 |
| VSchema | 定义表如何映射到分片、vindex(分片键)以及路由规则的配置文件。 |
| Vindex | 将列值映射到分片的分片函数(如 |
| 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 (direct) or
3306(serverless). SSL always required.443
- Branching:类Git的数据库分支,用于开发环境;生产环境schema变更需通过部署请求完成。
- Connections:支持MySQL协议,端口为(直连)或
3306(无服务器模式)。始终要求SSL加密。443
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: Not supported through VTGate.GET_LOCK - : Works within a single shard; cross-shard locking is not atomic.
SELECT ... FOR UPDATE - 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 BYmerge in VTGate memory. Large result sets can be slow.LIMIT - Foreign keys: Limited support. Prefer application-level referential integrity on sharded keyspaces.
Vitess几乎支持所有MySQL语法——大多数应用无需修改查询即可正常运行。标准DML、DDL、连接查询、子查询、CTE(包括v21+版本支持的递归CTE)、窗口函数以及常用内置函数均能按预期工作。
已知限制:
- 存储过程/触发器/事件:无法通过VTGate使用。
- /
LOCK TABLES:无法通过VTGate使用。GET_LOCK - :在单个分片内可正常工作;跨分片锁不具备原子性。
SELECT ... FOR UPDATE - 跨分片连接查询:支持但性能开销大(分散-聚合模式)。建议通过vindex列过滤以实现单分片路由。
- 关联子查询:跨分片场景下可能执行失败或性能低下。尽可能重写为连接查询。
- AUTO_INCREMENT:序列按分片独立生成。在分片表上,建议使用vindex或应用生成的ID(如UUID、雪花算法ID)避免冲突。
- 分片表上的聚合操作:/
GROUP BY/ORDER BY操作在VTGate内存中合并。结果集过大会导致性能缓慢。LIMIT - 外键:支持有限。在分片Keyspace中,建议优先在应用层实现引用完整性。
References
参考资料
| Topic | Reference | Use for |
|---|---|---|
| VSchema | references/vschema.md | VSchema design, vindexes, sequences, sharding strategies |
| Schema Changes | references/schema-changes.md | Online DDL, managed migrations, ddl strategies, migration lifecycle |
| VReplication | references/vreplication.md | MoveTables, Reshard, Materialize, VDiff, VStream |
| Architecture | references/architecture.md | VTGate, VTTablet, Topology Service, VTOrc, component interactions |
| Query Serving | references/query-serving.md | Query routing, MySQL compatibility, cross-shard performance, EXPLAIN |
| 主题 | 参考链接 | 适用场景 |
|---|---|---|
| VSchema | references/vschema.md | VSchema设计、vindex、序列、分片策略 |
| Schema变更 | references/schema-changes.md | Online DDL、托管迁移、DDL策略、迁移生命周期 |
| VReplication | references/vreplication.md | MoveTables、Reshard、Materialize、VDiff、VStream |
| 架构 | references/architecture.md | VTGate、VTTablet、拓扑服务、VTOrc、组件交互 |
| 查询服务 | references/query-serving.md | 查询路由、MySQL兼容性、跨分片性能、EXPLAIN |