ChangeMessageAccess: Add index for byPathSet method.

When using a sql datastore, ChangeMessageAccess#byPathSet ends
up creating a request filtering results with columns patchset_change_id
and patchset_patch_set_id, none of which is indexed. This results
in a full table scan.

Since change I6bc6391f456d9faeab7f1212b9c0463e7514cc05, change messages
are retrieved by patch set for highlighting purpose in ListChanges.

This can have a significant impact on dashboard. On a gerrit instance
I manage, which has about 70,000 lines in change_messages, one user
dashboard with 137 displayed changes went from an average display
time of 2.4s to 0.7s by adding this index.

Change-Id: If92f5b4f924617c69a1318f31a5ca01f320af792
This commit is contained in:
Arnaud Fabre
2012-10-14 19:05:42 +02:00
committed by Edwin Kempin
parent 7c245a6cb7
commit f77e9a9109
4 changed files with 50 additions and 1 deletions

View File

@@ -122,6 +122,9 @@ ON patch_set_approvals (change_open, account_id, change_sort_key);
-- ChangeMessageAccess -- ChangeMessageAccess
-- @PrimaryKey covers: byChange -- @PrimaryKey covers: byChange
-- covers: byPatchSet
CREATE INDEX change_messages_byPatchset
ON change_messages (patchset_change_id, patchset_patch_set_id);
-- ********************************************************************* -- *********************************************************************
-- PatchLineCommentAccess -- PatchLineCommentAccess

View File

@@ -203,6 +203,9 @@ WHERE change_open = 'N';
-- ChangeMessageAccess -- ChangeMessageAccess
-- @PrimaryKey covers: byChange -- @PrimaryKey covers: byChange
-- covers: byPatchSet
CREATE INDEX change_messages_byPatchset
ON change_messages (patchset_change_id, patchset_patch_set_id);
-- ********************************************************************* -- *********************************************************************
-- PatchLineCommentAccess -- PatchLineCommentAccess

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */ /** A version of the database schema. */
public abstract class SchemaVersion { public abstract class SchemaVersion {
/** The current schema version. */ /** The current schema version. */
public static final Class<Schema_72> C = Schema_72.class; public static final Class<Schema_73> C = Schema_73.class;
public static class Module extends AbstractModule { public static class Module extends AbstractModule {
@Override @Override

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2012 The Android Open Source Project
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.sql.Statement;
public class Schema_73 extends SchemaVersion {
@Inject
Schema_73(Provider<Schema_72> prior) {
super(prior);
}
@Override
protected void migrateData(final ReviewDb db, final UpdateUI ui)
throws SQLException {
final Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
stmt.executeUpdate("CREATE INDEX change_messages_byPatchset ON change_messages (patchset_change_id, patchset_patch_set_id )");
}
finally {
stmt.close();
}
}
}