FSharp.Management icon indicating copy to clipboard operation
FSharp.Management copied to clipboard

Suboptimal WMI execution

Open ForNeVeR opened this issue 11 years ago • 2 comments
trafficstars

Consider this code sample:

open System
open FSharp.Management

type LocalWmiProvider = WmiProvider<"localhost">

let IsUpdateInstalled (hotFixId : string) : bool =
    let data = LocalWmiProvider.GetDataContext()

    query {
        for hotfix in data.Win32_QuickFixEngineering do
        exists (hotfix.HotFixID = hotFixId)
    }

[<EntryPoint>]
let main argv = 
    let b = IsUpdateInstalled "KB2685893"
    Console.WriteLine b
    0

The check hotfix.HotFixID = hotFixId executes multiple times under debugger. As far as I can see, the query generated is

select * from Win32_QuickFixEngineering

But I think it should be

select * from Win32_QuickFixEngineering where HotFixID = ...

Could you please tell me if this is really an issue (and, e.g. not a debugger artifact) and what can I possibly do to improve the situation? Maybe I don't understand how query works here?

ForNeVeR avatar Jan 07 '14 15:01 ForNeVeR

Since the query will always project the collection first, the provider needs to run the first query. I don't see a way of fixing this for use with Linq queries other than adding some kind of pre-filter property so one could modify the query before it is ran by the QueryBuilder.

Firgeis avatar Apr 23 '16 14:04 Firgeis

How do other LINQ providers work (do they process such a query BTW?)?

ForNeVeR avatar Apr 23 '16 14:04 ForNeVeR