TL;DR

A metrics engine had two query paths — a SQL push-down for big datasets, an in-memory aggregator for small ones. They drifted.

The push-down path bound a metric parameter but never added it to the WHERE. With several metric series in one dataset, every query summed across all of them.

A KPI that should read 819 read 163,667,603,769.

Fix: put the metric_key predicate in the shared base WHERE so every compile path inherits it, and regression-test both paths assert it.