]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20315 use pagination.offset in all paginated sql queries, and remove the concep...
authorPierre <pierre.guillot@sonarsource.com>
Thu, 28 Sep 2023 09:03:56 +0000 (11:03 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Sep 2023 20:02:46 +0000 (20:02 +0000)
23 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/OffsetBasedPagination.java
server/sonar-db-dao/src/main/java/org/sonar/db/Pagination.java
server/sonar-db-dao/src/main/java/org/sonar/db/Pagineable.java
server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateGroupPermissionsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/webhook/WebhookDeliveryMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/OffsetBasedPaginationTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java

index 3ba9042b683286e33650c2a7e47087a48a191479..fb50adafbc5224f5648c168fc5b10ae498b23024 100644 (file)
@@ -55,11 +55,6 @@ public class OffsetBasedPagination implements Pagineable {
     return new OffsetBasedPagination(startRowNumber - 1, pageSize);
   }
 
-  @Override
-  public int getStartRowNumber() {
-    return offset + 1;
-  }
-
   @Override
   public int getOffset() {
     return offset;
index 5ee079241a25d4b98a8bcabd232d49038abd4cfa..882c3a81bb9566e4840e09e09a1ead7c7e83fe67 100644 (file)
@@ -63,11 +63,6 @@ public final class Pagination implements Pagineable {
     return (page - 1) * pageSize;
   }
 
-  @Override
-  public int getStartRowNumber() {
-    return getOffset() + 1;
-  }
-
   public int getEndRowNumber() {
     return page * pageSize;
   }
index 5bba0a4d0a3781e8d3736cff4cb77c6e66cdd400..e6517bdb1251aff985ded163121d67ef1f9e00c8 100644 (file)
@@ -21,8 +21,6 @@ package org.sonar.db;
 
 public interface Pagineable {
 
-  int getStartRowNumber();
-
   int getOffset();
 
   int getPageSize();
index a532172fc604ca848b716ee2ab8abe53a49415dd..550789850ebdedfae3fc98089b4f0379d3b48262 100644 (file)
@@ -31,7 +31,7 @@
     from audits a
     where
       a.created_at &gt;= #{start} and a.created_at &lt; #{end}
-    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="selectByPeriodPaginated" parameterType="map" resultType="org.sonar.db.audit.AuditDto" databaseId="mssql">
@@ -43,7 +43,7 @@
         where created_at &gt;= #{start} and created_at &lt; #{end}
     ) as a
     where
-    a.row_number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    a.row_number between (#{pagination.offset,jdbcType=INTEGER}+1) and #{pagination.endRowNumber,jdbcType=INTEGER}
     order by a.row_number asc
   </select>
 
@@ -57,7 +57,7 @@
       ) t
     ) a
     where
-      a.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+      a.rn between (#{pagination.offset,jdbcType=INTEGER}+1) and #{pagination.endRowNumber,jdbcType=INTEGER}
     order by a.rn asc
   </select>
 
index b7761f317710833e18d1f3804ef0340e6cf43826..a53f15d1d2bd676fde8fa68f8ae0471d5dd372f6 100644 (file)
@@ -85,7 +85,7 @@
   <sql id="sqlSelectByQuery">
     <include refid="sqlSelectByQueryWithoutPagination"/>
     order by ca.created_at desc, uuid desc
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <select id="countByQuery" parameterType="map" resultType="int">
index c98190ef5242a217834dd080f8e03eca617c270c..88e1d5e5e132c0a96d7d45280491dc96414df811 100644 (file)
   </select>
 
   <sql id="pagination">
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <select id="countByQuery" resultType="int">
     select cq.uuid as ceTaskUuid, cq.created_at as createdAt
     <include refid="sqlSelectEligibleForPeek"/>
     <include refid="orderBySelectEligibleForPeek"/>
-    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectEligibleForPeek" parameterType="map" resultType="org.sonar.db.ce.CeTaskDtoLight" databaseId="mssql">
-    select query.uuid as ceTaskUuid, query.created_at as createdAt from (
-      select
-        row_number() over(<include refid="orderBySelectEligibleForPeek"/>) as number,
-        <include refid="columnsSelectEligibleForPeek"/>
-      <include refid="sqlSelectEligibleForPeek"/>
-    ) as query
-    where
-    query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    order by number asc
-  </select>
-
-  <select id="selectEligibleForPeek" parameterType="map" resultType="org.sonar.db.ce.CeTaskDtoLight" databaseId="oracle">
-    select taskuuid as ceTaskUuid, createdat as createdAt from (
-      select rownum as rn, t."uuid" as taskuuid, t."created_at" as createdat from (
-        select
-          <include refid="columnsSelectEligibleForPeek"/>
-          <include refid="sqlSelectEligibleForPeek"/>
-          <include refid="orderBySelectEligibleForPeek"/>
-      ) t
-    ) t
-    where
-      t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <sql id="columnsSelectEligibleForPeek">
index 6dffe0b6848a5c7196e8ab5b069d7d4ef151a12f..ba9c732ea748966aecdcaf033e348c6e01247818 100644 (file)
       <include refid="componentColumns"/>
     <include refid="sqlSelectByQuery"/>
     ORDER BY LOWER(p.name), p.name, p.created_at
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countByQuery" resultType="int">
index d66491e315d194d806c4f8a71342f8a4b71be44a..79637cfad2cdce0e70e10ed51d9fde8a1f397082 100644 (file)
   </select>
 
   <sql id="pagination">
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <select id="selectSnapshotBefore" resultType="ViewsSnapshot">
index 62b53297cf2ac5615496ab66ffe43a2750b478f9..b9649d46bbf2006a898ae84a2a008cf9462197fd 100644 (file)
           </foreach>
     </if>
     order by i.kee
-    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectIssueKeysByComponentUuidWithFilters" parameterType="map" resultType="string" databaseId="mssql">
-       select
-      i.kee
-    from
-    (select
-        row_number() over(order by i.kee ASC) as row_number,
-          i.kee
-        from rules r
-        inner join issues i on i.rule_uuid = r.uuid
-        where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-        AND i.status &lt;&gt; 'CLOSED'
-        <if test="includingRepositories.size() > 0">
-            AND r.plugin_name IN
-              <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
-                #{ruleRepository}
-              </foreach>
-        </if>
-        <if test="excludingRepositories.size() > 0">
-          AND r.plugin_name NOT IN
-            <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
-              #{ruleRepository}
-            </foreach>
-        </if>
-        <if test="languages.size() > 0">
-            AND r.language IN
-              <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
-                  #{language}
-              </foreach>
-        </if>
-      order by row_number asc
-      offset #{pagination.offset} rows
-      fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only)  i
-   </select>
-
-  <select id="selectIssueKeysByComponentUuidWithFilters" parameterType="map" resultType="string" databaseId="oracle">
-    select
-      i.kee
-    from (
-             select rownum as rn, t.* from (
-               select
-                i.kee
-               from rules r
-          inner join issues i on i.rule_uuid = r.uuid
-               where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-          AND i.status &lt;&gt; 'CLOSED'
-          <if test="includingRepositories.size() > 0">
-              AND r.plugin_name IN
-                <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
-                  #{ruleRepository}
-                </foreach>
-          </if>
-          <if test="excludingRepositories.size() > 0">
-            AND r.plugin_name NOT IN
-              <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
-                #{ruleRepository}
-              </foreach>
-          </if>
-          <if test="languages.size() > 0">
-              AND r.language IN
-                <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
-                    #{language}
-                </foreach>
-          </if>
-          order by i.kee ASC
-             ) t ) i
-           where
-             i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-           order by i.rn asc
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string">
         </foreach>
    </if>
     order by i.kee
-    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string" databaseId="mssql">
-       select
-      i.kee
-    from
-    (select
-        row_number() over(order by i.kee ASC) as row_number,
-         i.kee
-        from rules r
-        inner join issues i on i.rule_uuid = r.uuid
-        where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-        AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
-        AND i.status &lt;&gt; 'CLOSED'
-        <if test="includingRepositories.size() > 0">
-            AND r.plugin_name IN
-              <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
-                #{ruleRepository}
-              </foreach>
-        </if>
-        <if test="excludingRepositories.size() > 0">
-          AND r.plugin_name NOT IN
-            <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
-              #{ruleRepository}
-            </foreach>
-        </if>
-        <if test="languages.size() > 0">
-            AND r.language IN
-              <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
-                  #{language}
-              </foreach>
-        </if>
-        order by row_number asc
-        offset #{pagination.offset} rows
-        fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only)  i
-  </select>
-
-  <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string" databaseId="oracle">
-    select
-      i.kee
-    from
-         (select rownum as rn, t.* from (
-               select
-                i.kee
-               from rules r
-          inner join issues i on i.rule_uuid = r.uuid
-               where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-          AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
-          AND i.status &lt;&gt; 'CLOSED'
-          <if test="includingRepositories.size() > 0">
-              AND r.plugin_name IN
-                <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
-                  #{ruleRepository}
-                </foreach>
-          </if>
-          <if test="excludingRepositories.size() > 0">
-            AND r.plugin_name NOT IN
-              <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
-                #{ruleRepository}
-              </foreach>
-          </if>
-          <if test="languages.size() > 0">
-              AND r.language IN
-                <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
-                    #{language}
-                </foreach>
-          </if>
-          order by i.kee ASC
-             ) t
-           ) i
-           where
-             i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-           order by i.rn asc
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap">
     left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
     where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
     order by i.issue_creation_date ASC
-    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap" databaseId="mssql">
-       select
-    <include refid="issueColumns"/>,
-    u.login as assigneeLogin
-    from
-    (select
-        row_number() over(order by i.issue_creation_date ASC) as row_number,
-          <include refid="issueColumnsInInnerQuery"/>
-        from issues i
-        where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-      order by row_number asc
-      offset #{pagination.offset} rows
-      fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only)  i
-    inner join rules r on r.uuid=i.rule_uuid
-    inner join components p on p.uuid=i.component_uuid
-    inner join components root on root.uuid=i.project_uuid
-    left join users u on i.assignee = u.uuid
-    left join new_code_reference_issues n on i.kee = n.issue_key
-    left outer join issues_impacts ii on i.kee = ii.issue_key
-    left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
-  </select>
-
-   <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap" databaseId="oracle">
-    select
-    <include refid="issueColumns"/>,
-    u.login as assigneeLogin
-    from
-         (select <include refid="issueColumnsInInnerQuery"/> from (
-             select rownum as rn, t.* from (
-               select
-               <include refid="issueColumnsInInnerQuery"/>
-               from issues i
-               where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-                       order by i.issue_creation_date ASC
-             ) t
-           ) i
-           where
-             i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-           order by i.rn asc) i
-    inner join rules r on r.uuid=i.rule_uuid
-    inner join components p on p.uuid=i.component_uuid
-    inner join components root on root.uuid=i.project_uuid
-    left join users u on i.assignee = u.uuid
-    left join new_code_reference_issues n on i.kee = n.issue_key
-    left outer join issues_impacts ii on i.kee = ii.issue_key
-    left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <sql id="selectByBranchColumns">
         <!--  order by clause is required if using offset rows fetch next on MSSQL Database   -->
         order by (select null)
       </if>
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 </mapper>
index c77a7c45a368ffd79adaa6907bdee395aa2aa9b0..8afb81bd763c7df8467abfc5c511c155201300b3 100644 (file)
@@ -45,7 +45,7 @@
       m.enabled=${_true}
     </where>
     ORDER BY UPPER(m.short_name), m.short_name
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countEnabled" resultType="Integer">
index 3a214437939c0ab503bad1d247b0ab2851a96846..49b60bfebb5db9ad167bc63fe017ba28cb5b520c 100644 (file)
@@ -79,7 +79,7 @@
   </select>
 
   <sql id="pagination">
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <select id="countGroupsByQuery" parameterType="map" resultType="int">
index 73520e48809d0be86d8690a1df78ad1380a2c8e8..2e122c5841aa35ebafab31eb91ecd70e5d45141a 100644 (file)
   </select>
 
   <sql id="pagination">
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <sql id="groupNamesByQueryAndTemplate">
index dd94c2f4f374b2bf4bc2320e6a207d29155940c1..f24ccb528092c46f0bf46841d3633bd9d62f2418 100644 (file)
@@ -50,7 +50,7 @@
         #{uuid,jdbcType=VARCHAR}
       </foreach>
       order by p.name, uuid desc
-      offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+      offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="selectProjectsByKeys" resultType="Project">
index 33cd3600741f7a9ca82feb5ba1372536e8a147d9..029701e607214141f6ac2af7572826c7a82c665b 100644 (file)
     SELECT g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY g.name ASC
-    LIMIT #{pagination.pageSize,jdbcType=INTEGER}
-    OFFSET #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="mssql">
-    select * from (
-    select row_number() over(order by g.name asc) as number,
-      g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
-      <include refid="sqlSelectByQuery" />
-    ) as query
-    where
-    query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    order by query.name asc
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="oracle">
-    select * from (
-      select rownum as rn, t.* from (
-        select g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
-        <include refid="sqlSelectByQuery"/>
-        order by g.name ASC
-      ) t
-    ) t
-    where
-    t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
    <select id="countByQuery" resultType="int">
index 149fc766cfb1d95934dd61ea314dad07278681c1..9181c55b5252ee9cc16762a391437c6fa59e6e2c 100644 (file)
     SELECT u.uuid as userUuid, u.name as name, qup.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY u.name ASC
-    LIMIT #{pagination.pageSize,jdbcType=INTEGER}
-    OFFSET #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchUserMembershipDto"
-          databaseId="mssql">
-    select * from (
-    select row_number() over(order by u.name asc) as number,
-    u.uuid as userUuid, u.name as name, qup.uuid as uuid
-    <include refid="sqlSelectByQuery"/>
-    ) as query
-    where
-    query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    order by query.name asc
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchUserMembershipDto"
-          databaseId="oracle">
-    select * from (
-    select rownum as rn, t.* from (
-    select u.uuid as userUuid, u.name as name, qup.uuid as uuid
-    <include refid="sqlSelectByQuery"/>
-    order by u.name ASC
-    ) t
-    ) t
-    where
-    t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <sql id="sqlSelectByQuery">
index 4314c7ac88a4bfb4b4f54a14cee1eb70b3ac04b0..acfd537f11054ddd488907ee3b3bec1be39cef4d 100644 (file)
     SELECT g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY g.name ASC
-    LIMIT #{pagination.pageSize,jdbcType=INTEGER}
-    OFFSET #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="mssql">
-    select * from (
-    select row_number() over(order by g.name asc) as number,
-      g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
-      <include refid="sqlSelectByQuery" />
-    ) as query
-    where
-    query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    order by query.name asc
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="oracle">
-    select * from (
-      select rownum as rn, t.* from (
-        select g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
-        <include refid="sqlSelectByQuery"/>
-        order by g.name ASC
-      ) t
-    ) t
-    where
-    t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <sql id="sqlSelectByQuery">
index 74b3b51280453a6eaeff0f782202f5bd960c7ad3..a8bbc1cd6d542956946577dbf74adefe25d29b15 100644 (file)
     SELECT u.uuid as userUuid, u.name as name, qeu.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY u.name ASC
-    LIMIT #{pagination.pageSize,jdbcType=INTEGER}
-    OFFSET #{pagination.offset,jdbcType=INTEGER}
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchUserMembershipDto"
-          databaseId="mssql">
-    select * from (
-    select row_number() over(order by u.name asc) as number,
-    u.uuid as userUuid, u.name as name, qeu.uuid as uuid
-    <include refid="sqlSelectByQuery"/>
-    ) as query
-    where
-    query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    order by query.name asc
-  </select>
-
-  <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchUserMembershipDto"
-          databaseId="oracle">
-    select * from (
-    select rownum as rn, t.* from (
-    select u.uuid as userUuid, u.name as name, qeu.uuid as uuid
-    <include refid="sqlSelectByQuery"/>
-    order by u.name ASC
-    ) t
-    ) t
-    where
-    t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <sql id="sqlSelectByQuery">
index dfb733bea4f1a3f931cf7b6ac7227bed84075235..ea9f0327977fb4cf35f9b55e2a7e7fe07b2cd1f9 100644 (file)
@@ -99,7 +99,7 @@
   </select>
 
   <sql id="pagination">
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </sql>
 
   <select id="countByQuery" parameterType="map" resultType="int">
index 4812a9dfdcafdcf896229d3e584a3427395e49f8..7853f238363818c602581f6c10e66d417bc643e8 100644 (file)
@@ -25,7 +25,7 @@
     SELECT g.uuid as uuid, g.name as name, g.description as description, gu.user_uuid as userUuid
     <include refid="commonClauses"/>
     ORDER BY g.name
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countGroups" parameterType="map" resultType="int">
@@ -99,7 +99,7 @@
     SELECT u.uuid as uuid, u.login as login, u.name as name, gu.group_uuid as groupUuid
     <include refid="userCommonClauses"/>
     ORDER BY u.name ASC
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countMembers" parameterType="map" resultType="int">
index fe46b5691903fd23df2ac4f9990a969bebbc335f..2420da17cac3562db3b8d06178ace7d946fbd4c7 100644 (file)
         <include refid="selectFromUsersAndJoinScmAccounts"/>
         <include refid="searchByQueryWhereClause"/>
         ORDER BY u.login
-        limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
-    </select>
-
-    <select id="selectUsers" parameterType="map" resultMap="userResultMap" databaseId="mssql">
-        SELECT
-            <include refid="usersAndScmAccountsColumns"/>
-        FROM
-            (SELECT
-                <include refid="searchByQueryInnerQueryColumns"/>
-            FROM users u
-            <include refid="searchByQueryWhereClause"/>
-            ORDER BY u.login
-            offset #{pagination.offset} rows
-            fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-            ) u
-        <include refid="leftOuterJoinScmAccounts"/>
-    </select>
-
-    <select id="selectUsers" parameterType="map" resultMap="userResultMap" databaseId="oracle">
-        SELECT
-            <include refid="usersAndScmAccountsColumns"/>
-        FROM
-            (SELECT rownum as rn, t.* from (
-                SELECT
-                <include refid="searchByQueryInnerQueryColumns"/>
-                FROM users u
-                <include refid="searchByQueryWhereClause"/>
-                ORDER BY u.login ASC
-                ) t
-            ) u
-        <include refid="leftOuterJoinScmAccounts"/>
-        WHERE
-        u.rn BETWEEN #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-             ORDER BY u.rn ASC
+        offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
     </select>
 
     <select id="countByQuery" parameterType="map" resultType="int">
index fa7a2e090337f0898e8f03f2204bb156e871856f..a115f936aed07cbc8b7bf6df0952827da9088616 100644 (file)
@@ -38,7 +38,7 @@
     from webhook_deliveries
     where webhook_uuid = #{webhookUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countByProjectUuid" parameterType="String" resultType="int">
@@ -53,7 +53,7 @@
     from webhook_deliveries
     where project_uuid = #{projectUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="selectOrderedByCeTaskUuid" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
@@ -61,7 +61,7 @@
     from webhook_deliveries
     where ce_task_uuid = #{ceTaskUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
   </select>
 
   <select id="countByCeTaskUuid" parameterType="String" resultType="int">
index 88c412aee32570dd3ab7d7a2f22e3eebc7b357e5..52b1eafe129bc6bf47a24da185374389f447df4b 100644 (file)
@@ -49,10 +49,10 @@ public class OffsetBasedPaginationTest {
   }
 
   @Test
-  public void forOffset_whenZeroOffset_shouldStartRowNumberAtOne() {
+  public void forOffset_whenZeroOffset_shouldStartOffsetAtZero() {
     assertThat(OffsetBasedPagination.forOffset(0, 100))
-      .extracting(p -> p.getStartRowNumber(), p -> p.getOffset(), p -> p.getPageSize())
-      .containsExactly(1, 0, 100);
+      .extracting(p -> p.getOffset(), p -> p.getPageSize())
+      .containsExactly(0, 100);
   }
 
   @Test
@@ -76,13 +76,6 @@ public class OffsetBasedPaginationTest {
       .hasMessage("page size must be >= 1");
   }
 
-  @Test
-  public void forStartRowNumber_whenZeroOffset_shouldStartRowNumberAtOne() {
-    assertThat(OffsetBasedPagination.forStartRowNumber(1, 100))
-      .extracting(p -> p.getStartRowNumber(), p -> p.getOffset(), p -> p.getPageSize())
-      .containsExactly(1, 0, 100);
-  }
-
   @Test
   public void equals_whenSameParameters_shouldBeTrue() {
     Assertions.assertThat(OffsetBasedPagination.forStartRowNumber(15, 20))
index 5f85d87c18b14da24c39347487db6df0572ed638..c0fc8c692d4827bed20484e192aa45fc79db51a5 100644 (file)
@@ -80,13 +80,6 @@ public class PaginationTest {
     assertThat(forPage(5).andSize(1).getOffset()).isEqualTo(4);
   }
 
-  @Test
-  public void startRowNumber_is_computed_from_page_and_size() {
-    assertThat(forPage(2).andSize(3).getStartRowNumber()).isEqualTo(4);
-    assertThat(forPage(5).andSize(3).getStartRowNumber()).isEqualTo(13);
-    assertThat(forPage(5).andSize(1).getStartRowNumber()).isEqualTo(5);
-  }
-
   @Test
   public void endRowNumber_is_computed_from_page_and_size() {
     assertThat(forPage(2).andSize(3).getEndRowNumber()).isEqualTo(6);