使用准备好的语句有不利之处吗? [英] Are there downsides to using prepared statements?

查看:82
本文介绍了使用准备好的语句有不利之处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关准备好的语句的信息,在我阅读的所有内容中,没有人谈论使用它们的弊端.因此,我想知道是否有人们容易忽略的有龙"的地方?

I've been reading a lot about prepared statements and in everything I've read, no one talks about the downsides of using them. Therefore, I'm wondering if there are any "there be dragons" spots that people tend to overlook?

推荐答案

Prepared语句只是经过解析和预编译的SQL语句,它仅等待提供绑定变量被执行.

Prepared statement is just a parsed and precompiled SQL statement which just waits for the bound variables to be provided to be executed.

任何执行的语句迟早都会准备(需要对其进行分析,优化,编译然后执行).

Any executed statement becomes prepared sooner or later (it need to be parsed, optimized, compiled and then executed).

一条准备好的语句只是重用了解析,优化和编译的结果.

A prepared statement just reuses the results of parsing, optimization and compilation.

通常,即使您自己不使用准备好的查询,数据库系统也会使用某种优化来节省查询准备的时间.

Usually database systems use some kind of optimization to save some time on query preparation even if you don't use prepared queries yourself.

Oracle在解析查询时首先检查库缓存,如果已经解析了相同的语句,它将使用缓存的执行计划.

Oracle, for instance, when parsing a query first checks the library cache, and if the same statement had already been parsed, it uses the cached execution plan instead.

这篇关于使用准备好的语句有不利之处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆