aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-25 21:27:17 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-25 21:27:17 +0200
commitadd8cddbb9d6dd14698329a2aea22feebe290d05 (patch)
treeb63594418fa943ba9db6837f1c4031e01f850ef5 /server/sonar-db-migration/src
parent51add9c146a5448ce130d6d83f7220bef7316f92 (diff)
downloadsonarqube-add8cddbb9d6dd14698329a2aea22feebe290d05.tar.gz
sonarqube-add8cddbb9d6dd14698329a2aea22feebe290d05.zip
Improve DB migration 1267 on MySQL
In our LTS upgrade environment: Before 13 hours After 10 minutes
Diffstat (limited to 'server/sonar-db-migration/src')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java
index c235d364899..fd213140d08 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v60/PopulateAnalysisUuidOnMeasures.java
@@ -35,11 +35,19 @@ public class PopulateAnalysisUuidOnMeasures extends DataChange {
@Override
public void execute(Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("select distinct m.snapshot_id, root_snapshots.uuid " +
+ // mysql can take hours if the 2 requests are merged into a single one
+ massUpdate.select("select distinct m.snapshot_id as sId, root_snapshots.uuid as rootUuid " +
"from project_measures m " +
"inner join snapshots s on m.snapshot_id=s.id " +
- "inner join snapshots root_snapshots on s.root_snapshot_id=root_snapshots.id or (s.root_snapshot_id is null and s.id=root_snapshots.id) " +
- "where m.analysis_uuid is null");
+ "inner join snapshots root_snapshots on s.root_snapshot_id = root_snapshots.id " +
+ "where m.analysis_uuid is null " +
+ "union " +
+ "select distinct m.snapshot_id as sId, root_snapshots.uuid as rootUuid " +
+ "from project_measures m " +
+ "inner join snapshots s on m.snapshot_id=s.id " +
+ "inner join snapshots root_snapshots on s.root_snapshot_id is null and s.id = root_snapshots.id " +
+ "where m.analysis_uuid is null"
+ );
massUpdate.update("update project_measures set analysis_uuid=? where snapshot_id=? and analysis_uuid is null");
massUpdate.rowPluralName("measures");
massUpdate.execute(PopulateAnalysisUuidOnMeasures::handle);