FSharp.Management
FSharp.Management copied to clipboard
Suboptimal WMI execution
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?
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.
How do other LINQ providers work (do they process such a query BTW?)?