diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-26 16:47:54 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-29 12:12:16 +0100 |
commit | cbf142857bfce52b0131ade69ce34880f813f2e7 (patch) | |
tree | 2294fe7aa748c156662b12a3e3ce13ee35fd76dc /sonar-db/src/test | |
parent | afe276c062e03d7c0ed7bab97b0ee8cf0511423e (diff) | |
download | sonarqube-cbf142857bfce52b0131ade69ce34880f813f2e7.tar.gz sonarqube-cbf142857bfce52b0131ade69ce34880f813f2e7.zip |
Replace SQL "count(*)" by "count(1)"
It can have slight performance improvements on some databases.
Diffstat (limited to 'sonar-db/src/test')
17 files changed, 35 insertions, 35 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java b/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java index b4c129d8af7..812ad84eb32 100644 --- a/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java +++ b/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java @@ -170,7 +170,7 @@ public abstract class DatabaseCommands { Statement stmt = connection.createStatement(); ResultSet rs = null; try { - rs = stmt.executeQuery("select count(*) from " + table); + rs = stmt.executeQuery("select count(1) from " + table); if (rs.next()) { return rs.getInt(1) > 0; } diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java index 5e7531562e1..55ca750d3dc 100644 --- a/sonar-db/src/test/java/org/sonar/db/DbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java @@ -144,7 +144,7 @@ public class DbTester extends ExternalResource { */ public int countRowsOfTable(String tableName) { Preconditions.checkArgument(StringUtils.containsNone(tableName, " "), "Parameter must be the name of a table. Got " + tableName); - return countSql("select count(*) from " + tableName); + return countSql("select count(1) from " + tableName); } /** diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java index ef82c1813ac..9c393f0e67c 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java @@ -86,11 +86,11 @@ public class ResourceIndexDaoTest { dao.indexProject(1); // project - assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=1")).isGreaterThan(0); + assertThat(dbTester.countSql("select count(1) from resource_index where resource_id=1")).isGreaterThan(0); // directory - assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=2")).isEqualTo(0); + assertThat(dbTester.countSql("select count(1) from resource_index where resource_id=2")).isEqualTo(0); // file - assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=3")).isGreaterThan(0); + assertThat(dbTester.countSql("select count(1) from resource_index where resource_id=3")).isGreaterThan(0); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index ce61889688b..5c7192d66ee 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -148,7 +148,7 @@ public class PurgeDaoTest { underTest.deleteProject(dbSession, "A"); dbSession.commit(); - assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero(); + assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero(); assertThat(dbTester.countRowsOfTable("projects")).isZero(); } @@ -159,17 +159,17 @@ public class PurgeDaoTest { // technical project underTest.deleteProject(dbSession, "D"); dbSession.commit(); - assertThat(dbTester.countSql("select count(id) from projects where uuid='D'")).isZero(); + assertThat(dbTester.countSql("select count(1) from projects where uuid='D'")).isZero(); // sub view underTest.deleteProject(dbSession, "B"); dbSession.commit(); - assertThat(dbTester.countSql("select count(id) from projects where uuid='B'")).isZero(); + assertThat(dbTester.countSql("select count(1) from projects where uuid='B'")).isZero(); // view underTest.deleteProject(dbSession, "A"); dbSession.commit(); - assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero(); + assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero(); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/version/v50/FeedIssueLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v50/FeedIssueLongDatesTest.java index 2c009e825f8..2c64d884f62 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v50/FeedIssueLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v50/FeedIssueLongDatesTest.java @@ -43,7 +43,7 @@ public class FeedIssueLongDatesTest { MigrationStep migration = new FeedIssueLongDates(db.database(), system); migration.execute(); - int count = db.countSql("select count(*) from issues where created_at_ms is not null and updated_at_ms is not null"); + int count = db.countSql("select count(1) from issues where created_at_ms is not null and updated_at_ms is not null"); assertThat(count).isEqualTo(3); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/CopyScmAccountsFromAuthorsToUsersTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/CopyScmAccountsFromAuthorsToUsersTest.java index 2d6f8405ab8..43769596e1c 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/CopyScmAccountsFromAuthorsToUsersTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/CopyScmAccountsFromAuthorsToUsersTest.java @@ -80,8 +80,8 @@ public class CopyScmAccountsFromAuthorsToUsersTest { migration.execute(); - assertThat(db.countSql("SELECT count(*) FROM USERS WHERE updated_at=" + updatedDate)).isEqualTo(0); - assertThat(db.countSql("SELECT count(*) FROM USERS WHERE updated_at=" + oldDate)).isEqualTo(7); + assertThat(db.countSql("SELECT count(1) FROM USERS WHERE updated_at=" + updatedDate)).isEqualTo(0); + assertThat(db.countSql("SELECT count(1) FROM USERS WHERE updated_at=" + oldDate)).isEqualTo(7); } private User getUserByLogin(String login) { diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedAnalysisReportsLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedAnalysisReportsLongDatesTest.java index 2d9e13d0058..2900b8b35c1 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedAnalysisReportsLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedAnalysisReportsLongDatesTest.java @@ -42,11 +42,11 @@ public class FeedAnalysisReportsLongDatesTest { MigrationStep migration = new FeedAnalysisReportsLongDates(db.database(), system); migration.execute(); - int count = db.countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null"); + int count = db.countSql("select count(1) from analysis_reports where created_at_ms is not null and updated_at_ms is not null"); assertThat(count).isEqualTo(3); int countWithAllDateFieldsNull = db - .countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null and started_at_ms is not null and finished_at_ms is not null"); + .countSql("select count(1) from analysis_reports where created_at_ms is not null and updated_at_ms is not null and started_at_ms is not null and finished_at_ms is not null"); assertThat(countWithAllDateFieldsNull).isEqualTo(2); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedEventsLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedEventsLongDatesTest.java index 26e766a33dd..fee3a503ce8 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedEventsLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedEventsLongDatesTest.java @@ -47,7 +47,7 @@ public class FeedEventsLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from events where " + + .countSql("select count(1) from events where " + "created_at_ms is not null " + "and event_date_ms is not null"); assertThat(count).isEqualTo(3); @@ -63,7 +63,7 @@ public class FeedEventsLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from events where " + + .countSql("select count(1) from events where " + "created_at_ms = 1234"); assertThat(count).isEqualTo(2); } @@ -76,7 +76,7 @@ public class FeedEventsLongDatesTest { long time = parseDate("2014-09-25").getTime(); int count = db - .countSql("select count(*) from events where " + + .countSql("select count(1) from events where " + "created_at_ms=" + time); assertThat(count).isEqualTo(1); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java index 65458da7acd..a3a93e51ca3 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java @@ -51,7 +51,7 @@ public class FeedFileSourcesBinaryDataTest { MigrationStep migration = new FeedFileSourcesBinaryData(db.database()); migration.execute(); - int count = db.countSql("select count(*) from file_sources where binary_data is not null"); + int count = db.countSql("select count(1) from file_sources where binary_data is not null"); assertThat(count).isEqualTo(3); try (Connection connection = db.openConnection()) { diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssueChangesLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssueChangesLongDatesTest.java index 5abccafdd7b..ee1e6dbae4c 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssueChangesLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssueChangesLongDatesTest.java @@ -42,11 +42,11 @@ public class FeedIssueChangesLongDatesTest { MigrationStep migration = new FeedIssueChangesLongDates(db.database(), system); migration.execute(); - int count = db.countSql("select count(*) from issue_changes where created_at_ms is not null and updated_at_ms is not null"); + int count = db.countSql("select count(1) from issue_changes where created_at_ms is not null and updated_at_ms is not null"); assertThat(count).isEqualTo(3); int countWithAllDateFieldsNull = db - .countSql("select count(*) from issue_changes where created_at_ms is not null and updated_at_ms is not null and issue_change_creation_date_ms is not null"); + .countSql("select count(1) from issue_changes where created_at_ms is not null and updated_at_ms is not null and issue_change_creation_date_ms is not null"); assertThat(countWithAllDateFieldsNull).isEqualTo(2); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssuesLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssuesLongDatesTest.java index be15120aa82..123c3727512 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssuesLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssuesLongDatesTest.java @@ -42,7 +42,7 @@ public class FeedIssuesLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from issues where " + + .countSql("select count(1) from issues where " + "issue_creation_date_ms is not null " + "and issue_update_date_ms is not null " + "and issue_close_date_ms is not null"); @@ -59,7 +59,7 @@ public class FeedIssuesLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from issues where " + + .countSql("select count(1) from issues where " + "issue_creation_date_ms = 0"); assertThat(count).isEqualTo(1); } @@ -73,7 +73,7 @@ public class FeedIssuesLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from issues where " + + .countSql("select count(1) from issues where " + "issue_creation_date_ms=" + snapshotTime); assertThat(count).isEqualTo(1); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedManualMeasuresLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedManualMeasuresLongDatesTest.java index 12da57dd9c1..32498793fb1 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedManualMeasuresLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedManualMeasuresLongDatesTest.java @@ -47,7 +47,7 @@ public class FeedManualMeasuresLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from manual_measures where " + + .countSql("select count(1) from manual_measures where " + "created_at_ms is not null " + "and updated_at_ms is not null"); assertThat(count).isEqualTo(2); @@ -63,7 +63,7 @@ public class FeedManualMeasuresLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from manual_measures where " + + .countSql("select count(1) from manual_measures where " + "created_at_ms = 1234"); assertThat(count).isEqualTo(1); } @@ -76,7 +76,7 @@ public class FeedManualMeasuresLongDatesTest { long snapshotTime = parseDate("2014-09-25").getTime(); int count = db - .countSql("select count(*) from manual_measures where " + + .countSql("select count(1) from manual_measures where " + "created_at_ms=" + snapshotTime); assertThat(count).isEqualTo(1); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedSnapshotsLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedSnapshotsLongDatesTest.java index 1d414459270..6cdab7d90bd 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedSnapshotsLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedSnapshotsLongDatesTest.java @@ -42,7 +42,7 @@ public class FeedSnapshotsLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from snapshots where created_at_ms is not null " + + .countSql("select count(1) from snapshots where created_at_ms is not null " + "and build_date_ms is not null " + "and period1_date_ms is not null " + "and period2_date_ms is not null " + @@ -62,7 +62,7 @@ public class FeedSnapshotsLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from snapshots where " + + .countSql("select count(1) from snapshots where " + "created_at_ms = 0"); assertThat(count).isEqualTo(1); } @@ -76,7 +76,7 @@ public class FeedSnapshotsLongDatesTest { migration.execute(); int count = db - .countSql("select count(*) from snapshots where " + + .countSql("select count(1) from snapshots where " + "created_at_ms=" + snapshotTime); assertThat(count).isEqualTo(1); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedUsersLongDatesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedUsersLongDatesTest.java index 556e00a271b..00d63a37f59 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedUsersLongDatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedUsersLongDatesTest.java @@ -43,7 +43,7 @@ public class FeedUsersLongDatesTest { MigrationStep migration = new FeedUsersLongDates(db.database(), system); migration.execute(); - int count = db.countSql("select count(*) from users where created_at_ms is not null and updated_at_ms is not null"); + int count = db.countSql("select count(1) from users where created_at_ms is not null and updated_at_ms is not null"); assertThat(count).isEqualTo(3); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v54/InsertGateAdminPermissionForEachProfileAdminTest.java b/sonar-db/src/test/java/org/sonar/db/version/v54/InsertGateAdminPermissionForEachProfileAdminTest.java index 5e099a5f89f..8afdbdf09ab 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v54/InsertGateAdminPermissionForEachProfileAdminTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v54/InsertGateAdminPermissionForEachProfileAdminTest.java @@ -230,7 +230,7 @@ public class InsertGateAdminPermissionForEachProfileAdminTest { private static String groupRoleRowSql(@Nullable Integer groupId, @Nullable Integer resourceId, String role) { return format( - "select count(*) from group_roles where group_id %s and resource_id %s and role = '%s'", + "select count(1) from group_roles where group_id %s and resource_id %s and role = '%s'", whereClauseFromInteger(groupId), whereClauseFromInteger(resourceId), role); @@ -248,7 +248,7 @@ public class InsertGateAdminPermissionForEachProfileAdminTest { private static String userRoleRowSql(@Nullable Integer userId, @Nullable Integer resourceId, String role) { return format( - "select count(*) from user_roles where user_id %s and resource_id %s and role = '%s'", + "select count(1) from user_roles where user_id %s and resource_id %s and role = '%s'", whereClauseFromInteger(userId), whereClauseFromInteger(resourceId), role); diff --git a/sonar-db/src/test/java/org/sonar/db/version/v54/RemoveComponentPagePropertiesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v54/RemoveComponentPagePropertiesTest.java index 5c0c2eec331..8533751c82f 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v54/RemoveComponentPagePropertiesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v54/RemoveComponentPagePropertiesTest.java @@ -116,7 +116,7 @@ public class RemoveComponentPagePropertiesTest { private static String propertiesRowSql(String key, @Nullable Integer resourceId, @Nullable Integer userId) { return format( - "select count(*) from properties where prop_key='%s' and resource_id %s and user_id %s and text_value = '%s'", + "select count(1) from properties where prop_key='%s' and resource_id %s and user_id %s and text_value = '%s'", key, whereClauseOfInteger(resourceId), whereClauseOfInteger(userId), diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java index 240c0e79345..ff33afa7152 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/FeedRulesLongDateColumnsTest.java @@ -52,9 +52,9 @@ public class FeedRulesLongDateColumnsTest { underTest.execute(); - assertThat(db.countSql("select count(*) from rules where created_at_ms is not null and updated_at_ms is not null")).isEqualTo(3); + assertThat(db.countSql("select count(1) from rules where created_at_ms is not null and updated_at_ms is not null")).isEqualTo(3); // Only 1 rules not updated - assertThat(db.countSql("select count(*) from rules where created_at_ms='1000000000000' and updated_at_ms='1000000000000'")).isEqualTo(1); + assertThat(db.countSql("select count(1) from rules where created_at_ms='1000000000000' and updated_at_ms='1000000000000'")).isEqualTo(1); } } |