有什么方法可以*不*在Postgresql中使用服务器端准备好的语句? [英] Any way to *not* use server-side prepared statements in Postgresql?

查看:61
本文介绍了有什么方法可以*不*在Postgresql中使用服务器端准备好的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在(例如)Python中,我可以发出:

In (say) Python, I can issue:

psycopg2.connect(...).cursor().execute("select * from account where id='00100000006ONCrAAO'")

在服务器上将导致以下日志条目:

which on the server results in the following log entries:

2011-07-18 18:56:08 PDT LOG:  duration: 6.112 ms  statement: select * from account where id='00100000006ONCrAAO'

但是,在Java中,发出:

However, in Java, issuing:

conn.createStatement().executeQuery("select * from account where id = '00100000006ONCrAAO'");

导致:

2011-07-18 18:44:59 PDT LOG:  duration: 4.353 ms  parse <unnamed>: select * from account where id = '00100000006ONCrAAO'
2011-07-18 18:44:59 PDT LOG:  duration: 0.230 ms  bind <unnamed>: select * from account where id = '00100000006ONCrAAO'
2011-07-18 18:44:59 PDT LOG:  duration: 0.246 ms  execute <unnamed>: select * from account where id = '00100000006ONCrAAO'

一些搜索显示PG JDBC驱动程序总是使用准备好的语句:

Some searching shows that the PG JDBC driver always uses prepared statements: http://postgresql.1045698.n5.nabble.com/JDBC-prepared-statements-amp-server-side-prepared-statements-td1919506.html

有什么办法可以规避服务器准备的语句?如果有所作为,我想问一下PG 8.4和9.0.

Is there any way to circumvent server prepared statements? If it makes a difference, I'm asking regarding PG 8.4 and 9.0.

推荐答案

从Postgresql JDBC驱动程序邮件列表中得到答案:

Got an answer from the Postgresql JDBC driver mailing list:

您可以使用v2协议(该协议将参数值作为文本插入, 而不是将它们发送出去),但是您将失去其他各种 取决于v3协议的驱动程序功能的一部分.

You can use the v2 protocol (which inserts parameter values as text, rather than sending them out of line), but you will lose various other bits of driver functionality that depend on the v3 protocol.

使用V2协议迫使驱动程序使用简单查询协议而不是扩展查询协议,并使性能恢复到我们在Python中看到的水平.

Using the V2 protocol worked in forcing the driver to use the simple query protocol instead of the extended query protocol, and brought performance back to levels we were seeing in Python.

这篇关于有什么方法可以*不*在Postgresql中使用服务器端准备好的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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