]> source.dussan.org Git - sonarqube.git/commitdiff
Replace SQL "IN SELECT" by "EXISTS"
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 17 Mar 2017 12:23:23 +0000 (13:23 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 20 Mar 2017 20:31:59 +0000 (21:31 +0100)
This is a good practice to improve performances on some databases.

server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml

index 17dc2b5eac26f6f8c1fd15d2a990f8ecfe94fe80..dd5fc1ff306b6f5a628b1a277ffde21ec09b6fcf 100644 (file)
     FROM group_roles gr
     WHERE
     gr.role=#{role,jdbcType=VARCHAR}
-    and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where gu.user_id=#{userId}))
+    and (gr.group_id is null or exists (select 1 from groups_users gu where gu.user_id = #{userId, jdbcType=INTEGER} and gr.group_id = gu.group_id))
     and
     <foreach collection="componentIds" open="(" close=")" item="element" index="index" separator=" or ">
       gr.resource_id=#{element,jdbcType=BIGINT}
         INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL
         where
         gr.role=#{role,jdbcType=VARCHAR}
-        and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where
-        gu.user_id=#{userId,jdbcType=INTEGER}))
+        and (gr.group_id is null or exists (select 1 from groups_users gu where gu.user_id = #{userId,jdbcType=INTEGER} and gu.group_id = gr.group_id))
         UNION
         SELECT p.uuid as root_project_uuid
         FROM user_roles ur
index 0923db5ae6042262d2590c8e54b572cc570db743..1d305087cf812cd5ba4917c766fa481e0fbe5d2b 100644 (file)
@@ -46,7 +46,7 @@
 
   <delete id="deleteConditionsWithInvalidMetrics">
     delete from quality_gate_conditions
-    where metric_id not in (select id from metrics where enabled=${_true})
+    where not exists (select 1 from metrics m where m.enabled=${_true} and m.id = metric_id)
   </delete>
 
 </mapper>