From 846d5358cf408d921bb57ee0a3c627d20196372f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 18 May 2024 22:25:46 +0200 Subject: [PATCH] wip --- lib/logstorage/parser.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index f5ce10044..af9853421 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -10,6 +10,7 @@ import ( "unicode" "unicode/utf8" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) @@ -275,6 +276,9 @@ func (q *Query) Optimize() { } } + // Substitute '*' prefixFilter with filterNoop. + q.f = removeStarFilters(q.f) + // Optimize 'in(query)' filters optimizeFilterIn(q.f) for _, p := range q.pipes { @@ -289,6 +293,22 @@ func (q *Query) Optimize() { } } +func removeStarFilters(f filter) filter { + visitFunc := func(f filter) bool { + fp, ok := f.(*filterPrefix) + return ok && isMsgFieldName(fp.fieldName) && fp.prefix == "" + } + copyFunc := func(_ filter) (filter, error) { + fn := &filterNoop{} + return fn, nil + } + f, err := copyFilter(f, visitFunc, copyFunc) + if err != nil { + logger.Fatalf("BUG: unexpected error: %s", err) + } + return f +} + func optimizeFilterIn(f filter) { visitFunc := func(f filter) bool { fi, ok := f.(*filterIn)