lib/logstorage: move getConstColumnValue() and getColumnHeader() methods from columnsHeader to blockSearch

This localizes blockSearch.getColumnsHeader() call at block_search.go .
This call is going to be optimized in the next commits in order to avoid
unmarshaling of header data for unneeded columns, which weren't requested
by getConstColumnValue() / getColumnHeader().
This commit is contained in:
Aliaksandr Valialkin 2024-10-13 14:28:59 +02:00
parent 279e25e7c8
commit 507b206a7d
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
18 changed files with 79 additions and 84 deletions

View file

@ -235,34 +235,6 @@ func (csh *columnsHeader) reset() {
csh.constColumns = ccs[:0]
}
func (csh *columnsHeader) getConstColumnValue(name string) string {
if name == "_msg" {
name = ""
}
ccs := csh.constColumns
for i := range ccs {
cc := &ccs[i]
if cc.Name == name {
return cc.Value
}
}
return ""
}
func (csh *columnsHeader) getColumnHeader(name string) *columnHeader {
if name == "_msg" {
name = ""
}
chs := csh.columnHeaders
for i := range chs {
ch := &chs[i]
if ch.name == name {
return ch
}
}
return nil
}
func (csh *columnsHeader) resizeConstColumns(columnsLen int) []Field {
csh.constColumns = slicesutil.SetLength(csh.constColumns, columnsLen)
return csh.constColumns

View file

@ -305,11 +305,10 @@ func (br *blockResult) initAllColumns() {
if !slices.Contains(unneededColumnNames, "_msg") {
// Add _msg column
csh := br.bs.getColumnsHeader()
v := csh.getConstColumnValue("_msg")
v := br.bs.getConstColumnValue("_msg")
if v != "" {
br.addConstColumn("_msg", v)
} else if ch := csh.getColumnHeader("_msg"); ch != nil {
} else if ch := br.bs.getColumnHeader("_msg"); ch != nil {
br.addColumn(ch)
} else {
br.addConstColumn("_msg", "")
@ -317,9 +316,9 @@ func (br *blockResult) initAllColumns() {
}
// Add other const columns
csh := br.bs.getColumnsHeader()
for _, cc := range csh.constColumns {
if isMsgFieldName(cc.Name) {
ccs := br.bs.getConstColumns()
for _, cc := range ccs {
if cc.Name == "" {
continue
}
if !slices.Contains(unneededColumnNames, cc.Name) {
@ -328,10 +327,10 @@ func (br *blockResult) initAllColumns() {
}
// Add other non-const columns
chs := csh.columnHeaders
chs := br.bs.getColumnHeaders()
for i := range chs {
ch := &chs[i]
if isMsgFieldName(ch.name) {
if ch.name == "" {
continue
}
if !slices.Contains(unneededColumnNames, ch.name) {
@ -357,11 +356,10 @@ func (br *blockResult) initRequestedColumns() {
case "_time":
br.addTimeColumn()
default:
csh := br.bs.getColumnsHeader()
v := csh.getConstColumnValue(columnName)
v := br.bs.getConstColumnValue(columnName)
if v != "" {
br.addConstColumn(columnName, v)
} else if ch := csh.getColumnHeader(columnName); ch != nil {
} else if ch := br.bs.getColumnHeader(columnName); ch != nil {
br.addColumn(ch)
} else {
br.addConstColumn(columnName, "")

View file

@ -190,6 +190,46 @@ func (bs *blockSearch) search(bsw *blockSearchWork, bm *bitmap) {
}
}
func (bs *blockSearch) getConstColumnValue(name string) string {
if name == "_msg" {
name = ""
}
csh := bs.getColumnsHeader()
for _, cc := range csh.constColumns {
if cc.Name == name {
return cc.Value
}
}
return ""
}
func (bs *blockSearch) getColumnHeader(name string) *columnHeader {
if name == "_msg" {
name = ""
}
csh := bs.getColumnsHeader()
chs := csh.columnHeaders
for i := range chs {
ch := &chs[i]
if ch.name == name {
return ch
}
}
return nil
}
func (bs *blockSearch) getConstColumns() []Field {
csh := bs.getColumnsHeader()
return csh.constColumns
}
func (bs *blockSearch) getColumnHeaders() []columnHeader {
csh := bs.getColumnsHeader()
return csh.columnHeaders
}
func (bs *blockSearch) getColumnsHeader() *columnsHeader {
if bs.cshCache == nil {
bs.cshBlockCache = readColumnsHeaderBlock(bs.cshBlockCache[:0], bs.bsw.p, &bs.bsw.bh)

View file

@ -81,8 +81,7 @@ func (fa *filterAnd) matchBloomFilters(bs *blockSearch) bool {
fieldName := ft.field
tokens := ft.tokens
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if matchStringByAllTokens(v, tokens) {
continue
@ -90,7 +89,7 @@ func (fa *filterAnd) matchBloomFilters(bs *blockSearch) bool {
return false
}
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
return false
}

View file

@ -86,8 +86,7 @@ func (fp *filterAnyCasePhrase) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
phraseLowercase := fp.getPhraseLowercase()
// Verify whether fp matches const column
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchAnyCasePhrase(v, phraseLowercase) {
bm.resetBits()
@ -96,7 +95,7 @@ func (fp *filterAnyCasePhrase) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether fp matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
// It matches anything only for empty phrase.

View file

@ -90,8 +90,7 @@ func (fp *filterAnyCasePrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
prefixLowercase := fp.getPrefixLowercase()
// Verify whether fp matches const column
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchAnyCasePrefix(v, prefixLowercase) {
bm.resetBits()
@ -100,7 +99,7 @@ func (fp *filterAnyCasePrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether fp matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
bm.resetBits()

View file

@ -174,8 +174,7 @@ func (fe *filterExact) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
fieldName := fe.fieldName
value := fe.value
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if value != v {
bm.resetBits()
@ -184,7 +183,7 @@ func (fe *filterExact) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
// It matches anything only for empty value.

View file

@ -51,8 +51,7 @@ func (fep *filterExactPrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
fieldName := fep.fieldName
prefix := fep.prefix
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchExactPrefix(v, prefix) {
bm.resetBits()
@ -61,7 +60,7 @@ func (fep *filterExactPrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
if !matchExactPrefix("", prefix) {

View file

@ -358,8 +358,7 @@ func (fi *filterIn) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
stringValues := fi.getStringValues()
if _, ok := stringValues[v]; !ok {
@ -369,7 +368,7 @@ func (fi *filterIn) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
// It matches anything only for empty phrase.

View file

@ -102,8 +102,7 @@ func (fr *filterIPv4Range) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchIPv4Range(v, minValue, maxValue) {
bm.resetBits()
@ -112,7 +111,7 @@ func (fr *filterIPv4Range) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
bm.resetBits()

View file

@ -125,8 +125,7 @@ func (fr *filterLenRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchLenRange(v, minLen, maxLen) {
bm.resetBits()
@ -135,7 +134,7 @@ func (fr *filterLenRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
if !matchLenRange("", minLen, maxLen) {

View file

@ -93,8 +93,7 @@ func (fo *filterOr) matchBloomFilters(bs *blockSearch) bool {
fieldName := ft.field
tokens := ft.tokens
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if matchStringByAllTokens(v, tokens) {
return true
@ -102,7 +101,7 @@ func (fo *filterOr) matchBloomFilters(bs *blockSearch) bool {
continue
}
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
continue
}

View file

@ -61,8 +61,7 @@ func (fp *filterPhrase) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
phrase := fp.phrase
// Verify whether fp matches const column
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchPhrase(v, phrase) {
bm.resetBits()
@ -71,7 +70,7 @@ func (fp *filterPhrase) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether fp matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
// It matches anything only for empty phrase.

View file

@ -59,8 +59,7 @@ func (fp *filterPrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
prefix := fp.prefix
// Verify whether fp matches const column
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchPrefix(v, prefix) {
bm.resetBits()
@ -69,7 +68,7 @@ func (fp *filterPrefix) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether fp matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
bm.resetBits()

View file

@ -173,8 +173,7 @@ func (fr *filterRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchRange(v, minValue, maxValue) {
bm.resetBits()
@ -183,7 +182,7 @@ func (fr *filterRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
bm.resetBits()

View file

@ -78,8 +78,7 @@ func (fr *filterRegexp) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
re := fr.re
// Verify whether filter matches const column
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !re.MatchString(v) {
bm.resetBits()
@ -88,7 +87,7 @@ func (fr *filterRegexp) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
if !re.MatchString("") {

View file

@ -87,8 +87,7 @@ func (fs *filterSequence) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchSequence(v, phrases) {
bm.resetBits()
@ -97,7 +96,7 @@ func (fs *filterSequence) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
// Fast path - there are no matching columns.
// It matches anything only for empty phrase.

View file

@ -52,8 +52,7 @@ func (fr *filterStringRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
return
}
csh := bs.getColumnsHeader()
v := csh.getConstColumnValue(fieldName)
v := bs.getConstColumnValue(fieldName)
if v != "" {
if !matchStringRange(v, minValue, maxValue) {
bm.resetBits()
@ -62,7 +61,7 @@ func (fr *filterStringRange) applyToBlockSearch(bs *blockSearch, bm *bitmap) {
}
// Verify whether filter matches other columns
ch := csh.getColumnHeader(fieldName)
ch := bs.getColumnHeader(fieldName)
if ch == nil {
if !matchStringRange("", minValue, maxValue) {
bm.resetBits()