Skip to content

A relative-error division by an estimate that is exactly zero returns the wrong sign of infinity #1322

Open

Description

@zzylol

Example

sum by (job) (
  quantile_over_time(0.9, data[5m])
  / on(instance, job, host, region)
  quantile_over_time(0.9, neg[5m])
)
  • data is declared non_negative and neg is declared non_positive. Each has 12 series with one sample per second.
  • Target: relative error 0.05, failure probability 0.3 over the whole result.
  • Deployment: {"raw_data_retained": false}.
  • Data: near zero. 30% of neg's samples are -0.0, so the exact quantile_over_time(0.9, neg[5m]) is -0.0.
Head Result for job j0, j1, j2 Exact reference
before the non-finite exact sums stream: node 13 (SummaryAgg) failed: accumulator input must be finite -Inf, -Inf, -Inf
with the non-finite exact sums (exact Sum, Count, Min and Max take ±Inf and NaN, as PromQL does) +Inf, +Inf, +Inf -Inf, -Inf, -Inf

With raw data retained, the plan already returned +Inf before that change. The answer is silently wrong in both deployments. Seeds 0, 1 and 2 behave the same.

Why it happens

  • The DDSketch readout of quantile_over_time(0.9, neg[5m]) returns +0.0 where the exact value is -0.0. A relative error of 0 lets the sign of zero change: |(+0) − (−0)| = 0 ≤ ε · |−0|.
  • x / +0 is +Inf and x / −0 is -Inf. So a divisor's signed-zero error, which the contract allows, flips the sign of the quotient's infinity.
  • The relative error contract of / (error_contract, ArithmeticOpKind::Div under AccuracyMetric::Relative in crates/accuracy/src/error_contract/mod.rs) caps the divisor's relative error at RELATIVE_OPERAND_VALIDITY_CAP. It does not require the divisor to be nonzero.
  • BinaryOperator::checked_relative_division (crates/types/src/ir/operator/non_asap.rs) is meant for exactly this case: "Execute division only for finite operands, a nonzero divisor, and a normal finite result". The executor checks it (crates/executor/src/expressions/arithmetic.rs). No planner code sets it to true; only executor tests do (grep -rn "checked_relative_division: true" crates).

Proposal

Two options, for a decision:

  1. The planner sets checked_relative_division on a / whenever its divisor reads an estimate. A divisor of exactly zero then takes the exact path instead of dividing by an estimate. The executor's checked division fails today rather than taking an exact path, so this option also needs that path in the executor.
  2. The / contract requires a divisor known to be nonzero. ValueSign (crates/types/src/stages/logical/group/column_properties.rs) has NonNegative, NonPositive and Unknown only, and both signed variants allow a zero. So this option needs a new fact for a value that is never zero (a new ValueSign variant or a declared bound), to be agreed before code. A divisor that may be zero then gets no relative error contract, and the readout edge into it is cut.

Option 1 keeps plans that option 2 would cut. Option 2 needs no executor change.

A related gap: ValueSign::NonPositive says every non-NaN value has its sign bit set, -0.0 included. The DDSketch readout's +0.0 breaks that fact for neg. Whichever option is chosen, a readout of a NonPositive column could return -0.0 for a zero estimate.

Scope and acceptance

  • In scope: the relative error contract of / and the plans it allows.
  • Out of scope: what each kernel does with non-finite values (Non-finite values across the executor should follow PromQL #1311).
  • Acceptance: the example above, run on near-zero data without raw data, returns -Inf for every job, or has no sketch plan. A unit test pins the rule chosen: either the planner sets checked_relative_division on the /, or the contract is None for a divisor that may be zero.

Related

Activity

  1. added
    accuracyAccuracy requirements, guarantees, and propagation
    bugSomething isn't working
    promqlPromQL front-end lowering (L1→L2)
    on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accuracyAccuracy requirements, guarantees, and propagationbugSomething isn't workingerror-estimationpromqlPromQL front-end lowering (L1→L2)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions