Deprecate database indexes used only by SqlRewriterImpl

These methods are only invoked by SqlRewriterImpl. A server relying
on secondary indexing does not need these indexes to be present in
the database. Mark the methods deprecated to discourage new uses.

Change-Id: Ia9eea39a994abc20e2c9735b6a98c028a86bbc53
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/ChangeAccess.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/ChangeAccess.java
index 66df78a..9618bc3 100644
--- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/ChangeAccess.java
+++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/ChangeAccess.java
@@ -42,12 +42,11 @@
   @Query("WHERE dest.projectName = ?")
   ResultSet<Change> byProject(Project.NameKey p) throws OrmException;
 
+  @Deprecated
   @Query("WHERE owner = ? AND open = true ORDER BY createdOn, changeId")
   ResultSet<Change> byOwnerOpen(Account.Id id) throws OrmException;
 
-  @Query("WHERE owner = ? AND open = false ORDER BY lastUpdatedOn DESC LIMIT 5")
-  ResultSet<Change> byOwnerClosed(Account.Id id) throws OrmException;
-
+  @Deprecated
   @Query("WHERE owner = ? AND open = false ORDER BY lastUpdatedOn")
   ResultSet<Change> byOwnerClosedAll(Account.Id id) throws OrmException;
 
@@ -58,9 +57,11 @@
   @Query("WHERE status = '" + Change.STATUS_SUBMITTED + "'")
   ResultSet<Change> allSubmitted() throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = true AND sortKey > ? ORDER BY sortKey LIMIT ?")
   ResultSet<Change> allOpenPrev(String sortKey, int limit) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = true AND sortKey < ? ORDER BY sortKey DESC LIMIT ?")
   ResultSet<Change> allOpenNext(String sortKey, int limit) throws OrmException;
 
@@ -70,6 +71,7 @@
   @Query("WHERE open = true AND dest = ?")
   ResultSet<Change> byBranchOpenAll(Branch.NameKey p) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = true AND dest.projectName = ? AND sortKey > ?"
       + " ORDER BY sortKey LIMIT ?")
   ResultSet<Change> byProjectOpenPrev(Project.NameKey p, String sortKey,
@@ -80,29 +82,35 @@
   ResultSet<Change> byProjectOpenNext(Project.NameKey p, String sortKey,
       int limit) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND dest.projectName = ? AND sortKey > ?"
       + " ORDER BY sortKey LIMIT ?")
   ResultSet<Change> byProjectClosedPrev(char status, Project.NameKey p,
       String sortKey, int limit) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND dest.projectName = ? AND sortKey < ?"
       + " ORDER BY sortKey DESC LIMIT ?")
   ResultSet<Change> byProjectClosedNext(char status, Project.NameKey p,
       String sortKey, int limit) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND sortKey > ? ORDER BY sortKey LIMIT ?")
   ResultSet<Change> allClosedPrev(char status, String sortKey, int limit)
       throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND sortKey < ? ORDER BY sortKey DESC LIMIT ?")
   ResultSet<Change> allClosedNext(char status, String sortKey, int limit)
       throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND dest = ? AND sortKey > ?"
       + " ORDER BY sortKey LIMIT ?")
   ResultSet<Change> byBranchClosedPrev(char status, Branch.NameKey p,
       String sortKey, int limit) throws OrmException;
 
+  @Deprecated
   @Query("WHERE open = false AND status = ? AND dest = ? AND sortKey < ?"
       + " ORDER BY sortKey DESC LIMIT ?")
   ResultSet<Change> byBranchClosedNext(char status, Branch.NameKey p,
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/PatchSetApprovalAccess.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/PatchSetApprovalAccess.java
index dae8e6d..25dfdbd 100644
--- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/PatchSetApprovalAccess.java
+++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/server/PatchSetApprovalAccess.java
@@ -39,15 +39,12 @@
   ResultSet<PatchSetApproval> byPatchSetUser(PatchSet.Id patchSet,
       Account.Id account) throws OrmException;
 
+  @Deprecated
   @Query("WHERE changeOpen = true AND key.accountId = ?")
   ResultSet<PatchSetApproval> openByUser(Account.Id account)
       throws OrmException;
 
-  @Query("WHERE changeOpen = false AND key.accountId = ?"
-      + " ORDER BY changeSortKey DESC LIMIT 10")
-  ResultSet<PatchSetApproval> closedByUser(Account.Id account)
-      throws OrmException;
-
+  @Deprecated
   @Query("WHERE changeOpen = false AND key.accountId = ? ORDER BY changeSortKey")
   ResultSet<PatchSetApproval> closedByUserAll(Account.Id account)
       throws OrmException;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/SqlRewriterImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/SqlRewriterImpl.java
index 34fe3fb..c94ee12 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/SqlRewriterImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/SqlRewriterImpl.java
@@ -81,6 +81,7 @@
       @Named("S") final SortKeyPredicate.After s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -105,6 +106,7 @@
       @Named("S") final SortKeyPredicate.Before s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -128,6 +130,7 @@
       @Named("S") final SortKeyPredicate.After s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(500, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -170,6 +173,7 @@
       @Named("S") final SortKeyPredicate.After s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -192,6 +196,7 @@
       @Named("S") final SortKeyPredicate.Before s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -214,6 +219,7 @@
       @Named("S") final SortKeyPredicate.After s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -236,6 +242,7 @@
       @Named("S") final SortKeyPredicate.Before s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(40000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -257,6 +264,7 @@
       @Named("S") final SortKeyPredicate.After s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(2000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -275,6 +283,7 @@
       @Named("S") final SortKeyPredicate.Before s,
       @Named("L") final IntPredicate<ChangeData> l) {
     return new PaginatedSource(2000, s.getValue(), l.intValue()) {
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -298,6 +307,7 @@
         init("r20_byMergedPrev", s, l);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -322,6 +332,7 @@
         init("r20_byMergedNext", s, l);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -346,6 +357,7 @@
         init("r20_byAbandonedPrev", s, l);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -370,6 +382,7 @@
         init("r20_byAbandonedNext", s, l);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a, String key, int limit)
           throws OrmException {
@@ -409,6 +422,7 @@
         init("r25_byOwnerOpen", o);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a) throws OrmException {
         return a.byOwnerOpen(o.getAccountId());
@@ -430,6 +444,7 @@
         init("r25_byOwnerClosed", o);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       ResultSet<Change> scan(ChangeAccess a) throws OrmException {
         return a.byOwnerClosedAll(o.getAccountId());
@@ -457,6 +472,7 @@
         init("r30_byReviewerOpen", r);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       public ResultSet<ChangeData> read() throws OrmException {
         return ChangeDataResultSet.patchSetApproval(dbProvider.get()
@@ -490,6 +506,7 @@
         init("r30_byReviewerClosed", r);
       }
 
+      @SuppressWarnings("deprecation")
       @Override
       public ResultSet<ChangeData> read() throws OrmException {
         return ChangeDataResultSet.patchSetApproval(dbProvider.get()