Skip to content

Commit

Permalink
Improve simple tag query performance by enabling the A-cost query pos…
Browse files Browse the repository at this point in the history
…sibilities

Add better regexp detection and test for most common cases

Add ^!.* as regexp check since we allow that syntax

Optimize OR-queries also in the query optimizer

Change tagNameAndValues to use IN
  • Loading branch information
Michael Burman authored and rubenvp8510 committed Mar 13, 2018
1 parent 13bd91d commit e86d960
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
* Copyright 2014-2018 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -130,7 +130,7 @@ <T> Observable<ResultSet> updateRetentionsIndex(String tenantId, MetricType<T> t

Observable<Row> findMetricsByTagName(String tenantId, String tag);

Observable<Row> findMetricsByTagNameValue(String tenantId, String tag, String tvalue);
Observable<Row> findMetricsByTagNameValue(String tenantId, String tag, String ... tvalues);

Observable<Row> findAllMetricsFromTagsIndex();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
* Copyright 2014-2018 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,6 +25,7 @@
import static org.hawkular.metrics.model.MetricType.STRING;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -565,7 +566,7 @@ protected void initPreparedStatements() {
findMetricsByTagNameValue = session.prepare(
"SELECT tenant_id, type, metric, tvalue " +
"FROM metrics_tags_idx " +
"WHERE tenant_id = ? AND tname = ? AND tvalue = ?");
"WHERE tenant_id = ? AND tname = ? AND tvalue IN ?");

updateMetricExpirationIndex = session.prepare(
"INSERT INTO metrics_expiration_idx (tenant_id, type, metric, time) VALUES (?, ?, ?, ?)");
Expand Down Expand Up @@ -1164,8 +1165,8 @@ public Observable<Row> findMetricsByTagName(String tenantId, String tag) {
}

@Override
public Observable<Row> findMetricsByTagNameValue(String tenantId, String tag, String tvalue) {
return rxSession.executeAndFetch(findMetricsByTagNameValue.bind(tenantId, tag, tvalue));
public Observable<Row> findMetricsByTagNameValue(String tenantId, String tag, String ... tvalues) {
return rxSession.executeAndFetch(findMetricsByTagNameValue.bind(tenantId, tag, Arrays.asList(tvalues)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
* Copyright 2014-2018 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -182,6 +182,7 @@ public int hashCode() {
/**
* Tools that do tag query parsing and execution
*/
private boolean disableACostOptimization;
private SimpleTagQueryParser tagQueryParser;
private ExpressionTagQueryParser expresssionTagQueryParser;

Expand Down Expand Up @@ -269,7 +270,7 @@ public void startUp(Session session, String keyspace, boolean resetDb, boolean c
setDefaultTTL(session, keyspace);
initMetrics();

tagQueryParser = new SimpleTagQueryParser(this.dataAccess, this);
tagQueryParser = new SimpleTagQueryParser(this.dataAccess, this, disableACostOptimization);
expresssionTagQueryParser = new ExpressionTagQueryParser(this.dataAccess, this);
}

Expand Down Expand Up @@ -344,6 +345,7 @@ private void initConfiguration(Session session) {
log.infoInsertRetryConfig(insertMaxRetries, insertRetryMaxDelay);

defaultPageSize = Integer.parseInt(configuration.get("page-size", "5000"));
disableACostOptimization = Boolean.parseBoolean(configuration.get("disable.parser.optimization", "false"));
}

private void setDefaultTTL(Session session, String keyspace) {
Expand Down

0 comments on commit e86d960

Please sign in to comment.