RpgSQL - 为什么这么慢?

发布于 2024-12-10 05:25:40 字数 380 浏览 0 评论 0原文

我尝试使用 RpgSQL 从 R 访问我的 PostgreSQL 数据库。

我的数据库非常大,查询也非常复杂。因此我明白我必须稍等一下。

但是,如果我使用 pgAdmin III 作为客户端,查询可能需要 5 秒。当我使用 RpgSQL 时,相同的查询实际上需要很长时间。

我看不出其中的原因,因为服务器而不是客户端必须完成这项工作,对吗?

你能给我一个理由和可能的解决方案吗?

谢谢你!

I try to access my PostgreSQL-database from R using RpgSQL.

My database is very big and the queries are quite sophisticated. Therefore I understand that I have to wait a bit.

However, if I use pgAdmin III as a client, a query takes maybe 5 seconds. When I use RpgSQL the same query literally takes ages.

I can't see the reason for that, as the server and not the client hast to do the work, right?

Can you give me a reason and possibly a solution?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱*していゐ 2024-12-17 05:25:40

还有 RPostgreSQL
这是积极维护的。由于它直接位于 PostgreSQL API 之上,因此
应该比使用 RODBC 通过 ODBC 更快。

这是我在家保存的数据库中的一个简单示例——它有一千个简单的行
在十分之一秒内:

R> library(RPostgreSQL)
Loading required package: DBI
R> drv <- dbDriver("PostgreSQL")
R> con <- dbConnect(drv, password="....", dbname="beancounter")
R> system.time(res <- dbGetQuery(con,
+>             "select * from fxprices where date >= '2005-01-01' limit 1000")) 
   user  system elapsed 
  0.030   0.000   0.113
R> dim(res)
[1] 1000    8
R>

There is also the RPostgreSQL package
which is actively maintained. As it sits directly on top of the PostgreSQL API, it
should be faster than going via ODBC with RODBC.

Here is a quick example from a database I keep at home---it gets a thousand simple rows
in a tenth of a second:

R> library(RPostgreSQL)
Loading required package: DBI
R> drv <- dbDriver("PostgreSQL")
R> con <- dbConnect(drv, password="....", dbname="beancounter")
R> system.time(res <- dbGetQuery(con,
+>             "select * from fxprices where date >= '2005-01-01' limit 1000")) 
   user  system elapsed 
  0.030   0.000   0.113
R> dim(res)
[1] 1000    8
R>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文