RJDBC太慢,无法读取SQL Server表

时间:2019-02-04 13:30:33

标签: r sql-server rodbc r-dbi rjdbc

我正在使用RJDBC包将R连接到SQL Server。但是,当我尝试从表中读取输入时,会花费大量时间来进行读取。下面的代码段将使您了解如何尝试访问表。

LocationOfJDBC <- "local_path/sqljdbc41.jar"
options(java.parameters = "-Xmx8048m")
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver" ,LocationOfJDBC ,identifier.quote="`")

mydb <- dbConnect(drv, paste0("jdbc:sqlserver://",DBhost,";databaseName=",DBname), DBuser, DBpass)

#dbListTables(mydb)
#dbDisconnect(mydb)

# Reading SQL Table using DBSENDQUERY Method-which is taking almost 2.6 mins for 100k rows and 14 columns (7 varchar,7 int)
Qyery1<-paste("select * from table1 where id = ",user_id,sep="")
R_table1 = dbSendQuery(mydb, Qyery1)
R_df_table1 = fetch (R_table1, n=-1)

# Reading SQL Table using DBGETQUERY Method - which is taking almost 140 sec for 100k rows and 14 columns (7 varchar,7 int)
Qyery1 <- paste("select * from table1 where id = ",user_id,sep="")
R_df_table1 = dbGetQuery(mydb, Qyery1)

有没有更好的方法可以做到这一点。还有其他客户端耗时不到10秒。为什么R这么慢?

0 个答案:

没有答案