-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index to improve user search by ID
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../main/resources/org/cloudfoundry/identity/uaa/db/hsqldb/V2_3_6__Add_Index_To_Users_Id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 user_perf_id ON users(id); |
16 changes: 16 additions & 0 deletions
16
...c/main/resources/org/cloudfoundry/identity/uaa/db/mysql/V2_3_6__Add_Index_To_Users_Id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- | ||
-- 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. | ||
-- | ||
|
||
|
||
-- in mysql we turn off lower function during queries | ||
CREATE INDEX user_perf_id ON users(id); |
16 changes: 16 additions & 0 deletions
16
...n/resources/org/cloudfoundry/identity/uaa/db/postgresql/V2_3_6__Add_Index_To_Users_Id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- | ||
-- 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. | ||
-- | ||
|
||
|
||
-- create an index to match the query | ||
CREATE INDEX user_perf_id ON users(LOWER(id)); |
55 changes: 55 additions & 0 deletions
55
common/src/test/java/org/cloudfoundry/identity/uaa/db/TestSchemaValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-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. | ||
* ***************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.db; | ||
|
||
import org.cloudfoundry.identity.uaa.test.JdbcTestBase; | ||
import org.junit.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DatabaseMetaData; | ||
import java.sql.ResultSet; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestSchemaValidation extends JdbcTestBase { | ||
|
||
@Test | ||
public void test_v2_3_6__That_Users_Perf_Id_Index_Exists() 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)) { | ||
foundIndex = true; | ||
} | ||
} | ||
rs.close(); | ||
if (foundIndex) { | ||
break; | ||
} | ||
} | ||
assertTrue("I was expecting to find index user_perf_id", foundIndex); | ||
} finally { | ||
connection.close(); | ||
} | ||
|
||
|
||
} | ||
} |