Multi-Language Extensibility in MS SQL Server James Hamilton [email_address] Microsoft SQL Server 2002.06.25
Agenda <ul><li>Common Language Runtime (CLR) Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></...
Basic Infrastructure <ul><li>CLR Hosted inside SQL Server: </li></ul><ul><ul><li>4S’s:  safety, security, scalability, & s...
Philosophy: Safety & Security <ul><li>Safety: </li></ul><ul><ul><li>User code does not compromise integrity  of server pro...
Philosophy: Security model <ul><li>Resources  protected by permissions </li></ul><ul><ul><li>threads, files, unmanaged cod...
Philosophy: 3 Permission Sets <ul><li>SAFESQL  </li></ul><ul><ul><li>Internal computation plus data access  </li></ul></ul...
Philosophy:  Scalability & Speed <ul><li>Scalability: </li></ul><ul><ul><li>As many concurrent users as TSQL </li></ul></u...
Philosophy: Functions speed <ul><li>. NET functions approximating speed of TSQL inline expressions </li></ul><ul><li>.NET ...
Agenda <ul><li>CLR Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></ul><ul><ul><li>Design phil...
Development Steps VS .NET Project Runtime hosted inside SQL Assembly: “TaxLib.dll” VB, C#, … Build SQL Server SQL Data Def...
Assembly Registration <ul><ul><li>CREATE ASSEMBLY lib_geom FROM ‘1	ypesgeometry.dll’  </li></ul></ul><ul><ul><li>WITH PERM...
ALTER Assembly <ul><li>Schema bound: </li></ul><ul><ul><li>Cannot invalidate persistent data or indexes </li></ul></ul><ul...
Register A Function <ul><ul><li>CREATE FUNCTION distance (  @x1 int, @y1 int, @x2 int, @y2 int ) RETURNS float  EXTERNAL N...
Call Function SELECT name FROM Employee  WHERE  dbo.tax(salary) >= 50000 Common Language Runtime Managed code Unmanaged co...
Register A Procedure <ul><ul><li>CREATE PROCEDURE check_inventory  </li></ul></ul><ul><ul><li>EXTERNAL NAME ‘lib_events:CI...
Register A Trigger <ul><ul><li>CREATE TRIGGER supplier_event ON supplier  </li></ul></ul><ul><ul><li>AFTER INSERT, UPDATE ...
UDT: Introduction <ul><li>Extends SQL Server type system </li></ul><ul><li>Complex structure & associated behavior </li></...
UDT: Ordering values <ul><li>Two kinds of ordering supported </li></ul><ul><li>Binary ordering indicated via CLR property:...
UDT: Creating <ul><li>Registered as a type from an already registered assembly </li></ul><ul><ul><li>CREATE ASSEMBLY MapLi...
UDT: Instantiating <ul><li>Can be declared as column type: </li></ul><ul><ul><li>Create table Cities( </li></ul></ul><ul><...
UDT: Read operations <ul><li>Registered methods, properties, & public data members can be use in SQL queries </li></ul><ul...
UDT: Ordering Operations <ul><li>Indexing, UNIQUE, & PRIMARY KEY constraints: </li></ul><ul><ul><li>Requires binary orderi...
UDT: UDT Write Operations <ul><li>Constructor can be called using new operator </li></ul><ul><ul><li>UPDATE Cities </li></...
UDT: Write Operations <ul><li>Methods marked mutators callable in UPDATEs </li></ul><ul><ul><ul><li>UPDATE Cities </li></u...
UDAggs Required Methods <ul><li>Implement QP interface to aggregate values over a group </li></ul><ul><li>Interface needed...
Creating UDAggs <ul><li>Aggregates implemented as set of methods packaged in a .NET class </li></ul><ul><li>UDAgg is bound...
UDAgg class definition e.g. <ul><li>Public class Concat { </li></ul><ul><li>//Private store for accumulating results. </li...
Final Stage: Access Methods <ul><li>Complete extensibility solution requires user defined access methods: </li></ul><ul><l...
CLR SQL Types Package <ul><li>Defines C#, VB, & Java types corresponding SQL Server types </li></ul><ul><li>Reduce impedan...
SQL Types Example <ul><li>Tax function implemented with SQL types: </li></ul>using System;  using System.Data.SQLTypes;  p...
Agenda <ul><li>CLR Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></ul><ul><ul><li>Design phil...
Integration: In-Proc Data Access <ul><li>Goals: </li></ul><ul><ul><li>Symmetric model </li></ul></ul><ul><ul><ul><li>Clien...
Integration: Process Model <ul><li>Thread integration: </li></ul><ul><ul><li>SQL Server: non-preemptive user-level thread ...
Integration: Memory Management <ul><li>Memory allocation from DB system (rather than via O/S): </li></ul><ul><ul><li>Allow...
Integration: Remaining Issues <ul><li>Assemblies (code) kept in database: </li></ul><ul><ul><li>Dispatched to VM through b...
Integration: Query optimization <ul><li>Gather function cost statistics </li></ul><ul><ul><li>Value histograms, execution ...
CLR Integration Summary <ul><li>DB extensibility without product stability risk </li></ul><ul><li>Ability to add types and...
Upcoming SlideShare
Loading in …5
×

Multi-Language Extensibility in MS SQL Server

652
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
652
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Here is an example program using SQL types. There is a static function called tax in class myFinances. It takes a SQLDouble value corresponding to salary as input argument. Inside the function there is logic that defines the percentage of tax the person must pay based on its salary. Notice that once can test for NULLS directly on values of sal and because the return type of the function is SQLDouble, the function can return a NULL value.
  • Multi-Language Extensibility in MS SQL Server

    1. 1. Multi-Language Extensibility in MS SQL Server James Hamilton [email_address] Microsoft SQL Server 2002.06.25
    2. 2. Agenda <ul><li>Common Language Runtime (CLR) Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></ul><ul><ul><li>Design philosophy </li></ul></ul><ul><ul><ul><li>4 S’s: Safety, Security, Scalability, & Speed </li></ul></ul></ul><ul><li>SQL Features Enabled: </li></ul><ul><ul><li>CLR assemblies </li></ul></ul><ul><ul><li>Scalar functions </li></ul></ul><ul><ul><li>Relational functions </li></ul></ul><ul><ul><li>Aggregate functions </li></ul></ul><ul><ul><li>Stored Procedures </li></ul></ul><ul><ul><li>Triggers </li></ul></ul><ul><ul><li>Types and Methods </li></ul></ul><ul><ul><li>SQL Types Package </li></ul></ul><ul><ul><li>Access methods </li></ul></ul><ul><li>Systems & Integration issues </li></ul>
    3. 3. Basic Infrastructure <ul><li>CLR Hosted inside SQL Server: </li></ul><ul><ul><li>4S’s: safety, security, scalability, & speed </li></ul></ul><ul><ul><li>Run verified, type-safe code in process </li></ul></ul><ul><ul><li>.NET Framework languages (VB, C#, Java, …) </li></ul></ul><ul><li>Competitive offerings: </li></ul><ul><ul><li>Oracle & DB2: in-proc Java & JDBC </li></ul></ul><ul><li>Data access in process: </li></ul><ul><ul><li>Based on ADO.NET </li></ul></ul><ul><ul><li>Same programming model as middle-tier </li></ul></ul><ul><li>SQLTypes support: </li></ul><ul><ul><li>SQL type semantics in managed code on client & server tiers </li></ul></ul>
    4. 4. Philosophy: Safety & Security <ul><li>Safety: </li></ul><ul><ul><li>User code does not compromise integrity of server process </li></ul></ul><ul><ul><ul><li>Verifiable code </li></ul></ul></ul><ul><ul><ul><li>Leverage CLR’s code access security </li></ul></ul></ul><ul><ul><li>User code cannot call UI, create threads, synchronization, or call unmanaged code </li></ul></ul><ul><li>Security: </li></ul><ul><ul><li>Access to SQL data from user code via SQL authorization model </li></ul></ul><ul><ul><li>Access to system resources from user code via .NET Framework code permissions </li></ul></ul><ul><ul><li>Administrators control permissions given to assemblies </li></ul></ul>
    5. 5. Philosophy: Security model <ul><li>Resources protected by permissions </li></ul><ul><ul><li>threads, files, unmanaged code access etc. </li></ul></ul><ul><li>API that exposes a resource </li></ul><ul><ul><li>introduces a demand for that permission </li></ul></ul><ul><li>Stack-walk based permission check: </li></ul><ul><ul><li>every assembly in call-stack has permission </li></ul></ul><ul><li>Permissions granted to assemblies determined by machine and user-level security policy </li></ul><ul><li>Allows host to add another policy layer to further restrict permissions </li></ul>
    6. 6. Philosophy: 3 Permission Sets <ul><li>SAFESQL </li></ul><ul><ul><li>Internal computation plus data access </li></ul></ul><ul><ul><li>No access to resources outside SQL Server </li></ul></ul><ul><ul><li>No unmanaged calls </li></ul></ul><ul><ul><li>Must be verifiable </li></ul></ul><ul><li>EXTERNAL ACCESS </li></ul><ul><ul><li>SAFESQL + access to external resources </li></ul></ul><ul><ul><li>Requires EXTERNAL ACCESS permission to create </li></ul></ul><ul><ul><li>SQL Server will impersonate the caller </li></ul></ul><ul><ul><li>Must be verifiable </li></ul></ul><ul><li>UNRESTRICTED </li></ul><ul><ul><li>No controls: can call unmanaged, & un-verifiable </li></ul></ul><ul><ul><li>Only Sysadmin can create </li></ul></ul>
    7. 7. Philosophy: Scalability & Speed <ul><li>Scalability: </li></ul><ul><ul><li>As many concurrent users as TSQL </li></ul></ul><ul><ul><ul><li>Integrated SQL and runtime threads </li></ul></ul></ul><ul><ul><ul><li>Collaboration between SQL and GC </li></ul></ul></ul><ul><li>Speed: </li></ul><ul><ul><li>Efficient data access in process </li></ul></ul><ul><ul><li>Compiled user code, not interpreted as TSQL </li></ul></ul><ul><ul><li>Fast transitions in/out of runtime </li></ul></ul>
    8. 8. Philosophy: Functions speed <ul><li>. NET functions approximating speed of TSQL inline expressions </li></ul><ul><li>.NET Framework functions much faster than TSQL functions for complex expressions </li></ul>
    9. 9. Agenda <ul><li>CLR Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></ul><ul><ul><li>Design philosophy </li></ul></ul><ul><ul><ul><li>4 S’s: Safety, Security, Scalability, & Speed </li></ul></ul></ul><ul><li>SQL Features Enabled: </li></ul><ul><ul><li>CLR assemblies </li></ul></ul><ul><ul><li>Scalar functions </li></ul></ul><ul><ul><li>Relational functions </li></ul></ul><ul><ul><li>Aggregate functions </li></ul></ul><ul><ul><li>Stored Procedures </li></ul></ul><ul><ul><li>Triggers </li></ul></ul><ul><ul><li>Types and Methods </li></ul></ul><ul><ul><li>Access methods </li></ul></ul><ul><ul><li>SQL Types Package </li></ul></ul><ul><li>Systems & Integration issues </li></ul>
    10. 10. Development Steps VS .NET Project Runtime hosted inside SQL Assembly: “TaxLib.dll” VB, C#, … Build SQL Server SQL Data Definition: create assembly … create function … create procedure … create trigger … create type … SQL Queries: select sum( tax(sal,state) ) from Emp where county = ‘King’
    11. 11. Assembly Registration <ul><ul><li>CREATE ASSEMBLY lib_geom FROM ‘1 ypesgeometry.dll’ </li></ul></ul><ul><ul><li>WITH PERMISSION SET SAFE WITH AUTOREGISTER </li></ul></ul><ul><ul><li>DROP ASSEMBLY lib_geom </li></ul></ul><ul><li>Assemblies stored in DB </li></ul><ul><ul><li>Backup, restore, etc. with data </li></ul></ul><ul><li>Code permissions assigned per assembly </li></ul><ul><ul><li>SafeSQL, external access, & unrestricted </li></ul></ul><ul><li>Autoregister functions </li></ul><ul><ul><li>Using .NET custom attributes </li></ul></ul><ul><li>Assembly benefits </li></ul><ul><ul><li>Self-describing metadata: types & file dependencies </li></ul></ul><ul><ul><li>Unit of deployment: permissions & versioning </li></ul></ul>
    12. 12. ALTER Assembly <ul><li>Schema bound: </li></ul><ul><ul><li>Cannot invalidate persistent data or indexes </li></ul></ul><ul><ul><li>No tables with columns of UDT from this assembly </li></ul></ul><ul><ul><li>No indexes on functions of that assembly </li></ul></ul><ul><li>Packaging considerations </li></ul><ul><ul><li>Place routines and types in different assemblies </li></ul></ul>
    13. 13. Register A Function <ul><ul><li>CREATE FUNCTION distance ( @x1 int, @y1 int, @x2 int, @y2 int ) RETURNS float EXTERNAL NAME ‘lib_geom:CPoint.Distance’ DETERMINISTIC RETURNS NULL ON NULL INPUT </li></ul></ul><ul><ul><li>DROP FUNCTION distance </li></ul></ul><ul><li>Functions called from queries: </li></ul><ul><ul><li>Static class functions </li></ul></ul><ul><ul><li>Deterministic functions: </li></ul></ul><ul><ul><ul><li>No SQL updates or access to global state </li></ul></ul></ul><ul><li>Can be scalar or table-valued </li></ul><ul><li>Using a function in a query: </li></ul><ul><ul><li>SELECT s.name FROM Supplier s </li></ul></ul><ul><ul><li>WHERE dbo.distance( s.x, s.y, @x, @y ) < 3 </li></ul></ul>
    14. 14. Call Function SELECT name FROM Employee WHERE dbo.tax(salary) >= 50000 Common Language Runtime Managed code Unmanaged code SQLSERVR.EXE Filter Project Employee Scan double tax( double sal ) { if (sal < 50000.0) return sal * 0.15; if (sal >= 50000.0 && sal <= 90000.0) return sal * 0.23; else return sal * 0.35; }
    15. 15. Register A Procedure <ul><ul><li>CREATE PROCEDURE check_inventory </li></ul></ul><ul><ul><li>EXTERNAL NAME ‘lib_events:CInventory.check_level’ </li></ul></ul><ul><ul><li>DROP PROCEDURE check_inventory </li></ul></ul><ul><li>Procedures called directly </li></ul><ul><ul><li>Can contain SQL queries, updates, or DDL </li></ul></ul><ul><ul><li>Can return results directly to client </li></ul></ul><ul><ul><li>Not directly callable (as functions are) from queries </li></ul></ul>
    16. 16. Register A Trigger <ul><ul><li>CREATE TRIGGER supplier_event ON supplier </li></ul></ul><ul><ul><li>AFTER INSERT, UPDATE </li></ul></ul><ul><ul><li>EXTERNAL NAME ‘lib_events:CNotif.Supp_Event’ </li></ul></ul><ul><ul><li>DROP TRIGGER supplier_event </li></ul></ul><ul><li>Similar to procedures </li></ul><ul><ul><li>with access to inserted & deleted tables </li></ul></ul>
    17. 17. UDT: Introduction <ul><li>Extends SQL Server type system </li></ul><ul><li>Complex structure & associated behavior </li></ul><ul><li>Managed classes in any CLR language </li></ul><ul><li>Functionally subsume SQL-99 distinct types </li></ul><ul><ul><li>equivalent to structured types </li></ul></ul><ul><li>Other products: Oracle Cartridges, Informix DataBlades, & IBM DB Extenders </li></ul>
    18. 18. UDT: Ordering values <ul><li>Two kinds of ordering supported </li></ul><ul><li>Binary ordering indicated via CLR property: </li></ul><ul><ul><li>public const bool IsByteOrdered; </li></ul></ul><ul><li>Operator-based ordering </li></ul><ul><ul><li>Overloaded comparison operators: </li></ul></ul><ul><li>public static SQLBool operator </li></ul><ul><li>== (<type>, <type>); </li></ul>
    19. 19. UDT: Creating <ul><li>Registered as a type from an already registered assembly </li></ul><ul><ul><li>CREATE ASSEMBLY MapLib </li></ul></ul><ul><ul><li>FROM ‘ysrvshareMapLib.dll’ </li></ul></ul><ul><ul><li>CREATE TYPE Point </li></ul></ul><ul><ul><li>EXTERNAL NAME ‘MapLib:Basetypes’ </li></ul></ul>
    20. 20. UDT: Instantiating <ul><li>Can be declared as column type: </li></ul><ul><ul><li>Create table Cities( </li></ul></ul><ul><ul><li>Name varchar(20), </li></ul></ul><ul><ul><li>State varchar(20), </li></ul></ul><ul><ul><li>Location Point DEFAULT new Point(0,0)) </li></ul></ul><ul><li>Variables & params of T-SQL & .NET routines can UDTs </li></ul>
    21. 21. UDT: Read operations <ul><li>Registered methods, properties, & public data members can be use in SQL queries </li></ul><ul><li>Methods assumed to be non-mutators unless marked using custom attribute </li></ul><ul><li>Only non-mutators allowed in SELECTs </li></ul><ul><ul><li>Declare @p </li></ul></ul><ul><ul><li>Set @p = new point(32, 23) </li></ul></ul><ul><ul><li>Select Location::Distance(@p) </li></ul></ul><ul><ul><li>From Cities </li></ul></ul>
    22. 22. UDT: Ordering Operations <ul><li>Indexing, UNIQUE, & PRIMARY KEY constraints: </li></ul><ul><ul><li>Requires binary ordering support </li></ul></ul><ul><ul><li>Inconsistent operator based ordering can cause corrupt indices, incorrect query results </li></ul></ul><ul><li>ORDER BY, GROUP BY, & comparison operators: </li></ul><ul><ul><li>If UDT supports binary ordering, always use binary ordering </li></ul></ul><ul><ul><li>Else use overloaded operators; rely on consistency and correctness of UDT implementation </li></ul></ul>
    23. 23. UDT: UDT Write Operations <ul><li>Constructor can be called using new operator </li></ul><ul><ul><li>UPDATE Cities </li></ul></ul><ul><ul><li>SET Location = new Point(12.3, 46.2) </li></ul></ul><ul><li>Properties and public data members can be modified through assignment </li></ul><ul><ul><li>UPDATE Cities </li></ul></ul><ul><ul><li>SET Location::X = 23.5, </li></ul></ul><ul><ul><li>Location::Y = 23.5 </li></ul></ul><ul><ul><li>WHERE Name = ‘Anchorage’ </li></ul></ul>
    24. 24. UDT: Write Operations <ul><li>Methods marked mutators callable in UPDATEs </li></ul><ul><ul><ul><li>UPDATE Cities </li></ul></ul></ul><ul><ul><ul><li>SET Location::SetXY(23.5, 23.5) </li></ul></ul></ul><ul><ul><ul><li>WHERE Name = ‘Anchorage’ </li></ul></ul></ul><ul><li>INSERTs get values from string, binary form or from constructor invocation </li></ul><ul><ul><li>INSERT Cities(‘Anchorage’, ‘Alaska’, ’19.3:2.3’) </li></ul></ul>
    25. 25. UDAggs Required Methods <ul><li>Implement QP interface to aggregate values over a group </li></ul><ul><li>Interface needed: </li></ul><ul><ul><li>Initialize a group </li></ul></ul><ul><ul><li>Pass values in the group to accumulate the aggregation </li></ul></ul><ul><ul><li>Merge multiple groups (for parallel plans) </li></ul></ul><ul><ul><li>Finalize computation and retrieve result </li></ul></ul>
    26. 26. Creating UDAggs <ul><li>Aggregates implemented as set of methods packaged in a .NET class </li></ul><ul><li>UDAgg is bound to a class in existing assembly </li></ul><ul><ul><li>CREATE AGGREGATE Concat(nvarchar) </li></ul></ul><ul><ul><li>RETURNS nvarchar </li></ul></ul><ul><ul><li>EXTERNAL ‘MyLib:Concat’ </li></ul></ul>
    27. 27. UDAgg class definition e.g. <ul><li>Public class Concat { </li></ul><ul><li>//Private store for accumulating results. </li></ul><ul><li>private SQLString agg; </li></ul><ul><li>//Optimizer properties </li></ul><ul><li>public static bool IsNullOnNullsSet() {return true;} </li></ul><ul><li>public static bool IsNullOnEmptySet() {return false;} </li></ul><ul><li>//Aggregation interface </li></ul><ul><li>public void Init(); </li></ul><ul><li>public void Accum(SQLString str); </li></ul><ul><li>public void Merge(Concat otheragg); </li></ul><ul><li>public SQLString Term(); </li></ul><ul><li>} </li></ul>
    28. 28. Final Stage: Access Methods <ul><li>Complete extensibility solution requires user defined access methods: </li></ul><ul><li>Informix supports adding access methods: </li></ul><ul><ul><li>Expose locking, concurrency control, recovery, etc. </li></ul></ul><ul><ul><li>Hard to make work in general … few engineers able to write internal storage engine code well </li></ul></ul><ul><ul><li>Many will try and they will have bugs … hard on product quality image </li></ul></ul><ul><li>Solution: Tailor existing access methods </li></ul><ul><ul><li>E.g. map spatial queries to queries over 2 B-trees or single Z-transform </li></ul></ul><ul><ul><li>Query rewrite language such that system can rewrite a function as an appropriate set of operations over 1 or more tables/indexes </li></ul></ul>
    29. 29. CLR SQL Types Package <ul><li>Defines C#, VB, & Java types corresponding SQL Server types </li></ul><ul><li>Reduce impedance mismatch between programming language & data </li></ul><ul><li>Consistent expression evaluation in mid- & server-tier programming </li></ul><ul><li>SQL Types library </li></ul><ul><ul><li>Managed classes: system.Data.SQLTypes </li></ul></ul><ul><ul><li>Provide SQL semantics </li></ul></ul><ul><ul><ul><li>Nullability, three-valued logic </li></ul></ul></ul><ul><ul><ul><li>Precision & scale in operations </li></ul></ul></ul>
    30. 30. SQL Types Example <ul><li>Tax function implemented with SQL types: </li></ul>using System; using System.Data.SQLTypes; public class myFinances { public static SQLDouble tax( SQLDouble sal ) { if ( sal < 50000.0 ) return sal * 0.15; if ( sal >= 50000.0 && sal <= 90000.0 ) return sal * 0.23 else return sal * 0.35; } }
    31. 31. Agenda <ul><li>CLR Integration Overview: </li></ul><ul><ul><li>Basic infrastructure </li></ul></ul><ul><ul><li>Design philosophy </li></ul></ul><ul><ul><ul><li>4 S’s: Safety, Security, Scalability, & Speed </li></ul></ul></ul><ul><li>SQL Features Enabled: </li></ul><ul><ul><li>CLR assemblies </li></ul></ul><ul><ul><li>Scalar functions </li></ul></ul><ul><ul><li>Relational functions </li></ul></ul><ul><ul><li>Aggregate functions </li></ul></ul><ul><ul><li>Stored Procedures </li></ul></ul><ul><ul><li>Triggers </li></ul></ul><ul><ul><li>Types and Methods </li></ul></ul><ul><ul><li>Access methods </li></ul></ul><ul><ul><li>SQL Types Package </li></ul></ul><ul><li>Systems & Integration issues </li></ul>
    32. 32. Integration: In-Proc Data Access <ul><li>Goals: </li></ul><ul><ul><li>Symmetric model </li></ul></ul><ul><ul><ul><li>Client, server, & mid-tier </li></ul></ul></ul><ul><ul><li>Fully supported by dev tools </li></ul></ul><ul><ul><ul><li>VS dev environment including debug </li></ul></ul></ul><ul><li>In same address space as server: </li></ul><ul><ul><li>Don’t marshal to TDS (tabular data stream) </li></ul></ul><ul><ul><li>Don’t loop-back through network interface </li></ul></ul><ul><ul><li>Avoid unnecessary copies </li></ul></ul><ul><ul><li>Avoid unnecessary transitions across managed/unmanaged (into VM) interface </li></ul></ul>
    33. 33. Integration: Process Model <ul><li>Thread integration: </li></ul><ul><ul><li>SQL Server: non-preemptive user-level thread scheduling </li></ul></ul><ul><ul><li>Fibers multiplexed on O/S thread with thread migration </li></ul></ul><ul><ul><li>Implication: TLS storage used by VM won’t work in SQL execution environment </li></ul></ul><ul><li>Lazy preemptive: </li></ul><ul><ul><li>When SQL calls potentially blocking code it must “go preemptive” (allocate a thread) </li></ul></ul><ul><ul><li>So thread required for each VM call – expensive </li></ul></ul><ul><ul><li>Lazy pre-emptive: assume preemption not required and set timer to catch rare cases when thread allocation is needed </li></ul></ul><ul><li>Garbage collection blocks VM threads: </li></ul><ul><ul><li>Hard on multi-user DB throughput </li></ul></ul><ul><ul><li>GC doesn’t directly suspend – calls DB to suspend and DB schedules other non-VM hosted work </li></ul></ul>
    34. 34. Integration: Memory Management <ul><li>Memory allocation from DB system (rather than via O/S): </li></ul><ul><ul><li>Allows memory resources to be used for different purposes over time </li></ul></ul><ul><ul><li>Garbage collection very general but DB systems often have more info: </li></ul></ul><ul><ul><ul><li>e.g. free memory pool at end of statement </li></ul></ul></ul><ul><ul><li>Goal: </li></ul></ul><ul><ul><ul><li>DB memory costing able to request memory from VM when needed </li></ul></ul></ul><ul><ul><ul><li>Per user memory consumption tracking & quotas </li></ul></ul></ul>
    35. 35. Integration: Remaining Issues <ul><li>Assemblies (code) kept in database: </li></ul><ul><ul><li>Dispatched to VM through buffers </li></ul></ul><ul><ul><li>Stream interface would be better yet </li></ul></ul><ul><li>Support attention propagation (user interrupt) into VM </li></ul><ul><li>Track all VM resources </li></ul><ul><ul><li>O/S portability layer tailored to DB execution environment </li></ul></ul><ul><li>Error containment/minimize multi-user impact of failures: </li></ul><ul><ul><li>Out-of-proc execution </li></ul></ul><ul><ul><li>Multiple VMs </li></ul></ul>
    36. 36. Integration: Query optimization <ul><li>Gather function cost statistics </li></ul><ul><ul><li>Value histograms, execution cost </li></ul></ul><ul><li>Reorder of predicate evaluation </li></ul><ul><ul><li>Based on cost of evaluation </li></ul></ul><ul><li>Function indexes </li></ul><ul><ul><li>Speed up expensive functions </li></ul></ul><ul><ul><li>Extends computed column indexes and indexed (materialized) views </li></ul></ul>
    37. 37. CLR Integration Summary <ul><li>DB extensibility without product stability risk </li></ul><ul><li>Ability to add types and behavior w/o access to engine source code </li></ul><ul><ul><li>Scalable, safe, secure & fast </li></ul></ul><ul><li>Rich server programming model </li></ul><ul><ul><li>Any CLR language </li></ul></ul><ul><ul><li>Symmetric mid- & server-tier model </li></ul></ul><ul><li>Better development environment </li></ul><ul><ul><li>Integrates SQL tools with Visual Studio </li></ul></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×