Home Forums Programming CLR Integration and Programming. CLR mountpoint freespace query scaling *really bad* with high number of mountpoints RE: CLR mountpoint freespace query scaling *really bad* with high number of mountpoints

  • Theo Ekelmans (2/24/2015)


    After the struggling with hello world issues that come with using Visual Studio 2013 C# for the first time, i got a cmd window working with precisely what i needed. But only to find out that .NET SQL CLR is "some what limited" in the things you can use.

    Hi Theo. So, by the statement above, are you meaning that the console app runs the code quickly and that it is only slow when executed within SQL Server via SQLCLR?

    As far as I can see, your code for the two drive space methods looks fine.

    For the Split function there are two improvements that should be made to make it much faster:

    1) in the SqlFunction attribute, add the property: IsDeterministic=true (as in "SqlFunction(IsDeterministic = true)")

    2) You don't need SqlChars for the delimiter. You could use SqlString. But if you are going to use SqlChars:

    a) you might be better off referencing it via "Delimiter.Buffer[0]"

    b) If you are publishing via Visual Studio / SSDT, be sure to add a SqlFacet to the delimiter parameter to prevent it from automapping SqlChars to NVARCHAR(MAX) (since NVARCHAR(MAX) will slow down the operation so only use it when necessary): "[SqlFacet(MaxSize = 10)] SqlChars delimiter"

    Also, while not making it faster, you should map the output field of "txt" to NVARCHAR(4000) instead of NVARCHAR(10). There is no reason to not do this and it is more flexible as it can handle any string passed in, including a 4000 characters string with no delimiter.

    You can get some SQLCLR functionality (including the Split and GetDriveInfo functions) already done and for free via the SQL#[/url] library (which I am the author of).

    And for more info on working with SQLCLR in general, I am writing a Stairway series here on SQL Server Central: Stairway to SQLCLR[/url]

    Take care,

    Solomon...

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR