Mysql 使用注意

Mysql中不等于过滤null

代码段1 没办法更新 NULL 数据, 需要使用代码段2

<update id="updateConfigStep">
        update xxx set config_step=#{configStep}
        where corp_id=#{corpId} and group_id=#{salaryGroupId} and config_step!='done'
</update>
<update id="updateConfigStep">
        update xxx set config_step=#{configStep}
        where corp_id=#{corpId} and group_id=#{salaryGroupId} and( config_step is null or config_step!='done')
</update>

limit分页,数据重复

使用 limit 分页取数据,需要指定 order by 唯一键;不然每次Mysql返回的数据顺序不一致,导致分页后取的数据重复/缺失

limit #{startRow}, #{pageSize} order by uid

If multiple rows have identical values in the ORDER BY columns, the server is free to return those rows in any order, and may do so differently depending on the overall execution plan. In other words, the sort order of those rows is nondeterministic with respect to the nonordered columns.
One factor that affects the execution plan is LIMIT, so an ORDER BY query with and without LIMIT may return rows in different orders.

https://dev.mysql.com/doc/refman/5.7/en/limit-optimization.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容