准备好的语句会显着降低程序速度吗? [英] Do prepared statements slow down program conspicuously?
问题描述
我正在编写一个软件,要求我准备语句并设置值,执行查询并在循环内获取结果.该循环可能超过7,000个周期.如果我使用简单的语句而不是准备的语句,执行速度会发生很大变化吗?
I am writing a software that requires me to prepare statements and set the values, execute the query and get results within a loop. This loop might have over 7,000 cycles. If I use simple statements rather than prepared statements, will the execution speed change greatly?
这是伪代码
- 准备对帐单
- 从某处获取列表
- 遍历列表
- 获取准备好的语句并进行一些数据库查询,并关闭新的资源(如结果集).
- 使用结果和初始列表中的值填充地图
谢谢.
推荐答案
如果重复使用同一条语句处理多组数据,则预备语句要快,然后是非预备语句.我不知道情况并非如此.
Prepared statements are FASTER then non-prepared statements if you repeatedly use the same statement with multiple sets of data. I'm unaware of a situation where this is not true.
一旦准备好一条语句,它就会发送到数据库服务器,该服务器只需在每次调用它时就接受数据-不必在每次绑定新数据时都重新处理该语句.
Once you've prepared a statement, its sent to the DB server which then only has to accept the data each time you call it -- it doesn't have to reprocess the statement every time you bind new data.
所以简单的答案是:
不.他们没有.
这篇关于准备好的语句会显着降低程序速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!