Non-deterministic pagination in /api/v2/search when rows share the same timestamp
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- clickhouse, typescript
调研方向
从 POST /api/v2/search 端点的实现开始,跟踪应用 Timestamp 排序和 LIMIT/OFFSET 分页的 ClickHouse 查询。验证 _block_number 和 _block_offset 的相关表设置,然后检查端点现有的测试,或补充针对相同 timestamps 的覆盖。连续页面具有确定性排序,且没有跳过或重复行,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Problem
The POST /api/v2/search endpoint (added in [hyperdxio/hyperdx#2258](https://github.com/hyperdxio/hyperdx/pull/2258)) uses LIMIT/OFFSET pagination with results ordered by Timestamp. When multiple rows share the same timestamp, pagination becomes non-deterministic -- rows near a page boundary can be duplicated or skipped across pages.
Example: If rows 90-110 all have the same Timestamp value and the client requests maxResults=100, offset=0 followed by maxResults=100, offset=100, ClickHouse arbitrarily assigns which rows fall on which page. The client may see some rows twice and miss others entirely.
Why this happens in practice
While Timestamp is DateTime64(9) (nanosecond precision), duplicate timestamps are common in real-world OTEL pipelines:
- Collector-assigned timestamps: When logs arrive at the OTEL collector without a timestamp, the collector assigns one. An entire batch receives the same timestamp.
- Limited source precision: Many language runtimes only produce microsecond or millisecond precision. The remaining digits are zero-padded, reducing the effective keyspace.
- High-throughput services: Multiple log lines from the same flush, HTTP request, or function call naturally share the same wall-clock time.
Adding search predicates reduces the likelihood (fewer matching rows means fewer ties), but the issue is still possible in any high-volume deployment.
Proposed solution
For tables with enable_block_number_column = 1 and enable_block_offset_column = 1 (which ClickStack already enables on otel_logs), add _block_number and _block_offset as tiebreaker columns in the ORDER BY clause:
ORDER BY Timestamp DESC, _block_number DESC, _block_offset DESC
LIMIT {maxResults} OFFSET {offset}
This produces a deterministic total ordering since (_block_number, _block_offset) uniquely identifies each row within a part. The additional columns should have negligible performance impact when using read_in_order.
Alternatives considered
- Cursor-based pagination (filter by
WHERE Timestamp < :last_seen): Avoids offset entirely but still non-deterministic when ties exist at the cursor boundary. Would also require a tiebreaker. - Nanosecond precision alone: Reduces probability but does not eliminate the issue, especially for collector-assigned timestamps.
- 主要语言
- TypeScript
- 星标
- 10.1k
- 派生
- 527
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 186
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ClickHouse/ClickStack 的其他 Issue
-
external
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#3761 ·
维护者通常 1 天内回复
-
Metric chart with aggFn increase and a multi-column group-by fails: toString() gets several arguments可能已有人在做 @CG-5228 于 26 天前认领。 未关闭external
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/ClickStack#3477 · 1 条评论 ·
维护者通常 1 天内回复
-
Slack notifications for inline alerts fail when the chart-explorer link passes Slack's 3000-character block limit可能已有人在做 @Tyagiquamar 于 27 天前认领。 未关闭alerting bug external
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/ClickStack#3452 ·
维护者通常 1 天内回复
-
check-alerts worker: 13 error spans (mongodb.create, NamespaceExists) every minute because mongoose autoCreate is still on可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug external Needs Feedback
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#3308 · 1 条评论 ·
维护者通常 1 天内回复
-
count_distinct aggFn on metric tiles ignores valueExpression, always counts distinct metric Values可能已有人在做 @Harshul1484 于 54 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#2311 ·
维护者通常 1 天内回复
查看 ClickHouse/ClickStack 的全部 Issue
相似的 Issue
-
Add: GTrekker未关闭check:passed streams:add
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
area: ui Bug Payload OSS
难度 1/5 1 小时以内 新手友好度 88/100
payloadcms/payload#19839 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
fix(auth): add the email OTP verification step to Pollar login可能已有人在做 @akansnoro 今天认领。 未关闭Stellar Wave
难度 2/5 1-3 小时 新手友好度 74/100
safetrustcr/dApp-SafeTrust#584 · 10 条评论 ·
维护者通常 1 天内回复
-
The manager preset saves launch definitions without the required file and digest pair可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复