¿Por qué el proveedor de tipo Sql es muy lento?

I have the following code. It will take a minutes if I change the line where (row.SiteID = 1) a where (row.SiteID = 2). I searched on web and added LocalSchemaFile = "Schema.dbml", ForceUpdate = false por SqlDataConnection. It still takes about 15 seconds everytime when the query condition is changed.

Actualizar:
If I rerun the code without changing the Linq code, it will get and print the row from the database table instantly.

open System
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
open System.Net
open System.IO
open FSharp.Data

type dbSchema = SqlDataConnection<"Data Source=Svr;Initial Catalog=DB;Integrated Security=SSPI;"> 
//, LocalSchemaFile = "Schema.dbml", ForceUpdate = false > // Still take 15 secs
let getARow =
    let db = dbSchema.GetDataContext()
    db.DataContext.Log <- System.Console.Out
    let query = query { 
        for row in db.Table1 do 
        where (row.SiteID = 1) 
        select (Some(row.Col1, row.Col2))
        headOrDefault
        }
    query 

[<EntryPoint>]
let main argv = 
    let aRow = getARow
    printfn "%A" aRow 
    0

preguntado el 09 de septiembre de 13 a las 21:09

just to clarify: it takes 15 seconds to do what? -

@desco It takes 15 seconds to printfn "%A" aRow. -

so query execution takes 15 seconds. At glance it looks like something that happens on database side and has nothing in common with type providers. Do you have the same results if you call your database from C# or run query using Sql Management Studio? -

The query seems simple enough. One trivial thing you might check is that SiteID is an indexed column. How many rows are present in Table1? -

@desco If I rerun the code without changing the Linq code, it will get and print the row from the database table instantly. -

1 Respuestas

Have you tried outputting a timestamp at the start of the main function? Is it possible you're seeing compile time, and not run time? If you don't change the code and hit F5, it will just run the already-compiled version. If you tweak the code, when you press F5 it will need to recompile (and compiling F# seems pretty slow).

If you output a timestamp at the start of the program and after the data access, it's possible you'll see that the runtime is just as fast in both cases.

Respondido el 10 de diciembre de 13 a las 10:12

yes, I think it takes a while to compile after the code is changed. - ca9163d9

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.