I need filter result in this way:
from(bucket: "zillonare") |> range(start: 2022-03-17T00:00:00Z, stop: 2022-03-18T00:00:01Z) |> filter(fn: (r) => r["_measurement"] == "stock_bars_1d") |> filter(fn: (r) => contains(value: r["code"], set: ["000001.XSHE"])) |> pivot(columnKey: ["_field"], rowKey: ["_time"], valueColumn: "_value") |> keep(columns: ["frame","open","high","low","close","volume","amount","factor","code","_time"]) |> top(n: 1, columns: ["_time"]) |> sort(columns: ["_time"], desc: false)
i.e., I need filter out records that their ‘code’ tag is not in [‘000001.XHSE’, …].
the query takes me almost 10 secs even the set ([‘000001.XSHE’]) contains only one item, however, if I use this filter:
|> filter(fn: (r) => r["code"] == "000001.XSHE"
the query performance is good.
Apparently, the former gramar is quiet concise, if the set is big.
Any idea why contains
is so slow, and if there’s better way in such case, we can both have better query performance and concise expression?
MzazM
2
Hi, a couple of helpful links about contains and its performance: