You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-deterministic pagination in /api/v2/search when rows share the same timestamp #2614
The POST /api/v2/search endpoint (added in [hyperdxio/hyperdx#2258](#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 BYTimestampDESC, _block_number DESC, _block_offset DESCLIMIT {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.
Discussed with @knudtty in Slack. Aaron confirmed this would be accepted as an issue and suggested the block number/offset approach for deterministic ordering, with large-scale performance testing needed.
I was discussing with one of my colleagues, he highlighted that the /api/v2/search endpoint actually already allows the ORDER BY to be set here. In the case of the default schemas we provide, the order by you'd want to use is
Activity
iShiBin commentedon Jul 9, 2026
Discussed with @knudtty in Slack. Aaron confirmed this would be accepted as an issue and suggested the block number/offset approach for deterministic ordering, with large-scale performance testing needed.
knudtty commentedon Jul 9, 2026
I was discussing with one of my colleagues, he highlighted that the
/api/v2/searchendpoint actually already allows the ORDER BY to be set here. In the case of the default schemas we provide, the order by you'd want to use is(toStartOfMinute(Timestamp) DESC, Timestamp DESC, _block_number DESC, _block_offset DESC)iShiBin commentedon Jul 9, 2026
@knudtty Great! Appending the
_block_number DESC, _block_offset DESCwill help to get the ordering deterministic.