Skip to content

Commit

Permalink
perf: add some unnecessary indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 4, 2024
1 parent 2a8ea8d commit 6fcd8b4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
13 changes: 9 additions & 4 deletions internal/chstorage/_golden/log_columns_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ CREATE TABLE IF NOT EXISTS `table`
`scope_version` LowCardinality(String),
`scope` LowCardinality(String),

INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX `idx_body` body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1,
INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192,
INDEX `attribute_keys` arrayConcat(JSONExtractKeys(attribute), JSONExtractKeys(scope), JSONExtractKeys(resource)) TYPE set(100)
INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX `idx_body` body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1,
INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192,
INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
Expand Down
13 changes: 9 additions & 4 deletions internal/chstorage/_golden/schema.logs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ CREATE TABLE IF NOT EXISTS `logs`
`scope_version` LowCardinality(String),
`scope` LowCardinality(String),

INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX `idx_body` body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1,
INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192,
INDEX `attribute_keys` arrayConcat(JSONExtractKeys(attribute), JSONExtractKeys(scope), JSONExtractKeys(resource)) TYPE set(100)
INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX `idx_body` body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1,
INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192,
INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
Expand Down
9 changes: 8 additions & 1 deletion internal/chstorage/_golden/schema.metrics_exemplars.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ CREATE TABLE IF NOT EXISTS `metrics_exemplars`
`span_id` FixedString(8),
`attribute` LowCardinality(String),
`resource` LowCardinality(String),
`scope` LowCardinality(String)
`scope` LowCardinality(String),

INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
Expand Down
9 changes: 8 additions & 1 deletion internal/chstorage/_golden/schema.metrics_exp_histograms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ CREATE TABLE IF NOT EXISTS `metrics_exp_histograms`
`flags` UInt8 CODEC(T64, ZSTD(1)),
`attribute` LowCardinality(String),
`resource` LowCardinality(String),
`scope` LowCardinality(String)
`scope` LowCardinality(String),

INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
Expand Down
8 changes: 7 additions & 1 deletion internal/chstorage/_golden/schema.metrics_points.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ CREATE TABLE IF NOT EXISTS `metrics_points`
`resource` LowCardinality(String),
`scope` LowCardinality(String),

INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192
INDEX `idx_ts` timestamp TYPE minmax GRANULARITY 8192,
INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(timestamp)
Expand Down
8 changes: 7 additions & 1 deletion internal/chstorage/_golden/schema.traces_spans.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ CREATE TABLE IF NOT EXISTS `traces_spans`
`links_tracestates` Array(String),
`links_attributes` Array(String),

INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1
INDEX `idx_trace_id` trace_id TYPE bloom_filter(0.001) GRANULARITY 1,
INDEX `idx_arr_join_attribute` arrayJoin(JSONExtractKeys(attribute)) TYPE set(100),
INDEX `idx_keys_attribute` JSONExtractKeys(attribute) TYPE set(100),
INDEX `idx_arr_join_resource` arrayJoin(JSONExtractKeys(resource)) TYPE set(100),
INDEX `idx_keys_resource` JSONExtractKeys(resource) TYPE set(100),
INDEX `idx_arr_join_scope` arrayJoin(JSONExtractKeys(scope)) TYPE set(100),
INDEX `idx_keys_scope` JSONExtractKeys(scope) TYPE set(100)
)
ENGINE = MergeTree
ORDER BY (`service_namespace`, `service_name`, `resource`, `start`)
Expand Down
14 changes: 14 additions & 0 deletions internal/chstorage/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ func (a *Attributes) DDL(table *ddl.Table) {
Type: a.Value.Type(),
},
)
table.Indexes = append(table.Indexes,
ddl.Index{
Name: "idx_arr_join_" + a.Name,
Target: "arrayJoin(JSONExtractKeys(" + a.Name + "))",
Type: "set",
Params: []string{"100"},
},
ddl.Index{
Name: "idx_keys_" + a.Name,
Target: "JSONExtractKeys(" + a.Name + ")",
Type: "set",
Params: []string{"100"},
},
)
}

func attrsToLabels(m otelstorage.Attrs, to map[string]string) {
Expand Down
6 changes: 0 additions & 6 deletions internal/chstorage/columns_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ func (c *logColumns) DDL() ddl.Table {
Type: "minmax",
Granularity: 8192,
},
{
Name: "attribute_keys",
Target: "arrayConcat(JSONExtractKeys(attribute), JSONExtractKeys(scope), JSONExtractKeys(resource))",
Type: "set",
Params: []string{"100"},
},
},
Columns: []ddl.Column{
{
Expand Down

0 comments on commit 6fcd8b4

Please sign in to comment.