From add8cddbb9d6dd14698329a2aea22feebe290d05 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 25 Aug 2017 21:27:17 +0200 Subject: [PATCH] Improve DB migration 1267 on MySQL In our LTS upgrade environment: Before 13 hours After 10 minutes --- .../v60/PopulateAnalysisUuidOnMeasures.java | 14 +++++++++++--- 1 file 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); -- 2.39.5