AccountPatchReview mariadb: fix key length
Setting up the db on mariadb currently fails with
com.google.gerrit.exceptions.StorageException: create failure on ACCOUNT_PATCH_REVIEWS
at com.google.gerrit.server.schema.JdbcAccountPatchReviewStore.createTableIfNotExists(JdbcAccountPatchReviewStore.java:188)
...
Caused by: java.sql.SQLSyntaxErrorException: (conn=13) Specified key was too long; max key length is 3072 bytes
If35aff6c8d dealt with this for mysql, this just ports it to mariadb.
Out of interest, I did a query on the file_name size on our production
database.
+---------------+---------------+---------------+----------------+
| pct_length_10 | pct_length_20 | pct_length_50 | pct_length_100 |
+---------------+---------------+---------------+----------------+
| 2.14 | 15.96 | 77.80 | 99.48 |
+---------------+---------------+---------------+----------------+
So 100 characters gets 99.48% of file names. Our longest filename is
249 characters apparently. We could probably optimize this with
partial indexes if required.
Change-Id: Ide9a8c647565d657d691a73be76129f237bf6ebb
diff --git a/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java b/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
index b0a3370..dd82be2 100644
--- a/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
+++ b/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
@@ -22,6 +22,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.sql.SQLException;
+import java.sql.Statement;
import org.eclipse.jgit.lib.Config;
@Singleton
@@ -50,4 +51,17 @@
return new StorageException(op + " failure on ACCOUNT_PATCH_REVIEWS", err);
}
}
+
+ @Override
+ protected void doCreateTable(Statement stmt) throws SQLException {
+ stmt.executeUpdate(
+ "CREATE TABLE IF NOT EXISTS account_patch_reviews ("
+ + "account_id INTEGER DEFAULT 0 NOT NULL, "
+ + "change_id INTEGER DEFAULT 0 NOT NULL, "
+ + "patch_set_id INTEGER DEFAULT 0 NOT NULL, "
+ + "file_name VARCHAR(255) DEFAULT '' NOT NULL, "
+ + "CONSTRAINT primary_key_account_patch_reviews "
+ + "PRIMARY KEY (change_id, patch_set_id, account_id, file_name)"
+ + ")");
+ }
}