Merge "Improve dimension filtering performance"

This commit is contained in:
Jenkins 2016-09-01 16:28:55 +00:00 committed by Gerrit Code Review
commit a44d2c96a0
2 changed files with 20 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at * in compliance with the License. You may obtain a copy of the License at
@ -92,8 +92,11 @@ final class MetricQueries {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(" and ").append(tableToJoinName).append( sb.append(" and ").append(tableToJoinName).append(
".dimension_set_id in ( " ".id in ( "
+ "SELECT dimension_set_id FROM MonMetrics.Dimensions WHERE ("); + "SELECT defDimsSub2.id FROM MonMetrics.Dimensions AS dimSub " +
"JOIN MonMetrics.DefinitionDimensions AS defDimsSub2 " +
"ON defDimsSub2.dimension_set_id = dimSub.dimension_set_id" +
" WHERE (");
int i = 0; int i = 0;
for (Iterator<Map.Entry<String, String>> it = dimensions.entrySet().iterator(); it.hasNext(); i++) { for (Iterator<Map.Entry<String, String>> it = dimensions.entrySet().iterator(); it.hasNext(); i++) {
@ -128,7 +131,7 @@ final class MetricQueries {
} }
} }
sb.append(") GROUP BY dimension_set_id HAVING count(*) = ").append(dimensions.size()).append(") "); sb.append(") GROUP BY defDimsSub2.id,dimSub.dimension_set_id HAVING count(*) = ").append(dimensions.size()).append(") ");
return sb.toString(); return sb.toString();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P. * (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at * in compliance with the License. You may obtain a copy of the License at
@ -28,9 +28,11 @@ public class MetricQueriesTest {
public void metricQueriesBuildDimensionAndClauseTest1() { public void metricQueriesBuildDimensionAndClauseTest1() {
String expectedResult = String expectedResult =
" and defdims.dimension_set_id in ( SELECT dimension_set_id FROM MonMetrics.Dimensions WHERE" " and defdims.id in ( SELECT defDimsSub2.id FROM MonMetrics.Dimensions AS dimSub "
+ "JOIN MonMetrics.DefinitionDimensions AS defDimsSub2 "
+ "ON defDimsSub2.dimension_set_id = dimSub.dimension_set_id WHERE"
+ " ((name = :dname0 and value = :dvalue0) or (name = :dname1 and value = :dvalue1))" + " ((name = :dname0 and value = :dvalue0) or (name = :dname1 and value = :dvalue1))"
+ " GROUP BY dimension_set_id HAVING count(*) = 2) "; + " GROUP BY defDimsSub2.id,dimSub.dimension_set_id HAVING count(*) = 2) ";
Map<String, String> dimsMap = new HashMap<>(); Map<String, String> dimsMap = new HashMap<>();
dimsMap.put("foo", "bar"); dimsMap.put("foo", "bar");
@ -54,9 +56,11 @@ public class MetricQueriesTest {
public void metricQueriesBuildDimensionAndClauseTest4() { public void metricQueriesBuildDimensionAndClauseTest4() {
String expectedResult = String expectedResult =
" and defdims.dimension_set_id in ( SELECT dimension_set_id FROM MonMetrics.Dimensions WHERE" " and defdims.id in ( SELECT defDimsSub2.id FROM MonMetrics.Dimensions AS dimSub "
+ "JOIN MonMetrics.DefinitionDimensions AS defDimsSub2 "
+ "ON defDimsSub2.dimension_set_id = dimSub.dimension_set_id WHERE"
+ " ((name = :dname0 and ( value = :dvalue0_0 or value = :dvalue0_1)))" + " ((name = :dname0 and ( value = :dvalue0_0 or value = :dvalue0_1)))"
+ " GROUP BY dimension_set_id HAVING count(*) = 1) "; + " GROUP BY defDimsSub2.id,dimSub.dimension_set_id HAVING count(*) = 1) ";
Map<String, String> dimsMap = new HashMap<>(); Map<String, String> dimsMap = new HashMap<>();
dimsMap.put("foo", "bar|baz"); dimsMap.put("foo", "bar|baz");
@ -67,10 +71,12 @@ public class MetricQueriesTest {
public void metricQueriesBuildDimensionAndClauseTest5() { public void metricQueriesBuildDimensionAndClauseTest5() {
String expectedResult = String expectedResult =
" and defdims.dimension_set_id in ( SELECT dimension_set_id FROM MonMetrics.Dimensions WHERE" " and defdims.id in ( SELECT defDimsSub2.id FROM MonMetrics.Dimensions AS dimSub "
+ "JOIN MonMetrics.DefinitionDimensions AS defDimsSub2 "
+ "ON defDimsSub2.dimension_set_id = dimSub.dimension_set_id WHERE"
+ " ((name = :dname0 and ( value = :dvalue0_0 or value = :dvalue0_1))" + " ((name = :dname0 and ( value = :dvalue0_0 or value = :dvalue0_1))"
+ " or (name = :dname1 and ( value = :dvalue1_0 or value = :dvalue1_1)))" + " or (name = :dname1 and ( value = :dvalue1_0 or value = :dvalue1_1)))"
+ " GROUP BY dimension_set_id HAVING count(*) = 2) "; + " GROUP BY defDimsSub2.id,dimSub.dimension_set_id HAVING count(*) = 2) ";
Map<String, String> dimsMap = new HashMap<>(); Map<String, String> dimsMap = new HashMap<>();
dimsMap.put("foo", "bar|baz"); dimsMap.put("foo", "bar|baz");