Skip to content

Commit

Permalink
Merge pull request #438 from go-faster/fix/use-body-index
Browse files Browse the repository at this point in the history
perf(chstorage): use `hasToken` to skip blocks
  • Loading branch information
tdakkota committed Jun 21, 2024
2 parents 3473bf0 + 7e7fe5a commit e2d7301
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions internal/chstorage/querier_logs_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,25 @@ func (q *Querier) lineFilter(m logql.LineFilter) (e chsql.Expr, rerr error) {
switch m.Op {
case logql.OpEq, logql.OpNotEq:
expr := chsql.Contains("body", m.By.Value)

// Clickhouse does not use tokenbf_v1 index to skip blocks
// with position* functions for some reason.
//
// Force to skip using hasToken function.
//
// Note that such optimization is applied only if operation is not negated to
// avoid false-negative skipping.
if val := m.By.Value; m.Op != logql.OpNotEq && chsql.IsSingleToken(val) {
expr = chsql.And(expr,
chsql.HasToken(chsql.Ident("body"), val),
)
}

{
// HACK: check for special case of hex-encoded trace_id and span_id.
// Like `{http_method=~".+"} |= "af36000000000000c517000000000003"`.
// TODO(ernado): also handle regex?

v, _ := hex.DecodeString(m.By.Value)

switch len(v) {
case len(otelstorage.TraceID{}):
expr = chsql.Or(expr, chsql.Eq(
Expand Down
2 changes: 1 addition & 1 deletion internal/chstorage/schema_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const schemaMigration = `
(
table String,
ddl String,
ts DateTime DEFAULT now(),
ts DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(ts)
ORDER BY (table)`

0 comments on commit e2d7301

Please sign in to comment.