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] 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 { func (csh *columnsHeader) resizeConstColumns(columnsLen int) []Field {
csh.constColumns = slicesutil.SetLength(csh.constColumns, columnsLen) csh.constColumns = slicesutil.SetLength(csh.constColumns, columnsLen)
return csh.constColumns return csh.constColumns

View file

@ -305,11 +305,10 @@ func (br *blockResult) initAllColumns() {
if !slices.Contains(unneededColumnNames, "_msg") { if !slices.Contains(unneededColumnNames, "_msg") {
// Add _msg column // Add _msg column
csh := br.bs.getColumnsHeader() v := br.bs.getConstColumnValue("_msg")
v := csh.getConstColumnValue("_msg")
if v != "" { if v != "" {
br.addConstColumn("_msg", 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) br.addColumn(ch)
} else { } else {
br.addConstColumn("_msg", "") br.addConstColumn("_msg", "")
@ -317,9 +316,9 @@ func (br *blockResult) initAllColumns() {
} }
// Add other const columns // Add other const columns
csh := br.bs.getColumnsHeader() ccs := br.bs.getConstColumns()
for _, cc := range csh.constColumns { for _, cc := range ccs {
if isMsgFieldName(cc.Name) { if cc.Name == "" {
continue continue
} }
if !slices.Contains(unneededColumnNames, cc.Name) { if !slices.Contains(unneededColumnNames, cc.Name) {
@ -328,10 +327,10 @@ func (br *blockResult) initAllColumns() {
} }
// Add other non-const columns // Add other non-const columns
chs := csh.columnHeaders chs := br.bs.getColumnHeaders()
for i := range chs { for i := range chs {
ch := &chs[i] ch := &chs[i]
if isMsgFieldName(ch.name) { if ch.name == "" {
continue continue
} }
if !slices.Contains(unneededColumnNames, ch.name) { if !slices.Contains(unneededColumnNames, ch.name) {
@ -357,11 +356,10 @@ func (br *blockResult) initRequestedColumns() {
case "_time": case "_time":
br.addTimeColumn() br.addTimeColumn()
default: default:
csh := br.bs.getColumnsHeader() v := br.bs.getConstColumnValue(columnName)
v := csh.getConstColumnValue(columnName)
if v != "" { if v != "" {
br.addConstColumn(columnName, 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) br.addColumn(ch)
} else { } else {
br.addConstColumn(columnName, "") 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 { func (bs *blockSearch) getColumnsHeader() *columnsHeader {
if bs.cshCache == nil { if bs.cshCache == nil {
bs.cshBlockCache = readColumnsHeaderBlock(bs.cshBlockCache[:0], bs.bsw.p, &bs.bsw.bh) 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 fieldName := ft.field
tokens := ft.tokens tokens := ft.tokens
csh := bs.getColumnsHeader() v := bs.getConstColumnValue(fieldName)
v := csh.getConstColumnValue(fieldName)
if v != "" { if v != "" {
if matchStringByAllTokens(v, tokens) { if matchStringByAllTokens(v, tokens) {
continue continue
@ -90,7 +89,7 @@ func (fa *filterAnd) matchBloomFilters(bs *blockSearch) bool {
return false return false
} }
ch := csh.getColumnHeader(fieldName) ch := bs.getColumnHeader(fieldName)
if ch == nil { if ch == nil {
return false return false
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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