It can have slight performance improvements on some databases.
}
private int count(String condition) {
- return orchestrator.getDatabase().countSql("select count(*) from " + condition);
+ return orchestrator.getDatabase().countSql("select count(1) from " + condition);
}
private void assertMeasuresCountForQualifier(String qualifier, int count) {
}
private int countMeasures(String qualifier) {
- String sql = "SELECT count(pm.id) FROM project_measures pm, snapshots s, metrics m where pm.snapshot_id=s.id and pm.metric_id=m.id and s.qualifier='" + qualifier + "'";
+ String sql = "SELECT count(1) FROM project_measures pm, snapshots s, metrics m where pm.snapshot_id=s.id and pm.metric_id=m.id and s.qualifier='" + qualifier + "'";
return orchestrator.getDatabase().countSql(sql);
}
public class TechnicalDebtPurgeTest {
- private static final String SQL_COUNT_MEASURES_ON_CHARACTERISTICS = "select count(*) from project_measures where characteristic_id is not null";
- private static final String SQL_COUNT_MEASURES_ON_DEBT_MEASURES_WITH_RULES = "select count(*) from project_measures where rule_id is not null and metric_id in (select id from metrics where name='sqale_index')";
+ private static final String SQL_COUNT_MEASURES_ON_CHARACTERISTICS = "select count(1) from project_measures where characteristic_id is not null";
+ private static final String SQL_COUNT_MEASURES_ON_DEBT_MEASURES_WITH_RULES = "select count(1) from project_measures where rule_id is not null and metric_id in (select id from metrics where name='sqale_index')";
@ClassRule
public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
}
private int count(String condition) {
- return orchestrator.getDatabase().countSql("select count(*) from " + condition);
+ return orchestrator.getDatabase().countSql("select count(1) from " + condition);
}
}
Connection connection = session.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
- String sql = "SELECT count(*) FROM properties pp " +
+ String sql = "SELECT count(1) FROM properties pp " +
"left outer join projects pj on pp.resource_id = pj.id " +
"where pp.user_id is not null and (pp.resource_id is null or pj.uuid=?) " +
"and (" + DatabaseUtils.repeatCondition("pp.prop_key like ?", dispatcherKeys.size(), "or") + ")";
</select>
<select id="countByStatus" parameterType="org.sonar.db.ce.CeQueueDto$Status" resultType="int">
- select count(id) from ce_queue where status=#{status}
+ select count(1) from ce_queue where status=#{status}
</select>
<select id="countAll" resultType="int">
- select count(id) from ce_queue
+ select count(1) from ce_queue
</select>
<select id="selectByComponentUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
</select>
<select id="countByQuery" resultType="int">
- select count(id)
+ select count(1)
<include refid="sqlSelectByQuery"/>
</select>
</resultMap>
<select id="countResourceByKey" parameterType="String" resultType="int">
- SELECT count(*)
+ SELECT count(1)
FROM projects
WHERE kee = #{key}
</select>
</select>
<select id="countLastSnapshotByComponentUuid" resultType="Integer">
- SELECT count(s.id)
+ SELECT count(1)
FROM snapshots s
INNER JOIN projects p ON p.id=s.project_id AND p.uuid=#{componentUuid}
<where>
</resultMap>
<select id="countByTypeAndKey" parameterType="map" resultType="int">
- SELECT count(*)
+ SELECT count(1)
FROM loaded_templates
WHERE kee = #{key} AND template_type = #{type}
</select>
</delete>
<select id="countByComponentUuid" resultType="Integer">
- select count(*)
+ select count(1)
from manual_measures m
where m.component_uuid=#{componentUuid}
</select>
<select id="countByComponentIdAndMetricId" resultType="Integer">
- select count(*)
+ select count(1)
from manual_measures m
where m.metric_id=#{metricId} and m.component_uuid=#{componentUuid}
</select>
</select>
<select id="countEnabled" resultType="Integer">
- SELECT COUNT(*)
+ SELECT COUNT(1)
FROM metrics m
<where>
AND m.enabled=${_true}
</delete>
<select id="count" resultType="long">
- select count(*) from notifications
+ select count(1) from notifications
</select>
<select id="findOldest" parameterType="int" resultType="NotificationQueue">
<select id="groupsCountByProjectIdAndPermission" parameterType="map"
resultType="org.sonar.db.permission.CountByProjectAndPermissionDto">
- SELECT count(name) as count, permission, componentId
+ SELECT count(1) as count, permission, componentId
FROM
(SELECT g.name as name, group_role.role as permission, group_role.resource_id as componentId
FROM groups g
</select>
<select id="countGroups" parameterType="map" resultType="int">
- SELECT count(name)
+ SELECT count(1)
FROM
(SELECT g.name as name
FROM groups g
</select>
<select id="countGroups" parameterType="map" resultType="int">
- SELECT count(name) FROM
+ SELECT count(1) FROM
(SELECT g.name as name, g.description as description, ptg.permission_reference as permission
FROM groups g
LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
</select>
<select id="countAll" parameterType="String" resultType="int">
- SELECT count(id)
+ SELECT count(1)
FROM permission_templates
<where>
<if test="nameMatch!=null">
<select id="groupsCountByTemplateIdAndPermission" parameterType="map"
resultType="org.sonar.db.permission.CountByTemplateAndPermissionDto">
- SELECT count(name) as count, permission, templateId
+ SELECT count(1) as count, permission, templateId
FROM
(SELECT g.name as name, ptg.permission_reference as permission, ptg.template_id as templateId
FROM groups g
</select>
<select id="countDeveloperLogins" parameterType="long" resultType="int">
- SELECT count(id)
+ SELECT count(1)
FROM authors WHERE person_id=#{id}
</select>
</select>
<select id="countByQuery" parameterType="map" resultType="int">
- SELECT count(g.id)
+ SELECT count(1)
FROM groups g
<where>
<if test="query!=null">
</delete>
<select id="countResourceUserRoles" parameterType="long" resultType="int">
- SELECT count(id)
+ SELECT count(1)
FROM user_roles WHERE resource_id=#{id}
</select>
<select id="countResourceGroupRoles" parameterType="long" resultType="int">
- SELECT count(id)
+ SELECT count(1)
FROM group_roles WHERE resource_id=#{id}
</select>
</select>
<select id="countByEmail" parameterType="String" resultType="long">
- SELECT count(u.id)
+ SELECT count(1)
FROM users u
where lower(u.email)=#{email} AND u.active=${_true}
</select>
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;
}
*/
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);
}
/**
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
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();
}
// 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
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);
}
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) {
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);
}
}
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);
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);
}
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);
}
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()) {
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);
}
}
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");
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);
}
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);
}
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);
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);
}
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);
}
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 " +
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);
}
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);
}
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);
}
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);
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);
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),
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);
}
}