apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.79k stars 6.7k forks source link

limit offset return wrong result #1903

Closed keitho00 closed 5 years ago

keitho00 commented 5 years ago

Which version of ShardingSphere did you use?

3.1.0

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

java code

        List<ProfitJournal> profitJournalPage1 = profitJournalMapper.selectPage(ProfitJournal.Query.builder()
                        .userId(20162268)
                        .build(), 1550627000L, 1550628875L
                , 5, 5);

mybaits xml

<select id="selectPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from profit_journal
    <where>
        <if test="query.userId != null">
            and user_id = #{query.userId}
        </if>
        <if test="query.guildId != null">
            and guild_id = #{query.guildId}
        </if>

        <if test="query.profitType != null">
            and profit_type = #{query.profitType}
        </if>
        <if test="query.memberType != null">
            and member_type = #{query.memberType}
        </if>
        <if test="query.month != null">
            and `month` = #{query.month}
        </if>
        <if test="beginTime != null and endTime != null">
            and dateline between #{beginTime} and #{endTime}
        </if>
        order by id
        LIMIT #{offset},#{limit}
    </where>
</select>

Expect Sql

SELECT
    * 
FROM
    profit_journal_20190220 
WHERE
    user_id = ?and dateline between ? and ? LIMIT ?, ?  ::: [[20162268, 1550627000, 1550628875, 5, 5]]

Actual Sql

SELECT
    * 
FROM
    profit_journal_20190220 
WHERE
    user_id = ?and dateline between ? and ? LIMIT ?, ?  ::: [[20162268, 1550627000, 1550628875, 0, 10]]

two sql limit param is different

Result

image

I want 5 result but get 10 result ,I think there is something wrong .

tuohai666 commented 5 years ago

Known issue, please refer to https://github.com/apache/incubator-shardingsphere/issues/1722.