diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 1a83eefe6..a1f177ff5 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -1820,4 +1820,6 @@ func TestQueryGetNeededColumns(t *testing.T) { f(`* | unpack_logfmt from x fields (a,b) | count() r1`, ``, ``) f(`* | unpack_logfmt if (q:w p:a) from x | count() r1`, `p,q`, ``) f(`* | unpack_logfmt if (q:w p:a) from x fields(a,b) | count() r1`, `p,q`, ``) + f(`* | unroll (a, b) | count() r1`, `a,b`, ``) + f(`* | unroll if (q:w p:a) (a, b) | count() r1`, `a,b,p,q`, ``) } diff --git a/lib/logstorage/pipe_unroll.go b/lib/logstorage/pipe_unroll.go index 2a2978f0b..97117b259 100644 --- a/lib/logstorage/pipe_unroll.go +++ b/lib/logstorage/pipe_unroll.go @@ -52,25 +52,15 @@ func (pu *pipeUnroll) initFilterInValues(cache map[string][]string, getFieldValu func (pu *pipeUnroll) updateNeededFields(neededFields, unneededFields fieldsSet) { if neededFields.contains("*") { - unneededFieldsCount := 0 - for _, f := range pu.fields { - if unneededFields.contains(f) { - unneededFieldsCount++ - } - } - if unneededFieldsCount < len(pu.fields) && pu.iff != nil { + if pu.iff != nil { unneededFields.removeFields(pu.iff.neededFields) } + unneededFields.removeFields(pu.fields) } else { - needIfFields := false - for _, f := range pu.fields { - if neededFields.contains(f) { - needIfFields = true - } - } - if needIfFields && pu.iff != nil { + if pu.iff != nil { neededFields.addFields(pu.iff.neededFields) } + neededFields.addFields(pu.fields) } } diff --git a/lib/logstorage/pipe_unroll_test.go b/lib/logstorage/pipe_unroll_test.go index f30dff562..75ad91eaa 100644 --- a/lib/logstorage/pipe_unroll_test.go +++ b/lib/logstorage/pipe_unroll_test.go @@ -225,13 +225,13 @@ func TestPipeUnrollUpdateNeededFields(t *testing.T) { f("unroll if (f1:b) (x)", "*", "f1,f2", "*", "f2") // all the needed fields, unneeded fields intersect with src - f("unroll (x)", "*", "f2,x", "*", "f2,x") - f("unroll if (a:b) (x)", "*", "f2,x", "*", "f2,x") - f("unroll if (f2:b) (x)", "*", "f2,x", "*", "f2,x") + f("unroll (x)", "*", "f2,x", "*", "f2") + f("unroll if (a:b) (x)", "*", "f2,x", "*", "f2") + f("unroll if (f2:b) (x)", "*", "f2,x", "*", "") // needed fields do not intersect with src - f("unroll (x)", "f1,f2", "", "f1,f2", "") - f("unroll if (a:b) (x)", "f1,f2", "", "f1,f2", "") + f("unroll (x)", "f1,f2", "", "f1,f2,x", "") + f("unroll if (a:b) (x)", "f1,f2", "", "a,f1,f2,x", "") // needed fields intersect with src f("unroll (x)", "f2,x", "", "f2,x", "")