Skip to content

Commit

Permalink
Add index to group_membership to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed Oct 17, 2016
1 parent 4e23e78 commit a9d2419
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
@@ -0,0 +1,15 @@
--
-- Cloud Foundry
-- Copyright (c) [2015] Pivotal Software, Inc. All Rights Reserved.
--
-- This product is licensed to you under the Apache License, Version 2.0 (the "License").
-- You may not use this product except in compliance with the License.
--
-- This product includes a number of subcomponents with
-- separate copyright notices and license terms. Your use of these
-- subcomponents is subject to the terms and conditions of the
-- subcomponent's license, as noted in the LICENSE file.
--

-- HSQLDB does not support indices with function - but we create this one to keep it in synch with the other schemas
CREATE INDEX group_membership_perf_idx ON group_membership(member_id);
@@ -0,0 +1,16 @@
--
-- Cloud Foundry
-- Copyright (c) [2016] Pivotal Software, Inc. All Rights Reserved.
--
-- This product is licensed to you under the Apache License, Version 2.0 (the "License").
-- You may not use this product except in compliance with the License.
--
-- This product includes a number of subcomponents with
-- separate copyright notices and license terms. Your use of these
-- subcomponents is subject to the terms and conditions of the
-- subcomponent's license, as noted in the LICENSE file.
--


-- in mysql we turn off lower function during queries
CREATE INDEX group_membership_perf_idx ON group_membership(member_id);
@@ -0,0 +1,16 @@
--
-- Cloud Foundry
-- Copyright (c) [2016] Pivotal Software, Inc. All Rights Reserved.
--
-- This product is licensed to you under the Apache License, Version 2.0 (the "License").
-- You may not use this product except in compliance with the License.
--
-- This product includes a number of subcomponents with
-- separate copyright notices and license terms. Your use of these
-- subcomponents is subject to the terms and conditions of the
-- subcomponent's license, as noted in the LICENSE file.
--


-- create an index to match the query
CREATE INDEX group_membership_perf_idx ON group_membership(LOWER(member_id));
Expand Up @@ -27,16 +27,28 @@ public class TestSchemaValidation extends JdbcTestBase {

@Test
public void test_v2_3_6__That_Users_Perf_Id_Index_Exists() throws Exception {
String[] tableNames = {"users", "USERS"};
validate_index_existence(tableNames, "user_perf_id");
}

@Test
public void test_v3_9_0__That_Users_Perf_Id_Index_Exists() throws Exception {
String tableName = "group_membership";
validate_index_existence(new String[] {tableName,tableName.toUpperCase()}, "group_membership_perf_idx");
}


public void validate_index_existence(String[] tableNames, String lookupIndexName) throws Exception {

Connection connection = dataSource.getConnection();
try {
DatabaseMetaData meta = connection.getMetaData();
boolean foundIndex = false;
String[] tableNames = {"users", "USERS"};
for (String tableName : tableNames) {
ResultSet rs = meta.getIndexInfo(connection.getCatalog(), null, tableName, false, false);
while ((!foundIndex) && rs.next()) {
String indexName = rs.getString("INDEX_NAME");
if ("user_perf_id".equalsIgnoreCase(indexName)) {
if (lookupIndexName.equalsIgnoreCase(indexName)) {
foundIndex = true;
}
}
Expand All @@ -45,11 +57,9 @@ public void test_v2_3_6__That_Users_Perf_Id_Index_Exists() throws Exception {
break;
}
}
assertTrue("I was expecting to find index user_perf_id", foundIndex);
assertTrue("I was expecting to find index "+ lookupIndexName, foundIndex);
} finally {
connection.close();
}


}
}

0 comments on commit a9d2419

Please sign in to comment.