Make the top-L client diff cost depend on what changed, not on the limit
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Problem
For a query with ORDER BY … LIMIT L, every write that touches the window rebuilds the client's whole top-L list and compares it with the previous one to find what changed. That costs O(L) per write, even though a single-row write usually moves only one or two rows in or out of the top L.
For example, on a newest-first feed with LIMIT 200, each new row means copying and comparing about 400 keys just to send the client one add and one delete. Writes that land in the buffer below the top L pay the same cost and end up sending nothing.
On busy feeds this adds up, and since the engine is single-threaded, it slows every other table too.
Proposal
The window already keeps its rows in sorted order, so it can work out the change from the position where the write landed:
- Inserted inside the top L: add it, and remove the row it pushed out.
- Removed from inside the top L: remove it, and add the row that moves up.
- Updated in place: pass the update through.
- Inserted or removed below the top L: nothing to send.
This works the same for ASC and DESC. Rarer cases keep using today's full comparison, so correctness never depends on the new path: several changes in one step, a storage read landing many rows, and pages filtered through a join condition.
The messages sent to the client must stay exactly as they are today.
Testing
- A randomized test that runs the old and new diff on the same writes and checks they produce identical output.
- A benchmark of a feed with steady inserts at different limits. Today's cost should grow with L; after the change it should stay flat.
- 主要语言
- Rust
- 星标
- 129
- 派生
- 7
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
juspay/streamgres 的其他 Issue
-
Query optimisation: share initial snapshots across LIMIT variants of the same query (donor windows)可能已有人在做 @sprihaanand-juspay 于 3 天前认领。 未关闭
juspay/streamgres#58 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 4/5 一周以上 新手友好度 38/100
juspay/streamgres#56 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
juspay/streamgres#55 ·
维护者通常 1 天内回复
-
PgBouncer transaction pooling: `prepare` runs outside the read transaction and can land on another backend可能已有人在做 @sprihaanand-juspay 于 6 天前认领。 未关闭
juspay/streamgres#53 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
juspay/streamgres#49 ·
维护者通常 1 天内回复
查看 juspay/streamgres 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
area: settings bug Haiku review: no-score ui
难度 2/5 1-3 小时 新手友好度 78/100
MMFoundation/WallpaperMachine#346 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
rubys/roundhouse#2473 ·
-
bug mod: quantum info
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复