From 21b1536b5a7129c71bbf64db57850b20e53d2291 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Sun, 6 Jul 2025 12:57:19 +0200 Subject: [PATCH] storage: add projection fields to select hints (#16423) This commit adds Projection metadata to SelectHints so that downstream storage implementations can use it to save effort when answering to Select calls. Signed-off-by: Michael Hoffmann --- storage/interface.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/storage/interface.go b/storage/interface.go index 3562802495..636473d07c 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -223,6 +223,19 @@ type SelectHints struct { // When disabled, the result may contain samples outside the queried time range but Select() performances // may be improved. DisableTrimming bool + + // Projection hints. They are currently unused in the Prometheus promql engine but can be used by different + // implementations of the Queryable interface and engines. + // These hints are useful for queries like `sum by (label) (rate(metric[5m]))` - we can safely evaluate it + // even if we only fetch the `label` label. For some storage implementations this is beneficial. + + // ProjectionLabels are the minimum amount of labels required to be fetched for this Select call + // When honored it is required to add an __series_hash__ label containing the hash of all labels + // of a particular series so that the engine can still perform horizontal joins. + ProjectionLabels []string + + // ProjectionInclude defines if we have to include or exclude the labels from the ProjectLabels field. + ProjectionInclude bool } // LabelHints specifies hints passed for label reads.