MySQL 测试Mybatis 中CASE WHEN 和 普通foreach update 批量更新单个字段性能 :
测试代码
List<Info> infos = new ArrayList<>();
        for (int i = 1; i < 1000; i++) {
            infos.add(new Info(String.valueOf(i), String.valueOf(i), i + "0", new Time(System.currentTimeMillis()), new Time(System.currentTimeMillis())));
        }
        long begin = System.currentTimeMillis();
        System.err.println("数据生成完毕,准备修改  使用CASE WHEN 语法:");
        System.err.println(infoMapper.updateBatch(infos));
//        System.out.println(infos);
        System.err.printf("总用时:%s ms\n", System.currentTimeMillis() - begin);

注意 MySQL 要支持执行多条SQL语句请在url链接中加入配置:url: jdbc:mysql://localhost:3306/library?allowMultiQueries=true

使用case when 批量更新
<update id="updateBatch">-- noinspection SqlNoDataSourceInspectionForFile
        UPDATE info
        SET seat = CASE card
        <foreach collection="list" item="item" separator=" ">
            WHEN #{item.card} THEN #{item.seat}
        </foreach>
        ELSE seat
        END
        WHERE card IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item.card}
        </foreach>
    </update>
使用 普通foreach 循环更新
<update id="updateBatchByForEach">
        <foreach collection="list" item="item">
            UPDATE info
            set seat = #{item.seat}
            where card = #{item.card};
        </foreach>
    </update>

1万条数据测试

4万条数据

评论

  1. Windows Chrome
    1 周前
    2026-5-08 16:04:53

    Just finished reading this guide; understanding before excitement is key. Start your journey here via ibet register app download for secure Filipino gaming.

  2. Macintosh Chrome
    2 月前
    2026-3-31 23:07:35

    Excellent performance comparison! CASE WHEN is typically 3-5x faster for batch updates since it executes as a single statement. Just like how 2jl legit platforms optimize database queries for real-time gaming, proper SQL batching significantly reduces connection overhead. Consider adding prepared statement caching for even better results at scale.

  3. Windows Chrome
    2 月前
    2026-3-06 13:39:57

    Interesting read! Seeing platforms like bunny casino online casino really highlights how much the gaming landscape is evolving – a modern take on classic fun, especially in regions like the Philippines. Responsible gaming is key, though! 🤔

  4. Windows Chrome
    4 月前
    2026-1-16 2:38:10

    Really interesting read! Seeing platforms like legend link app download prioritize responsible gaming & regulatory compliance (PAGCOR licensing!) is a huge step forward. Makes enjoying slots & live casino much more comfortable! 👍

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇