]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 remove useless SQL join when indexing issues
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 1 Aug 2017 13:19:47 +0000 (15:19 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 08:55:09 +0000 (10:55 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueIteratorFactoryTest/one_issue.xml
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueIteratorFactoryTest/shared.xml

index 081d44c6afeb87337136f82073232b4372a96436..a939bfac5a1841e67210550ada9df8195c1e3f1f 100644 (file)
@@ -54,7 +54,6 @@ class IssueIteratorForSingleChunk implements IssueIterator {
   private static final String[] FIELDS = {
     // column 1
     "i.kee",
-    "root.uuid",
     "i.assignee",
     "i.line",
     "i.resolution",
@@ -63,9 +62,9 @@ class IssueIteratorForSingleChunk implements IssueIterator {
     "i.effort",
     "i.author_login",
     "i.issue_close_date",
+    "i.issue_creation_date",
 
     // column 11
-    "i.issue_creation_date",
     "i.issue_update_date",
     "r.plugin_name",
     "r.plugin_rule_key",
@@ -75,6 +74,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
     "p.path",
     "p.scope",
     "p.organization_uuid",
+    "p.project_uuid",
 
     // column 21
     "i.tags",
@@ -82,12 +82,11 @@ class IssueIteratorForSingleChunk implements IssueIterator {
   };
 
   private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from issues i " +
-    "inner join rules r on r.id=i.rule_id " +
-    "inner join projects p on p.uuid=i.component_uuid " +
-    "inner join projects root on root.uuid=i.project_uuid";
+    "inner join rules r on r.id = i.rule_id " +
+    "inner join projects p on p.uuid = i.component_uuid ";
 
-  private static final String PROJECT_FILTER = " AND root.uuid=?";
-  private static final String ISSUE_KEY_FILTER_PREFIX = " AND i.kee IN (";
+  private static final String PROJECT_FILTER = " and p.project_uuid=?";
+  private static final String ISSUE_KEY_FILTER_PREFIX = " and i.kee in (";
   private static final String ISSUE_KEY_FILTER_SUFFIX = ")";
 
   static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
@@ -187,34 +186,34 @@ class IssueIteratorForSingleChunk implements IssueIterator {
       IssueDoc doc = new IssueDoc(Maps.newHashMapWithExpectedSize(30));
 
       String key = rs.getString(1);
-      String projectUuid = rs.getString(2);
 
       // all the fields must be present, even if value is null
       doc.setKey(key);
-      doc.setProjectUuid(projectUuid);
-      doc.setAssignee(rs.getString(3));
-      doc.setLine(DatabaseUtils.getInt(rs, 4));
-      doc.setResolution(rs.getString(5));
-      doc.setSeverity(rs.getString(6));
-      doc.setStatus(rs.getString(7));
-      doc.setEffort(getLong(rs, 8));
-      doc.setAuthorLogin(rs.getString(9));
-      doc.setFuncCloseDate(longToDate(getLong(rs, 10)));
-      doc.setFuncCreationDate(longToDate(getLong(rs, 11)));
-      doc.setFuncUpdateDate(longToDate(getLong(rs, 12)));
-      String ruleRepo = rs.getString(13);
-      String ruleKey = rs.getString(14);
+      doc.setAssignee(rs.getString(2));
+      doc.setLine(DatabaseUtils.getInt(rs, 3));
+      doc.setResolution(rs.getString(4));
+      doc.setSeverity(rs.getString(5));
+      doc.setStatus(rs.getString(6));
+      doc.setEffort(getLong(rs, 7));
+      doc.setAuthorLogin(rs.getString(8));
+      doc.setFuncCloseDate(longToDate(getLong(rs, 9)));
+      doc.setFuncCreationDate(longToDate(getLong(rs, 10)));
+      doc.setFuncUpdateDate(longToDate(getLong(rs, 11)));
+      String ruleRepo = rs.getString(12);
+      String ruleKey = rs.getString(13);
       doc.setRuleKey(RuleKey.of(ruleRepo, ruleKey).toString());
-      doc.setLanguage(rs.getString(15));
-      doc.setComponentUuid(rs.getString(16));
-      String moduleUuidPath = rs.getString(17);
+      doc.setLanguage(rs.getString(14));
+      doc.setComponentUuid(rs.getString(15));
+      String moduleUuidPath = rs.getString(16);
       doc.setModuleUuid(extractModule(moduleUuidPath));
       doc.setModuleUuidPath(moduleUuidPath);
-      String scope = rs.getString(19);
-      String filePath = extractFilePath(rs.getString(18), scope);
+      String scope = rs.getString(18);
+      String filePath = extractFilePath(rs.getString(17), scope);
       doc.setFilePath(filePath);
       doc.setDirectoryPath(extractDirPath(doc.filePath(), scope));
-      doc.setOrganizationUuid(rs.getString(20));
+      doc.setOrganizationUuid(rs.getString(19));
+      String projectUuid = rs.getString(20);
+      doc.setProjectUuid(projectUuid);
       String tags = rs.getString(21);
       doc.setTags(ImmutableList.copyOf(IssueIteratorForSingleChunk.TAGS_SPLITTER.split(tags == null ? "" : tags)));
       doc.setType(RuleType.valueOf(rs.getInt(22)));
index 757dbfb067dcc90a38f3f72619cb7380192e73c9..aba2b242e359390a5e732e47a5a940f03fa0f519 100644 (file)
@@ -36,7 +36,7 @@
             uuid="DIR1"
             uuid_path="NOT_USED"
             root_uuid="MODULE1"
-            project_uuid="MODULE1"
+            project_uuid="PROJECT1"
             path="src/main/java"
             module_uuid_path=".PROJECT1.MODULE1."
             id="70"
@@ -49,7 +49,7 @@
             uuid="FILE1"
             uuid_path="NOT_USED"
             root_uuid="MODULE1"
-            project_uuid="MODULE1"
+            project_uuid="PROJECT1"
             path="src/main/java/Action.java"
             module_uuid_path=".PROJECT1."
             id="100"
index e952552b8f5748b16f8bc488ac216f1d375885a7..9b1d90ed52d60cd8aa1d26d91274d0932308923f 100644 (file)
@@ -36,7 +36,7 @@
             uuid="DIR1"
             uuid_path="NOT_USED"
             root_uuid="MODULE1"
-            project_uuid="MODULE1"
+            project_uuid="PROJECT1"
             path="src/main/java"
             module_uuid_path=".PROJECT1.MODULE1."
             id="70"
@@ -49,7 +49,7 @@
             uuid="FILE1"
             uuid_path="NOT_USED"
             root_uuid="MODULE1"
-            project_uuid="MODULE1"
+            project_uuid="PROJECT1"
             path="src/main/java/Action.java"
             module_uuid_path=".PROJECT1."
             id="100"