使用 SqlDataProvider 读取大型 Oracle table
Reading a large Oracle table with SqlDataProvider
我有一个 Oracle table,其中有 150 万行数据需要处理;但是我不断收到内存不足异常。显示该问题的最小代码示例是:
module MyModule
open System
open FSharp.Data.Sql
type SQL = SqlDataProvider<ConnectionString = myConnectionString, DatabaseVendor = Common.DatabaseProviderTypes.ORACLE>
let getdata() =
let ctx = SQL.GetDataContext(SelectOperations.DatabaseSide)
let qdata= query {
for somerow in ctx.myschema.sometable do
select (somerow)
}
qdata |> Seq.take 10 |> Seq.iter (printfn "%A") // Fails with both the Seq.take and without
是否可以让 SqlDataProvider 提供可管理块中的行?
您在此处调用的 Seq.take
已经在具体化结果上执行 - 它不是 SQL 查询生成器的一部分 - 这非常类似于在 IQueryable<> 对象上调用 AsEnumerable() .所有 SQL 将基于 query { ... }
括号内发生的情况构建。
如果您read the docs了解 F# SqlProvider,您会发现有一些特殊的表达式可以在查询语句中使用:
let qdata = query {
for somerow in ctx.myschema.sometable do
sortBy (somerow.column)
skip 30
take 10
select (somerow)
}
我有一个 Oracle table,其中有 150 万行数据需要处理;但是我不断收到内存不足异常。显示该问题的最小代码示例是:
module MyModule
open System
open FSharp.Data.Sql
type SQL = SqlDataProvider<ConnectionString = myConnectionString, DatabaseVendor = Common.DatabaseProviderTypes.ORACLE>
let getdata() =
let ctx = SQL.GetDataContext(SelectOperations.DatabaseSide)
let qdata= query {
for somerow in ctx.myschema.sometable do
select (somerow)
}
qdata |> Seq.take 10 |> Seq.iter (printfn "%A") // Fails with both the Seq.take and without
是否可以让 SqlDataProvider 提供可管理块中的行?
您在此处调用的 Seq.take
已经在具体化结果上执行 - 它不是 SQL 查询生成器的一部分 - 这非常类似于在 IQueryable<> 对象上调用 AsEnumerable() .所有 SQL 将基于 query { ... }
括号内发生的情况构建。
如果您read the docs了解 F# SqlProvider,您会发现有一些特殊的表达式可以在查询语句中使用:
let qdata = query {
for somerow in ctx.myschema.sometable do
sortBy (somerow.column)
skip 30
take 10
select (somerow)
}