mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: ignore start text
and end text
anchors in getOrValues(regexp) function
This is OK, since the anchors are implicitly applied to the whole regexp. This optimization should improve the speed for regexp series filters with explicit $ and ^ anchors. For example, `{label="^(foo|bar)$"}`
This commit is contained in:
parent
cdffe401e4
commit
fdbf5b5795
2 changed files with 9 additions and 0 deletions
|
@ -811,6 +811,8 @@ func getOrValuesExt(sre *syntax.Regexp) []string {
|
|||
return []string{string(sre.Rune)}
|
||||
case syntax.OpEmptyMatch:
|
||||
return []string{""}
|
||||
case syntax.OpBeginText, syntax.OpEndText:
|
||||
return []string{""}
|
||||
case syntax.OpAlternate:
|
||||
a := make([]string, 0, len(sre.Sub))
|
||||
for _, reSub := range sre.Sub {
|
||||
|
|
|
@ -1176,6 +1176,13 @@ func TestGetOrValues(t *testing.T) {
|
|||
f("(a|b|c)(d|e|f)(g|h|k)", nil)
|
||||
f("(?i)foo", nil)
|
||||
f("(?i)(foo|bar)", nil)
|
||||
f("^foo|bar$", []string{"bar", "foo"})
|
||||
f("^(foo|bar)$", []string{"bar", "foo"})
|
||||
f("^a(foo|b(?:a|r))$", []string{"aba", "abr", "afoo"})
|
||||
// This is incorrect conversion, because the regexp matches nothing.
|
||||
// It is OK for now, since such regexps are uncommon in practice.
|
||||
// TODO: properly handle this case.
|
||||
f("^a(^foo|bar$)z$", []string{"abarz", "afooz"})
|
||||
}
|
||||
|
||||
func TestGetRegexpPrefix(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue