问题描述
我使用 RSQLite 包对本地 SQLite 数据库进行查询,对于某些查询,RSQLite 接口非常慢.
I'm using the RSQLite package to make queries to a local SQLite database, and for some queries the RSQLite interface is quite slow.
作为一个具体示例,使用 sqlite3 命令行实用程序运行以下查询所需的时间不到一秒钟:
As a specific example, the following query takes under one second to run using the sqlite3 command-line utility:
$ sqlite3 data/svn.db
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select count(distinct svn_path.revision) FROM src INNER JOIN svn_path ON src.filename=svn_path.path;
5039
但是 R 中的等效查询需要两分钟多一点的时间,并且 100% 使用了我的一个 CPU:
But the equivalent query in R takes a little over two minutes and uses 100% of one of my CPUs:
> library(RSQLite)
Loading required package: DBI
> con <- dbConnect(SQLite(), dbname="data/svn.db")
> dbGetQuery(con, "select count(distinct svn_path.revision) FROM src INNER JOIN svn_path ON src.filename=svn_path.path")
count(distinct svn_path.revision)
1 5039
为什么通过 R 接口的性能如此之慢?
Why is the performance so much slower through the R interface?
请注意,我在 Mac OS X 10.6.6 上使用 R64 2.10.1.
Note that I'm using R64 2.10.1 on Mac OS X 10.6.6.
推荐答案
重要的是您拥有的 RSQLite 版本.您的 R 版本似乎已有一年多的历史,因此如果您的 RSQLite 与 Benoit 建议的一样旧,那么它可能是一个更旧的引擎(例如 3.6.4).
What matters is the version of RSQLite you have. Your version of R seems to be over a year old so if your RSQLite is just as old it could be a much older engine (eg, 3.6.4) as suggested by Benoit.
这篇关于通过 RSqlite 进行 SQLilte 查询比使用 sqlite3 命令行界面慢得多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!