diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index 48a529316..d73df433a 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -95,7 +95,7 @@ func (br *blockResult) clone() *blockResult { // initFromNeededColumns initializes br from brSrc, by copying only the given neededColumns for rows identified by set bits at bm. // -// The br valid until brSrc is reset or bm is updated. +// The br valid until brSrc or bm is updated. func (br *blockResult) initFromNeededColumns(brSrc *blockResult, bm *bitmap, neededColumns []string) { br.reset() @@ -106,6 +106,11 @@ func (br *blockResult) initFromNeededColumns(brSrc *blockResult, bm *bitmap, nee }) br.timestamps = dstTimestamps + if len(br.timestamps) == 0 { + // There is no need in initializing columns for zero rows. + return + } + for _, neededColumn := range neededColumns { cSrc := brSrc.getColumnByName(neededColumn) @@ -1277,6 +1282,9 @@ func (br *blockResult) areSameColumns(columnNames []string) bool { } func (br *blockResult) getColumnByName(columnName string) *blockResultColumn { + if columnName == "" { + columnName = "_msg" + } for _, c := range br.getColumns() { if c.name == columnName { return c diff --git a/lib/logstorage/filter_phrase.go b/lib/logstorage/filter_phrase.go index 76658c5b3..4ca15e6f7 100644 --- a/lib/logstorage/filter_phrase.go +++ b/lib/logstorage/filter_phrase.go @@ -32,8 +32,8 @@ func (fp *filterPhrase) String() string { return quoteFieldNameIfNeeded(fp.fieldName) + quoteTokenIfNeeded(fp.phrase) } -func (fp *filterPhrase) updateNeededFields(neededColumns fieldsSet) { - neededColumns.add(fp.fieldName) +func (fp *filterPhrase) updateNeededFields(neededFields fieldsSet) { + neededFields.add(fp.fieldName) } func (fp *filterPhrase) getTokens() []string { diff --git a/lib/logstorage/pipe_stats.go b/lib/logstorage/pipe_stats.go index b9a211350..0a19bb65b 100644 --- a/lib/logstorage/pipe_stats.go +++ b/lib/logstorage/pipe_stats.go @@ -523,16 +523,16 @@ func parsePipeStats(lex *lexer) (*pipeStats, error) { } f.f = sf - neededFields := newFieldsSet() - f.f.updateNeededFields(neededFields) - f.neededFieldsForFunc = neededFields.getAll() - if lex.isKeyword("if") { iff, err := parseIfFilter(lex) if err != nil { return nil, fmt.Errorf("cannot parse 'if' filter for %s: %w", sf, err) } f.iff = iff + + neededFields := newFieldsSet() + iff.updateNeededFields(neededFields) + f.neededFieldsForFunc = neededFields.getAll() } resultName, err := parseResultName(lex)