gpt4 book ai didi

java - 为什么当记录 > 约 600 条时查询性能急剧下降

转载 作者:行者123 更新时间:2023-12-01 10:11:02 29 4
gpt4 key购买 nike

当我在 Oracle 中使用大于约 600 条记录的“INSERT ALL”查询时,为什么查询性能会急剧下降?你能教我吗?

我使用的是 Spring + Mybatis + Oracle

以下是我的查询。

    INSERT ALL
<foreach collection="list" item="record">
INTO tablename (
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o
) VALUES (
#{a},
#{b},
#{c},
#{d},
#{e},
#{f},
#{g},
#{h},
#{i},
#{j},
#{k},
#{l},
#{m},
#{n},
#{o}
)
</foreach>
SELECT 1 FROM dual

(我更改了列和变量的名称。上部查询正在运行)

请帮帮我~

最佳答案

正如 @kordirko 提到的,它很慢很可能是因为您使用的 MyBatis insert 不进行批处理。

这是多行插入示例 from MyBatis docs :

<insert id="insertAuthor" useGeneratedKeys="true"
keyProperty="id">
insert into Author (username, password, email, bio) values
<foreach item="item" collection="list" separator=",">
(#{item.username}, #{item.password}, #{item.email}, #{item.bio})
</foreach>
</insert>

所以尝试这样使用它:

INSERT INTO tablename (
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o
) VALUES
<foreach collection="list" item="record">
(
#{a},
#{b},
#{c},
#{d},
#{e},
#{f},
#{g},
#{h},
#{i},
#{j},
#{k},
#{l},
#{m},
#{n},
#{o}
)
</foreach>

关于java - 为什么当记录 > 约 600 条时查询性能急剧下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112013/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com