技巧

Notion 实现 PostgreSQL 查询流水线提升性能

精选理由

Notion 工程师分享了他们如何通过 PostgreSQL 查询流水线将性能提升 50%,具体代码示例很实用。

Notion 工程师 Jake 实现了 PostgreSQL 扩展查询协议流水线技术。该技术将查询网络往返次数从 N 次减少到 1 次(读)或 2 次(写)。

正文

Notion 的查询性能因此提升了约 50%。Notion 在事务中运行大量查询,配合 pgbouncer 事务池使用效果更佳。

原文 · Akshay Kothari

i enjoy posting about new features. i enjoy posting about performance improvement more. Jake 🎉 @jitl implemented postgres extended query protocol pipelining, makes queries at notion go about 50% faster why? notion runs many queries in transactions so we can use pgbouncer txn pooling + SET LOCAL; many reads look like this: await query(sql`BEGIN; SET LOCAL search_path = ...`) const result = await query(sql`SELECT ...`) // rare txns sometimes do more reads await query(sql`COMMIT`) pipelining which reduces network round trips from N → 1 for reads and N → 2 for writes (tho maybe its fine to pipeline COMMIT there also) const results = await query(new ExtendedQueryPipeline([ sql`BEGIN`, sql`SET LOCAL ...`, sql`SELECT ...`, sql`COMMIT`, ])) 🔗 View Quoted Tweet📊 4 ⚡

产业坐标与信源核验

本条情报归属 AITOP「技巧」核心栏目,重点聚焦北美前沿实验室与硅谷科技巨头。在跨区域产业观察坐标中,该动态直接关联「AI 开发者工具链、Coding Agent 与工程化实践」研究主线,反映出当前技术演进与商业落地的最新风向。涉及核心实体与技术议题包括:PostgreSQL、Notion、查询优化、性能提升,读者可通过下方标签进入对应专题页查阅历史脉络与关联对比。

信源核验说明:本文原始线索采编自「Akshay Kothari」(@akothari),经 AITOP 多维评分管线结构化提炼。