I'm using Grafana with QuestDB and have a multi-value variable element with "All" option enabled. When "All" is selected, Grafana expands all values in the WHERE clause:
-- Current behavior when "All" is selected:
AND element IN ('value1', 'value2', 'value3', ... 'value1000') -- Performance issue
This causes very long queries and performance problems with large datasets.
I want to skip the filter entirely or use a more efficient approach when "All" is selected, instead of listing every value. I've tried: Complex conditional logic checking for magic values, but it feels hacky:
AND (
${element} = '_ALL_GRAFANA_MAGIC_'
AND element IS NOT NULL AND element <> '' OR
(
${element:sqlstring} != '_ALL_GRAFANA_MAGIC_'
AND element IN ('${element}')
)
)
What's the best practice to handle Grafana's "All" option with QuestDB queries efficiently?