内核 复用真实 PG 查询层 —— 迁移成本最低的分布式 PG
- 一句话
- YSQL 直接复用 PostgreSQL 的查询层代码(不是重写)——pl/pgSQL、触发器、扩展的兼容度在分布式 SQL 里最高;"PG 特性用得多、又要水平扩展"的唯一答案。YSQL reuses the PostgreSQL query-layer source code directly (not a rewrite) — the highest compatibility in distributed SQL for pl/pgSQL, triggers, and extensions; the only answer when "heavy PG feature usage meets horizontal scale".
- 窄场景
- 重度使用 PG 特性(存储过程、触发器、PostGIS/pgvector 等扩展)的应用要水平扩展;不接受"重写 SQL 层"迁移方案的团队。Applications heavily using PG features (stored procedures, triggers, extensions like PostGIS/pgvector) that need horizontal scaling; teams that reject "rewrite the SQL layer" migration plans.
- 机制
- 双 API 架构:YSQL(PG 兼容)复用上游 PG 查询层源码,DocDB 是自研的分布式文档存储(tablet 分片、Raft 复制)。查询计划、优化器行为、pl/pgSQL 语义都来自真正的 PG 代码,而非"看起来像 PG"的重写——这是与 CockroachDB(自研 SQL 层、线路级兼容)的本质区别。官方承诺上游 PG 大版本发布后 6 个月内完成 rebase(已到 PG15)。Dual-API architecture: YSQL (PG-compatible) reuses the upstream PG query-layer source, while DocDB is a homegrown distributed document store (tablet sharding, Raft replication). Query plans, optimizer behavior, and pl/pgSQL semantics come from genuine PG code, not a "looks like PG" rewrite — the essential difference from CockroachDB (homegrown SQL layer, wire-level compatibility). The official commitment is rebasing within 6 months of each upstream PG major release (already at PG15).
- 生产验证
- 独立架构解析:第三方工程师拆解 DocDB 存储、tablet 分裂与双 API 架构,确认查询层复用路线的实现细节(https://letsbuildsolutions.com/blog/system-design/how-yugabytedb-works-internally-docdb-storage-tablet-splitting-and-the-dual-api-architecture-that-scales-postgresql-horizontally/)。诚实备注:独立项目 pidgeiot 记录 Kratos(Ory 身份系统)官方支持列表里没有 YugabyteDB,其迁移曾死于 ALTER TABLE…ALTER COLUMN TYPE(PG15 rebase 后已支持)——"兼容 PG"不等于"被 PG 生态承认"(https://github.com/justins-engineering/pidgeiot/blob/HEAD/docs/infra/postgres-consolidation.md)。An independent architecture teardown: a third-party engineer dissected DocDB storage, tablet splitting, and the dual-API architecture, confirming how the query-layer reuse is implemented (https://letsbuildsolutions.com/blog/system-design/how-yugabytedb-works-internally-docdb-storage-tablet-splitting-and-the-dual-api-architecture-that-scales-postgresql-horizontally/). Honest note: the independent project pidgeiot records that Kratos (Ory identity system) doesn't list YugabyteDB as officially supported, and its migration once died on ALTER TABLE…ALTER COLUMN TYPE (supported after the PG15 rebase) — "PG compatible" is not "acknowledged by the PG ecosystem" (https://github.com/justins-engineering/pidgeiot/blob/HEAD/docs/infra/postgres-consolidation.md).
- 竞品差距
- CockroachDB 自研 SQL 层,兼容停在"线路 + 常用方言"层,触发器/扩展是短板;TiDB 是 MySQL 线路,PG 用户无关。反之只用标准 SQL+ORM 的团队,CockroachDB 的顺滑度可能更高。CockroachDB's homegrown SQL layer keeps compatibility at the "wire + common dialect" level, with triggers/extensions as weaknesses; TiDB speaks the MySQL protocol, irrelevant to PG users. Conversely, teams using only standard SQL+ORM may find CockroachDB smoother.
- 证据等级
- 独立架构解析 + 官方博客(rebase 承诺可验证)Independent architecture teardown + official blog (the rebase commitment is verifiable)
- 最后核验
- 2026-10-012026-10-01