gpt4 book ai didi

postgresql - pgjdbc中prepareThreshold = 5有什么好处?

转载 作者:行者123 更新时间:2023-11-29 12:15:34 24 4
gpt4 key购买 nike

pgjdbc中的prepareThreshold定义如下:

Determine the number of PreparedStatement executions required before switching over to use server side prepared statements. The default is five, meaning start using server side prepared statements on the fifth execution of the same PreparedStatement object. More information on server side prepared statements is available in the section called “Server Prepared Statements”.

我想知道这实际上给我们带来了什么好处?大多数网络服务器几个月都不会重新启动,所以所有数据库查询最终都会发送 5 次以上,所以给它一个星期左右的时间,所有准备好的语句都会存储在服务器上,不是吗?这只是为了让桌面应用程序受益吗?还是我遗漏了什么,比如“一段时间内的 5 个阈值”?

最佳答案

我知道您想知道为什么 JDBC 驱动程序在使用服务器端准备好的语句之前完全等待。

在不参与决策过程的情况下,我会说原因是准备语句意味着一定的开销(发送 Prepare、Bind 和 Execute 调用)。只有当您确信该语句将被重用时,才有意义这样做。

不要忘记准备语句还有其他用途,可以在多次执行时节省解析步骤:这是避免 SQL 注入(inject)的王道。仅此一项就可以证明准备好的语句是正确的,即使它只执行一次。

关于postgresql - pgjdbc中prepareThreshold = 5有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56261410/

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