From: Julien Lancelot Date: Wed, 12 Jun 2013 08:58:43 +0000 (+0200) Subject: SONAR-3755 Fix big performance issue on selectChildrenComponentIds query X-Git-Tag: 3.6~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=414edae8ff2e18bd75cb76bfbc5c5fdd365b6e66;p=sonarqube.git SONAR-3755 Fix big performance issue on selectChildrenComponentIds query --- diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 0b6d58823bb..11cd702ab84 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -126,30 +126,52 @@ - select s.project_id - from snapshots s - inner join snapshots rootsnapshots on (rootsnapshots.id=s.id or ((rootsnapshots.id=s.root_snapshot_id or rootsnapshots.root_snapshot_id=s.root_snapshot_id) and + -- project ids of the children of a component which is not PRJ/TRK + select children.project_id + from snapshots children + inner join ( + select rootSnapshot.id, rootSnapshot.root_snapshot_id, rootSnapshot.path from snapshots rootSnapshot + + rootSnapshot.project_id in ( + select p.id from projects p where p.enabled=${_true} + and p.kee in #{componentKey} + ) + and rootSnapshot.islast=${_true} + and rootSnapshot.root_snapshot_id is not null + + ) rootSnapshot on children.root_snapshot_id = rootSnapshot.root_snapshot_id + and - s.path LIKE rootsnapshots.path + CAST(rootsnapshots.id AS varchar(15)) + '.%' + children.path LIKE rootSnapshot.path + CAST(rootSnapshot.id AS varchar(15)) + '.%' - s.path LIKE concat(rootsnapshots.path, rootsnapshots.id, '.%') + children.path LIKE concat(rootSnapshot.path, rootSnapshot.id, '.%') - s.path LIKE rootsnapshots.path || rootsnapshots.id || '.%' + children.path LIKE rootSnapshot.path || rootSnapshot.id || '.%' - )) - and rootsnapshots.islast=${_true} - - and s.islast=${_true} - and rootsnapshots.project_id in - (select p.id from projects p where p.enabled=${_true} - and p.kee in #{componentKey}) - + + union + -- project ids of the children of a PRJ/TRK component + select children.project_id from snapshots children + inner join ( + select rootSnapshot.id from snapshots rootSnapshot + + rootSnapshot.project_id in ( + select p.id from projects p where p.enabled=${_true} + and p.kee in #{componentKey} + ) + and rootSnapshot.islast=${_true} + and rootSnapshot.root_snapshot_id is null + + ) rootSnapshot on children.root_snapshot_id = rootSnapshot.id + union + -- project id of the component itself + select p.id as project_id from projects p where p.enabled=true + and p.kee in #{componentKey} - insert into projects (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at)