EP1683046A2 - Systems and methods for supporting inheritance for user-defined types - Google Patents

Systems and methods for supporting inheritance for user-defined types

Info

Publication number
EP1683046A2
EP1683046A2 EP04779487A EP04779487A EP1683046A2 EP 1683046 A2 EP1683046 A2 EP 1683046A2 EP 04779487 A EP04779487 A EP 04779487A EP 04779487 A EP04779487 A EP 04779487A EP 1683046 A2 EP1683046 A2 EP 1683046A2
Authority
EP
European Patent Office
Prior art keywords
type
user
defined type
database
computer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
EP04779487A
Other languages
German (de)
French (fr)
Other versions
EP1683046A4 (en
Inventor
Beysim c/o Microsoft Corporation SEZGIN
Denis Y. c/o Microsoft Corporation ALTUDOV
Jose A. c/o Microsoft Corporation BLAKELEY
Ramachandran Microsoft Corporation VENKATESH
Wei c/o Microsoft Corporation YU
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Microsoft Corp
Original Assignee
Microsoft Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Priority claimed from US10/775,282 external-priority patent/US6976029B2/en
Application filed by Microsoft Corp filed Critical Microsoft Corp
Publication of EP1683046A2 publication Critical patent/EP1683046A2/en
Publication of EP1683046A4 publication Critical patent/EP1683046A4/en
Withdrawn legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/289Object oriented databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q50/00Systems or methods specially adapted for specific business sectors, e.g. utilities or tourism
    • G06Q50/10Services

Definitions

  • MSFT-1748 filed on August 21, 2003, entitled “SYSTEMS AND METHODS FOR REPRESENTING UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM BUT INDEPENDENT OF PHYSICAL REPRESENTATION”; U.S. Patent Application No. 10/646,941 (Atty. Docket No. MSFT-1749), filed on August 21, 2003, entitled “SYSTEMS AND METHODS FOR SEPARATING UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM FROM THEIR PHYSICAL ORGANIZATION”; U.S. Patent Application No. 10/646,940 (Atty. Docket No. MSFT-1750), filed on August 21, 2003, entitled “SYSTEMS AND METHODS FOR THE IMPLEMENTATION OF A BASE SCHEMA FOR ORGANIZING UNITS OF INFORMATION MANAGEABLE BY A
  • MSFT-1752 filed on August 21, 2003, entitled “SYSTEMS AND METHOD FOR REPRESENTING RELATIONSHIPS BETWEEN UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM”; U.S. Patent Application No. 10/646,575 (Atty. Docket No. MSFT-2733), filed on August 21, 2003, entitled “SYSTEMS AND METHODS FOR INTERFACING APPLICATION PROGRAMS WITH AN ITEM-BASED STORAGE PLATFORM"; U.S. Patent Application No. 10/646,646 (Atty. Docket No.
  • MSFT-2734 filed on August 21, 2003, entitled “STORAGE PLATFORM FOR ORGANIZING, SEARCHING, AND SHARING DATA”; U.S. Patent Application No. 10/646,580 (Atty. Docket No. MSFT-2735), filed on August 21, 2003, entitled “SYSTEMS AND METHODS FOR DATA MODELING IN AN ITEM-BASED STORAGE PLATFORM.”
  • the present invention relates to data storage in a computer system and, more particularly, to systems and methods for providing inheritance to user-defined types (UDTs) in a database system where UDTs are an extensibility mechanism employed in connection with relational database engines and file systems to extend a scalar type system(s) of a data store by registering managed types that implement a specific contract.
  • UDTs are an extensibility mechanism employed in connection with relational database engines and file systems to extend a scalar type system(s) of a data store by registering managed types that implement a specific contract.
  • MICROSOFT SQL SERVER is a comprehensive database management platform that provides extensive management and development tools, a powerful extraction, transformation, and loading (ETL) tool, business intelligence and analysis services, and other capabilities.
  • ETL extraction, transformation, and loading
  • CLR Common Language Runtime
  • the CLR provides various functions and services required for program execution, including just-in-time (JIT) compilation, allocating and managing memory, enforcing type safety, exception handling, thread management and security.
  • JIT just-in-time
  • the CLR is now loaded by SQL SERVER upon the first invocation of a .NET routine.
  • SQL SERVER database programmers were limited to using Transact-SQL when writing code on the server side.
  • Transact-SQL is an extension of the Structured Query Language (“SQL”) as defined by the International Standards Organization (ISO) and the American National Standards Institute (ANSI).
  • Transact-SQL database developers can create, modify and delete databases and tables, as well as insert, retrieve, modify and delete data stored in a database.
  • Transact-SQL is specifically designed for direct structural data access and manipulation. While Transact-SQL excels at structural data access and management, it is not a full-fledged programming language as are VISUAL BASIC .NET and C#. For example, Transact-SQL does not support arrays, collections, for each loops, bit shifting or classes. [0007] With the CLR integrated into the SQL SERVER database, database developers have been able to perform tasks that were impossible or difficult to achieve with Transact-SQL alone.
  • VISUAL BASIC .NET and C# are modern programming languages offering full support for arrays, structured exception handling, and collections. Developers can leverage CLR integration to write code that has more complex logic and is more suited for computation tasks using languages such as VISUAL BASIC .NET and C#. These programming languages offer object-oriented capabilities such as encapsulation, inheritance and polymorphism. Related code can be easily organized into classes and namespaces. [0008] Managed code is better suited than Transact-SQL for number crunching and complicated execution logic, and features extensive support for many complex tasks, including string handling and regular expressions.
  • .NET Framework Base Class Library BCL
  • database developers have access to thousands of pre-built classes and routines which can be easily accessed from any stored procedure, trigger or user-defined function.
  • type safety Another benefit of managed code is type safety.
  • the CLR verifies that the code is safe. This process is known as "verification.” During verification, the CLR performs several checks to ensure that the code is safe to run. For example, the code is checked to ensure that no memory is read that has not be been written to. The CLR will also prevent buffer overflows.
  • the deployment unit is called an assembly. An assembly is packaged as a dynamic link library (DLL). Managed DLL assemblies can be loaded into and hosted by SQL SERVER. The CREATE ASSEMBLY statement is used to register an assembly in the server.
  • SQL SERVER has traditionally supported "built-in" scalar types such as integer, floating point number, date, time, and character string. These built-in types also come with a set of built-in operations such as +, -, *, / as well as built-in functions over these types. These types, operations, and functions are "built-in" in the sense that they are implemented and packaged by the product and users cannot define their own types.
  • a database system such as SQL SERVER
  • SQL SERVER it is desirable for a database system, such as SQL SERVER, to allow users to extend the type system of the database system such that users could create new types that act as scalar types in the database system but which contain more complex structure and behavior — for example, to create a "Point" type consisting of X and Y coordinates.
  • DBMS database management system
  • the SQL standard and some database management system (DBMS) products have used the term "user- defined type" to describe several forms of type extensibility.
  • the SQL-99 standard describes a "distinct type," which is a type that can be defined by a user to have an internal representation that is a value of an existing SQL built-in data type.
  • a distinct type may optionally share comparison and arithmetic operators, type conversions, and aggregate (column) functions (e.g., max, min, average) with an existing scalar type.
  • the distinct type may allow constraints to be defined on its values.
  • a distinct type may expose behaviors beyond those of an existing scalar type by defining new functions specific to the distinct type via user- defined functions. With respect to type checking, the distinct type and existing scalar types are considered to be different types. [0013]
  • the main advantage of distinct types is ease of definition. If the internal representation of the new type has a single data member that can be described with an existing built-in type and the built-in type already implements most of the behaviors required on the new type, then distinct types are an attractive alternative.
  • the user does not have to worry about implementing the behaviors required to manage the on-disk storage of the type, constructors, comparison operators (used for ordering and indexing), arithmetic operators, and type conversion (casting) operators.
  • the user only needs to choose what functionality of the underlying built-in type needs to be exposed on the distinct type and optionally add constraints on values or additional functions on the new type.
  • Another advantage of distinct types is that all of the query processing available for built-in types, such as computation of histograms, can be readily used on columns of distinct types.
  • a disadvantage of distinct types, however, is that they can not easily be used to create more complex types.
  • the SQL-99 standard also described a "structured type," which is a type that can be defined by user and that has an internal representation that is a collection of data members, each of which may be of a different SQL built-in or user-defined type. This is similar to the notion of a struct in C and C++.
  • SQL-99 describes a style for defining structured types by which a user only needs to define the type in terms of its internal structure. The system automatically generates accessor and mutator functions on its data members, constructor, and functions to manage the on-disk representation of instances of the type.
  • the main advantages of structured types as defined in SQL are (a) ease of definition of basic behaviors of the type, and (b) the flexibility to define more complex types.
  • the invention disclosed in the UDT Patent Application is directed to a system and method that allows a user to extend the scalar type system of a database system by creating user-defined types that act as scalar types but that contain more complex structure and behavior.
  • a user writes program code in a high-level programming language that implements a class that defines the structure of a user-defined type and methods that can be invoked on instances of the user-defined type.
  • structure when referring to a user-defined type, encompasses the set of fields or properties that implement the type.
  • the type of each field in the UDT Patent Application could be a scalar SQL type or any previously defined user-defined type.
  • the class defining a user-defined type is then compiled and registered with the database system.
  • a CLR class defining a user-defined type may be compiled into an assembly which is then registered with the database system via a CREATE ASSEMBLY data definition statement.
  • a user can register the class within the assembly that defines the user-defined type using a CREATE TYPE data definition statement.
  • the database system enforces a specific contract that the class must implement to enable the user-defined type to act as a scalar in the SQL type system.
  • contract refers to a technique that is used at runtime in object-oriented programming environments to check that code to be executed satisfies certain pre-conditions or requirements to ensure that it will execute properly.
  • the contract against which a class that defines a user-defined type is compared comprises several requirements. First, the class must specify one of a plurality of different formats for persisting instances of the user-defined type in a database store. Second, the class must be capable of returning a null value for the user-defined type. Third, the class must provide a method for converting the user-defined type to and from another type, such as a string type. Once these requirements are satisfied, the database system enables instances of the user-defined type to be created.
  • the user-defined type can be instantiated as a column value in a table, a variable, a parameter of a routine, or a return value of a routine.
  • the database system stores metadata about the class defining the user-defined type for subsequent use in creating instances of the type.
  • the verification of the user-defined type contract is performed using the metadata describing the class that defines the type.
  • the plurality of different formats for persisting instances of the user-defined type comprises a first format in which an instance of the user-defined type is automatically serialized in accordance with a native format of the database system, and a second format in which an instance of the user-defined type is serialized in a manner defined by the user authored class.
  • expressions in the query language of the database system can include one or more references to an instance(s) of a user-defined type, such that evaluation of the expression requires invocation of a method on the instance of the user-defined type.
  • the database system receives such a query language expression, it translates the expression into a sequence of program code instructions that, when executed, invoke the required method on the instance of the user-defined type.
  • the database system then returns the result of the method invocation as the result of evaluation of the query language expression.
  • the instance of the user-defined type is deserialized prior to invoking the method on the instance.
  • Another feature of the that invention is the ability to change the value of an instance of a user-defined type through invocation of a mutator method.
  • the author of the class that defines the user-defined type includes a mutator method as part of the class. When invoked on an instance of the user-defined type, the mutator method enables a value of the user-defined type to be changed.
  • This process may comprise deserializing the instance of the user-defined type, invoking the mutator method to change the value of the deserialized data of the instance, and then serializing the modified instance of the user-defined type to persist the changes.
  • the class defining a user- defined type may further contain an attribute that specifies that serialized binary representations of instances of the user-defined type will be binary ordered. This allows binary comparisons to be made on instances of the type and also enables indexing to be performed on instances of the type.
  • the serialized binary representations of the two instances can be used to evaluate the expression, without deserializing either instance.
  • a table in the database store can be created that has a column defined as the user-defined type. An index can then be created on the column. An index can also be created over a query language expression that references the user-defined type. In this case, a computed column is first generated over the expression, and then an index is created over the computed column.
  • Various embodiments of the present invention are directed to extending a UDT framework to support inheritance.
  • Inheritance is one of the key tenets of object oriented programming and is a basic building block for most modern typesystems (such as the CLR typesystem or the XSD typesystem).
  • CLR common language runtime
  • XSD XSD typesystem
  • UDT inheritance solutions that possess one or more of the following capabilities not present in the existing art: • Seamless integration with the CLR typesystem.
  • Several embodiments of the present invention are directed to UDT inheritance system and methods where the basic UDT contract is specified as a set of required custom attributes and interfaces on the managed type, and wherein inheritance extends this same concept and uses the managed type definition to drive the specification of inheritance to the SQL typesystem.
  • This solution enables the developer to author inherited types in any CLS- compliant programming language of their choice, including but not limited to C#, C++ and VB.NET. • Full support for substitutability.
  • a site (variable, parameter, column definition, etc.) is declared to be of a particular UDT
  • a value of any of the subtypes of that UDT can be stored in that site.
  • This notion of substitutability extends to all uses of the type including casting, conversion, assignment, and method invocation, as well as in the way result sets are processed by the client application.
  • inheritance adds the notion of the exact runtime type of a value that can be different from the declared type. For example, SQL Server supports the creation of indexes over this kind of information, and also uses the index in predicates based on the type of the value.
  • Inheritance would also add the notion of virtual behaviors that can be redefined (overridden) in subtypes, and this notion may be folded into the computation of indexability of a particular UDT function and may be verified at type creation time.
  • Queryable metadadata and catalog services For various embodiments of the present inventino, the relationship between a type and its super-type is recorded in metadata at type creation time and is available through queryable catalog views. This lets applications compose queries to determine the substitutable extent of a particular type.
  • one embodiment of the present invention is directed to a database with an extensible type system for at least one user-defined type that comprises information for describing its structure as well as information for describing an inheritance relationship between itself and another user-defined type (either a subtype or a supertype / base type).
  • the user-defined type is defined in something other than Sequential Query Language (SQL) statement such as, for example, a Common Language Runtime (CLR) statement, a statement in C, C++, and C# ("C-sharp”), and/or a visual basic statement.
  • SQL Sequential Query Language
  • CLR Common Language Runtime
  • several embodiments are further directed to a system wherein the database is aware of the inheritance relationship between two user-defined types (one as the subtype and the other as the supertype / base type).
  • the database is made aware of said inheritance relationship between the two user-defined types by an explicit registration of the user-defined types with said database.
  • one overarching method of the invention for several embodiments comprises: (a) compiling a type into an assembly; (b) registering said assembly with said database; (c) registering said type of said assembly with said database; and (d) using said type.
  • Fig. 1 is a block diagram representing a computer system in which aspects of the present invention may be incorporated
  • Fig. 2 is a block diagram representing an exemplary network environment having a variety of computing devices in which the present invention may be implemented
  • Fig. 3 is a block diagram illustrating the serialization and deserialization of an instance of a user defined type that has been instantiated in managed code
  • Fig. 1 is a block diagram representing a computer system in which aspects of the present invention may be incorporated
  • Fig. 2 is a block diagram representing an exemplary network environment having a variety of computing devices in which the present invention may be implemented
  • Fig. 3 is a block diagram illustrating the serialization and deserialization of an instance of a user defined type that has been instantiated in managed code
  • Fig. 4 is a table illustrating a non-exhaustive list of properties for SqlUserDefinedType
  • Fig. 5 is pseudo-code illustrating that, if Address is a type, and if US Address is a subtype of address, then Addresses may be a table with a column addrcol of type Address.
  • Fig. 6 is pseudo-code illustrating a client/server deserializer that uses the exact type of the value being deserialized to determine the CLR type that it should deserialize into;
  • Fig. 7 is a table illustrating the behaviors and semantics for the CONVERT, CAST, and TREAT commands; and
  • Fig. 8 is a table illustrating the routine properties the UDT methods may comprise.
  • SQL SERVER incorporates the MICROSOFT .NET Common Language Runtime (CLR) to enable managed code to be written and executed to operate on the data store of a SQL SERVER database.
  • CLR Common Language Runtime
  • the present invention is by no means limited to implementation in the SQL SERVER product. Rather, the present invention can be implemented in any database system that supports the execution of object-oriented programming code to operate on a database store, such as object oriented database systems and relational database systems with object relational extensions. Accordingly, it is understood that the present invention is not limited to the particular embodiment described below, but is intended to cover all modifications that are within the spirit and scope of the invention as defined by the appended claims.
  • FIG. 1 Numerous embodiments of the present invention may execute on a computer.
  • Fig. 1 and the following discussion is intended to provide a brief general description of a suitable computing environment in which the invention may be implemented.
  • the invention will be described in the general context of computer executable instructions, such as program modules, being executed by a computer, such as a client workstation or a server.
  • program modules include routines, programs, objects, components, data structures and the like that perform particular tasks or implement particular abstract data types.
  • the invention may be practiced with other computer system configurations, including hand held devices, multi processor systems, microprocessor based or programmable consumer electronics, network PCs, minicomputers, mainframe computers and the like.
  • an exemplary general purpose computing system includes a conventional personal computer 20 or the like, including a processing unit 21, a system memory 22, and a system bus 23 that couples various system components including the system memory to the processing unit 21.
  • the system bus 23 may be any of several types of bus structures including a memory bus or memory controller, a peripheral bus, and a local bus using any of a variety of bus architectures.
  • the system memory includes read only memory (ROM) 24 and random access memory (RAM) 25.
  • a basic input/output system 26 (BIOS), containing the basic routines that help to transfer information between elements within the personal computer 20, such as during start up, is stored in ROM 24.
  • the personal computer 20 may further include a hard disk drive 27 for reading from and writing to a hard disk, not shown, a magnetic disk drive 28 for reading from or writing to a removable magnetic disk 29, and an optical disk drive 30 for reading from or writing to a removable optical disk 31 such as a CD ROM or other optical media.
  • the hard disk drive 27, magnetic disk drive 28, and optical disk drive 30 are connected to the system bus 23 by a hard disk drive interface 32, a magnetic disk drive interface 33, and an optical drive interface 34, respectively.
  • the drives and their associated computer readable media provide non volatile storage of computer readable instructions, data structures, program modules and other data for the personal computer 20.
  • the exemplary environment described herein employs a hard disk, a removable magnetic disk 29 and a removable optical disk 31, it should be appreciated by those skilled in the art that other types of computer readable media which can store data that is accessible by a computer, such as magnetic cassettes, flash memory cards, digital video disks, Bernoulli cartridges, random access memories (RAMs), read only memories (ROMs) and the like may also be used in the exemplary operating environment.
  • a number of program modules may be stored on the hard disk, magnetic disk 29, optical disk 31, ROM 24 or RAM 25, including an operating system 35, one or more application programs 36, other program modules 37 and program data 38.
  • a user may enter commands and information into the personal computer 20 through input devices such as a keyboard 40 and pointing device 42.
  • Other input devices may include a microphone, joystick, game pad, satellite disk, scanner or the like.
  • These and other input devices are often connected to the processing unit 21 through a serial port interface 46 that is coupled to the system bus, but may be connected by other interfaces, such as a parallel port, game port or universal serial bus (USB).
  • a monitor 47 or other type of display device is also connected to the system bus 23 via an interface, such as a video adapter 48.
  • personal computers typically include other peripheral output devices (not shown), such as speakers and printers.
  • the personal computer 20 may operate in a networked environment using logical connections to one or more remote computers, such as a remote computer 49.
  • the remote computer 49 may be another personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the personal computer 20, although only a memory storage device 50 has been illustrated in Fig. 1.
  • the logical connections depicted in Fig. 1 include a local area network (LAN) 51 and a wide area network (WAN) 52.
  • LAN local area network
  • WAN wide area network
  • the personal computer 20 When used in a LAN networking environment, the personal computer 20 is connected to the LAN 51 through a network interface or adapter 53. When used in a WAN networking environment, the personal computer 20 typically includes a modem 54 or other means for establishing communications over the wide area network 52, such as the Internet.
  • the modem 54 which may be internal or external, is connected to the system bus 23 via the serial port interface 46.
  • program modules depicted relative to the personal computer 20, or portions thereof may be stored in the remote memory storage device. It will be appreciated that the network connections shown are exemplary and other means of establishing a communications link between the computers may be used.
  • computer system is intended to encompass any and all devices capable of storing and processing information and/or capable of using the stored information to control the behavior or execution of the device itself, regardless of whether such devices are electronic, mechanical, logical, or virtual in nature.
  • Fig. 2 provides a schematic diagram of an exemplary networked or distributed computing environment.
  • the distributed computing environment comprises computing objects 10a, 10b, etc. and computing objects or devices 110a, 110b, 110c, etc. These objects may comprise programs, methods, data stores, programmable logic, etc.
  • the objects may comprise portions of the same or different devices such as PDAs, televisions, MP3 players, personal computers, etc.
  • Each object can communicate with another object by way of the communications network 14.
  • This network may itself comprise other computing objects and computing devices that provide services to the system of Fig. 2, and may itself represent multiple interconnected networks.
  • an object such as 110c
  • an object may be hosted on another computing device 10a, 10b, etc. or 110a, 110b, etc.
  • the physical environment depicted may show the connected devices as computers, such illustration is merely exemplary and the physical environment may alternatively be depicted or described comprising various digital devices such as PDAs, televisions, MP3 players, etc., software objects such as interfaces, COM objects and the like.
  • computing systems may be connected together by wired or wireless systems, by local networks or widely distributed networks.
  • many of the networks are coupled to the Internet, which provides the infrastructure for widely distributed computing and encompasses many different networks. Any of the infrastructures may be used for exemplary communications made incident to the present invention.
  • the Internet commonly refers to the collection of networks and gateways that utilize the TCP/IP suite of protocols, which are well-known in the art of computer networking.
  • TCP/IP is an acronym for "Transmission Control Protocol/Internet Protocol.”
  • the Internet can be described as a system of geographically distributed remote computer networks interconnected by computers executing networking protocols that allow users to interact and share information over the network(s).
  • the network infrastructure enables a host of network topologies such as client/server, peer-to-peer, or hybrid architectures.
  • the "client” is a member of a class or group that uses the services of another class or group to which it is not related.
  • a client is a process, i.e., roughly a set of instructions or tasks, that requests a service provided by another program.
  • the client process utilizes the requested service without having to "know" any working details about the other program or the service itself.
  • a client is usually a computer that accesses shared network resources provided by another computer, e.g., a server.
  • computers 110a, 110b, etc. can be thought of as clients and computer 10a, 10b, etc. can be thought of as servers, although any computer could be considered a client, a server, or both, depending on the circumstances. Any of these computing devices may be processing data in a manner that implicates the user-defined type techniques of the invention.
  • a server is typically a remote computer system accessible over a remote or local network, such as the Internet.
  • the client process may be active in a first computer system, and the server process may be active in a second computer system, communicating with one another over a communications medium, thus providing distributed functionality and allowing multiple clients to take advantage of the information-gathering capabilities of the server. Any software objects utilized pursuant to the invention may be distributed across multiple computing devices.
  • Client(s) and server(s) may communicate with one another utilizing the functionality provided by a protocol layer.
  • HTTP HyperText Transfer Protocol
  • WWW World Wide Web
  • a computer network address such as an Internet Protocol (IP) address or other reference such as a Universal Resource Locator (URL) can be used to identify the server or client computers to each other.
  • IP Internet Protocol
  • URL Universal Resource Locator
  • Fig. 2 illustrates an exemplary networked or distributed environment, with a server in communication with client computers via a network/bus, in which the present invention may be employed.
  • the network/bus 14 may be a LAN, WAN, intranet, the Internet, or some other network medium, with a number of client or remote computing devices 110a, 110b, 110c, 1 lOd, 1 lOe, etc., such as a portable computer, handheld computer, thin client, networked appliance, or other device, such as a VCR, TV, oven, light, heater and the like in accordance with the present invention.
  • the present invention may apply to any computing device in connection with which it is desirable to create user-defined types in a database store.
  • the servers 10a, 10b, etc. can be servers with which the clients 110a, 110b, 110c, HOd, HOe, etc. communicate via any of a number of known protocols such as HTTP.
  • Servers 10a, 10b, etc. may also serve as clients 110a, 110b, 110c, HOd, HOe, etc., as may be characteristic of a distributed computing environment.
  • Communications may be wired or wireless, where appropriate.
  • Client devices 110a, 110b, 110c, 1 lOd, 1 lOe, etc. may or may not communicate via communications network/bus 14, and may have independent communications associated therewith. For example, in the case of a TV or VCR, there may or may not be a networked aspect to the control thereof.
  • Each client computer 110a, 110b, 110c, HOd, HOe, etc. and server computer 10a, 10b, etc. may be equipped with various application program modules or objects 135 and with connections or access to various types of storage elements or objects, across which files or data streams may be stored or to which portion(s) of files or data streams may be downloaded, transmitted or migrated. Any computer 10a, 10b, 110a, 110b, etc.
  • the present invention can be utilized in a computer network environment having client computers 110a, 110b, etc. that can access and interact with a computer network/bus 14 and server computers 10a, 10b, etc. that may interact with client computers 110a, 110b, etc. and other like devices, and databases 20.
  • FIG. 3 is a block diagram illustrating the serialization and deserialization of an instance of a user defined type. As shown, an instance of a user-defined type is persisted on disk through serialization of the object representing the instance in memory.
  • an application When an application generates a query that includes a predicate or expression that references a method of an instance of a UDT, the persisted form of the instance is de-serialized (a process also referred to as "hydration") and the CLR allocates memory for the full object in order to receive its stored values. The CLR then invokes the appropriate method on the object that implements the behavior desired by the application or user.
  • Base Type the type that a given type inherits from, also called as supertype, superclass, or proper ancestor in various inheritance models.
  • Sub Type a type that has the current type as its base type, either directly, or through another sub type.
  • Site Any context in the programming language which has an associated type definition. Examples include variable declarations, parameter definitions, column definitions, etc.
  • Declared Type the "compile time" type of a site, such the type of a column in a table, or a function parameter.
  • Exact Type the "runtime" type of a particular value. In a strongly typed system, the exact type has to be of the declared type, or be a sub type of the declared type.
  • Substitutability the property of a site where a value of the subtype can be "substituted" for a value of the basetype.
  • parameter substitutability implies, if a function is declared to take a parameter of a particular type, it should be possible to pass in a value of a subtype to it.
  • UDTs are managed types implemented in an assembly registered with SQL Server. UDTs can be used in most contexts where a native type can be used, including table definitions variables and parameters. The methods, properties, and fields defined in the UDT that conform to the UDT contract can be invoked from T-SQL.
  • UDTs are assumed to be simple scalars with behavior. This assumption is reflected in the simple programming model and the serialization layouts supported by UDTs.
  • a file system may use the UDT abstraction to create "structured types" that are not simple scalars but, instead, could be types with a complex structure and behavior.
  • the following pseudo-code describes the creation of a subtype for several embodiments of the present invention: CREATE TYPE [ type-schema-name. ] subtype-name UNDER [type-schema-name.]base-type-name EXTERNAL NAME assembly-name:clr-type-name
  • the UDT author has to annotate the base type in the type hierarchy with, for example, the SqlUserDefinedType custom attribute, and properties on this attribute specify invariants that apply to the entire type family (a type and all of its subtypes).
  • SqlUserDefinedType A non-exhaustive list of properties for SqlUserDefinedType are illustrated in Fig. 4.
  • the user must add the "UNDER" clause to indicate the base SQL type under which a particular type must be registered, for example: /* create the Address type, with no supertype */ create type Address external name MyTypes ::Address
  • the base-type-name has to be registered as a valid UDT in the specified schema.
  • the CLR type has to be a direct subtype of the CLR type that the base-type-name is defined over.
  • the subtype should not define the SqlUserDefinedTypeAttribute, it should inherit the attribute from its parent. Furthennore, the base type must not be binary ordered.
  • values of the subtype is considered substitutable in column definitions; local variable and parameter declarations in batches, stored procedures, and functions; and query result sets where the result column can contain values that are of the declared type of the column or any of its subtypes.
  • allowing an instance of a subtype to be stored in a column that is declared to be of the supertype has the following implications: (a) the serialization format should be the same for the base type and the subtype; and (b) the MaxByteSize value for the parent has to be big enough to allow storing an instance of the subtype.
  • all assignments may preserve the exact type of the value, and assigning a value of a subtype to a variable of a basetype will always succeed while assigning a value with a declared type of the basetype to a variable of the subtype will require an explicit conversion that will succeed only if the exact type of the value is assignable to the target type. For example, if Address is a type, and if USAddress is a subtype of address, then Addresses may be a table with a column addrcol of type Address as illustrated in Fig.
  • information about the inheritance relationship between two types is a first class part of the scalar typesystem of the database, and this information is used to determine assignability and conversion between values.
  • two new operators called IS OF and TREAT are introduced into the scalar typesystem, and these operators may be used to model type predicates and in-place conversion during scalar expression evaluation.
  • the TREAT operator is transformed during query compilation.
  • the IS OF operator may be rewritten in terms of the hierarchical_type_id to take advantage of any type specific indexes that may be available.
  • the UDT expression compilation process is modified to account for the nature of the dispatch (virtual vs. static), and to disambiguate methods based on the full signature of the method, including the parameter types. This information is passed in from the outer compilation process and is used in method location. Once the method is found, the appropriate IL instruction is used to invoke the static dispatch or virtual method. Then at runtime, the UDT deserialization code uses the exact type of the value to create the object of the correct type and populate it with the persisted state. This object is pushed onto the execution stack and the method is invoked.
  • a client/server deserializer also uses the exact type of the value being deserialized to determine the CLR type that it should deserialize into. If the client has not encountered the type before, it makes an out of band request on a cloned connection to download the metadata about the CLR type on demand and uses this information to locate the CLR type. (See Fig. 6.)
  • the method name matching uses binary collation.
  • the parameter type check ensures that the CLR type for each parameter is implicitly convertible from a SQL parameter type.
  • method overloading is not allowed if there are two suitable methods in the same type, but it is allowed if the two methods take different numbers of parameters or they are defined in different types in the hierarchy.
  • a method or a property returns an instance of a CLR subtype that is not registered with SQL, the system will raise an error at runtime.
  • the actual dispatch instruction used depends on the method that was resolved — that is, if the method found is defined as a virtual or an overridden method, virtual dispatch is used, else, static dispatch is used.
  • TREAT is SQL99 conformant syntax ( ⁇ 6.25 of the SQL standard) and is intended for use in downcasting or narrowing scenarios when an expression of a supertype is to be treated as an expression of one of its subtypes (the standard calls this subtype treatment). This operator is valid in two contexts: (a) to access the properties of that are defined in a subtype; and (b) to update properties that are defined in a subtype. At compile time, if the declared type of value is not a supertype of the target_type, an error will be reported and TREAT will fail. For example: select TREAT (person as Employee) .
  • a new property on SqlUserDefinedTypeAttribute and on SqlMethodAttribute may be used to control whether methods on a type should be invoked if the receiver (this) is a null value, though this can be overridden for specific method by setting it to true using a SqlMethodAttribute.
  • the default value is FALSE.
  • the return type of the method is a nullable type
  • the distinguished null value for the type is returned. If the return type is not nullable, the default clr value for the type is returned.
  • the default value for reference types is null
  • the default value for value types is the result of calling the default constructor for the type.
  • all null values in the system are typed.
  • type predicates as specified in the standard returns unknown if the value is null, there is no way from SQL to determine the specific type of a null value.
  • type predicates support both (a) the return all the instances of a type and all of its subtypes in a column, as well as (b) the return all the instances of a specific type in a column (as set forth in ⁇ 8.14 of the SQL99 standard).
  • udtColumnOrValue IS [NOT] OF (type-specifier) type-specifier : : [ONLY] TYPE [, type-specifier]
  • Type predicates can be used in all scalar contexts where an expression that produces a Boolean is permitted such as, for example, instances of a type only: select convert (USAddress, addrcol) as USAddrCol from Addresses where addrcol is of (only USAddress) ;
  • the overridden implementation when a virtual method is overridden in a subtype, the overridden implementation has to be substitutable with respect to the routine properties specified in the base method. This matrix is checked at type registration time and an error is generated if an invalid combination is detected.
  • the guiding principles here are that the subtype implementation should not break indexability of base method. Thus, if the base method definition is indexable, the overridden implementation should also be indexable.
  • subtype implementation should not invalidate expression compiled for base method definition (null receiver and arguments, sqlfacet, data access, mutator method invocation).
  • subtype implementation can add behaviors that don't conflict with base but need a cast or treat to be activated (indexability).
  • the UDT methods may comprise the routine properties illustrated in Fig. 8.
  • every UDT value has to carry its specific type_id around, and this should never change once a UDT is created. Since there is no support for binary ordering with UDT inheritance, this approach does not affect binary comparisons for the type (as all the instances that will be binary compared will have the same type_id).
  • the DROP type should check that there are no columns defined of any of the supertypes that contain a value of the subtype (and thus the DROP type could be expensive as a result). Similarly, the add subtype will invalidate existing comp plans that reference the supertype for every type in the chain.
  • the various system, methods, and techniques described herein may be implemented with hardware or software or, where appropriate, with a combination of both.
  • the methods and apparatus of the present invention may take the form of program code (i.e., instructions) embodied in tangible media, such as floppy diskettes, CD-ROMs, hard drives, or any other machine-readable storage medium, wherein, when the program code is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention.
  • the computer will generally include a processor, a storage medium readable by the processor (including volatile and non-volatile memory and/or storage elements), at least one input device, and at least one output device.
  • One or more programs are preferably implemented in a high level procedural or object oriented programming language to communicate with a computer system.
  • the program(s) can be implemented in assembly or machine language, if desired.
  • the language may be a compiled or interpreted language, and combined with hardware implementations.
  • the methods and apparatus of the present invention may also be embodied in the form of program code that is transmitted over some transmission medium, such as over electrical wiring or cabling, through fiber optics, or via any other form of transmission, wherein, when the program code is received and loaded into and executed by a machine, such as an EPROM, a gate array, a programmable logic device (PLD), a client computer, a video recorder or the like, the machine becomes an apparatus for practicing the invention.
  • a machine such as an EPROM, a gate array, a programmable logic device (PLD), a client computer, a video recorder or the like
  • PLD programmable logic device
  • client computer a client computer
  • video recorder or the like
  • the program code When implemented on a general-purpose processor, the program code combines with the processor to provide a unique apparatus that operates to perform the indexing functionality of the present invention.

Abstract

Various embodiments of the present invention are directed to a database with an extensible type system for at least one user-defined type that comprises information for describing its structure as well as information for describing an inheritance relationship between itself and another user-defined type (either a subtype or a supertype/base type). For certain embodiments, the user-defined type is defined in something other than Sequential Query Language (SQL) statement such as, for example, a Common Language Runtime (CLR) statement, a statement in C, C++, and C# ('C-sharp'), and/or a visual basic statement. In any event, several embodiments are further directed to a system wherein the database is aware of the inheritance relationship between two user-defined types by an explicit registration of the userdefined types with said database.

Description

SYSTEMS AND METHODS FOR SUPPORTING INHERITANCE FOR USER-DEFINED TYPES
CROSS-REFERENCE TO RELATED APPLICATIONS [0001] This application claims priority to U.S. Application Serial No. 10/837,929 filed May 3, 2004 (Atty Docket No. 3843), which claims priority of continuation-in-part of U.S. Patent Application No. 10/775,282 (Atty. Docket No. MSFT-3029), filed on February 10, 2004, the disclosures of which are incorporated herein by reference in their entirety. [0002] This application is related by subject matter to the inventions disclosed in the following commonly assigned applications, the contents of which are hereby incorporated into this present application in their entirety: U.S. Patent Application No. 10/647,058 (Atty. Docket No. MSFT-1748), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR REPRESENTING UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM BUT INDEPENDENT OF PHYSICAL REPRESENTATION"; U.S. Patent Application No. 10/646,941 (Atty. Docket No. MSFT-1749), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR SEPARATING UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM FROM THEIR PHYSICAL ORGANIZATION"; U.S. Patent Application No. 10/646,940 (Atty. Docket No. MSFT-1750), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR THE IMPLEMENTATION OF A BASE SCHEMA FOR ORGANIZING UNITS OF INFORMATION MANAGEABLE BY A
HARDWARE/SOFTWARE INTERFACE SYSTEM"; U.S. Patent Application No. 10/646,632 (Atty. Docket No. MSFT-1751), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR THE IMPLEMENTATION OF A CORE SCHEMA FOR PROVIDING A TOP-LEVEL STRUCTURE FOR ORGANIZING UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM"; U.S. Patent Application No. 10/646,645 (Atty. Docket No. MSFT-1752), filed on August 21, 2003, entitled "SYSTEMS AND METHOD FOR REPRESENTING RELATIONSHIPS BETWEEN UNITS OF INFORMATION MANAGEABLE BY A HARDWARE/SOFTWARE INTERFACE SYSTEM"; U.S. Patent Application No. 10/646,575 (Atty. Docket No. MSFT-2733), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR INTERFACING APPLICATION PROGRAMS WITH AN ITEM-BASED STORAGE PLATFORM"; U.S. Patent Application No. 10/646,646 (Atty. Docket No. MSFT-2734), filed on August 21, 2003, entitled "STORAGE PLATFORM FOR ORGANIZING, SEARCHING, AND SHARING DATA"; U.S. Patent Application No. 10/646,580 (Atty. Docket No. MSFT-2735), filed on August 21, 2003, entitled "SYSTEMS AND METHODS FOR DATA MODELING IN AN ITEM-BASED STORAGE PLATFORM."
TECHNICAL FIELD [0003] The present invention relates to data storage in a computer system and, more particularly, to systems and methods for providing inheritance to user-defined types (UDTs) in a database system where UDTs are an extensibility mechanism employed in connection with relational database engines and file systems to extend a scalar type system(s) of a data store by registering managed types that implement a specific contract.
BACKGROUND [0004] MICROSOFT SQL SERVER is a comprehensive database management platform that provides extensive management and development tools, a powerful extraction, transformation, and loading (ETL) tool, business intelligence and analysis services, and other capabilities. Among other improvements, the MICROSOFT WINDOWS .NET Framework Common Language Runtime (CLR) was recently integrated into the SQL SERVER database. [0005] The CLR is the heart of the MICROSOFT .NET Framework, and provides the execution environment for all .NET code. Thus, code that runs within the CLR is referred to as "managed code." The CLR provides various functions and services required for program execution, including just-in-time (JIT) compilation, allocating and managing memory, enforcing type safety, exception handling, thread management and security. The CLR is now loaded by SQL SERVER upon the first invocation of a .NET routine. [0006] In previous versions of SQL SERVER, database programmers were limited to using Transact-SQL when writing code on the server side. Transact-SQL is an extension of the Structured Query Language ("SQL") as defined by the International Standards Organization (ISO) and the American National Standards Institute (ANSI). Using Transact-SQL, database developers can create, modify and delete databases and tables, as well as insert, retrieve, modify and delete data stored in a database. Transact-SQL is specifically designed for direct structural data access and manipulation. While Transact-SQL excels at structural data access and management, it is not a full-fledged programming language as are VISUAL BASIC .NET and C#. For example, Transact-SQL does not support arrays, collections, for each loops, bit shifting or classes. [0007] With the CLR integrated into the SQL SERVER database, database developers have been able to perform tasks that were impossible or difficult to achieve with Transact-SQL alone. Both VISUAL BASIC .NET and C# are modern programming languages offering full support for arrays, structured exception handling, and collections. Developers can leverage CLR integration to write code that has more complex logic and is more suited for computation tasks using languages such as VISUAL BASIC .NET and C#. These programming languages offer object-oriented capabilities such as encapsulation, inheritance and polymorphism. Related code can be easily organized into classes and namespaces. [0008] Managed code is better suited than Transact-SQL for number crunching and complicated execution logic, and features extensive support for many complex tasks, including string handling and regular expressions. With the functionality found in the .NET Framework Base Class Library (BCL), database developers have access to thousands of pre-built classes and routines which can be easily accessed from any stored procedure, trigger or user-defined function. [0009] Another benefit of managed code is type safety. Before managed code is executed, the CLR verifies that the code is safe. This process is known as "verification." During verification, the CLR performs several checks to ensure that the code is safe to run. For example, the code is checked to ensure that no memory is read that has not be been written to. The CLR will also prevent buffer overflows. [0010] When writing managed code, the deployment unit is called an assembly. An assembly is packaged as a dynamic link library (DLL). Managed DLL assemblies can be loaded into and hosted by SQL SERVER. The CREATE ASSEMBLY statement is used to register an assembly in the server. Here is an example: CREATE ASSEMBLY YukonCLR FROM 'C:\MyDBApp\YukonCLR.dll'
In this example, the FROM clause specifies the pathname of the assembly to load. [0011] SQL SERVER has traditionally supported "built-in" scalar types such as integer, floating point number, date, time, and character string. These built-in types also come with a set of built-in operations such as +, -, *, / as well as built-in functions over these types. These types, operations, and functions are "built-in" in the sense that they are implemented and packaged by the product and users cannot define their own types. [0012] It is desirable for a database system, such as SQL SERVER, to allow users to extend the type system of the database system such that users could create new types that act as scalar types in the database system but which contain more complex structure and behavior — for example, to create a "Point" type consisting of X and Y coordinates. In this regard, the SQL standard and some database management system (DBMS) products have used the term "user- defined type" to describe several forms of type extensibility. For example, the SQL-99 standard describes a "distinct type," which is a type that can be defined by a user to have an internal representation that is a value of an existing SQL built-in data type. A distinct type may optionally share comparison and arithmetic operators, type conversions, and aggregate (column) functions (e.g., max, min, average) with an existing scalar type. The distinct type may allow constraints to be defined on its values. In addition, a distinct type may expose behaviors beyond those of an existing scalar type by defining new functions specific to the distinct type via user- defined functions. With respect to type checking, the distinct type and existing scalar types are considered to be different types. [0013] The main advantage of distinct types is ease of definition. If the internal representation of the new type has a single data member that can be described with an existing built-in type and the built-in type already implements most of the behaviors required on the new type, then distinct types are an attractive alternative. The user does not have to worry about implementing the behaviors required to manage the on-disk storage of the type, constructors, comparison operators (used for ordering and indexing), arithmetic operators, and type conversion (casting) operators. The user only needs to choose what functionality of the underlying built-in type needs to be exposed on the distinct type and optionally add constraints on values or additional functions on the new type. Another advantage of distinct types is that all of the query processing available for built-in types, such as computation of histograms, can be readily used on columns of distinct types. A disadvantage of distinct types, however, is that they can not easily be used to create more complex types. [0014] The SQL-99 standard also described a "structured type," which is a type that can be defined by user and that has an internal representation that is a collection of data members, each of which may be of a different SQL built-in or user-defined type. This is similar to the notion of a struct in C and C++. SQL-99 describes a style for defining structured types by which a user only needs to define the type in terms of its internal structure. The system automatically generates accessor and mutator functions on its data members, constructor, and functions to manage the on-disk representation of instances of the type. [0015] The main advantages of structured types as defined in SQL are (a) ease of definition of basic behaviors of the type, and (b) the flexibility to define more complex types. However, a significant disadvantage of structure types is the complexity of definition of type- specific methods, which are usually defined via external functions written in a general-purpose programming language like C or C++. In order to define a structured type fully, the definer of the type needs to straddle a line between SQL and some other programming language. [0016] While the distinct type and structured type features of SQL 99 offer some advantages to users in terms of enabling them to extend the existing scalar type system of a SQL database, there has been a need for improved systems and methods for enabling a user to extend the scalar type system of a database system through user-defined types that act as scalar types but that contain more complex structure and behavior. [0017] The invention disclosed in the UDT Patent Application is directed to a system and method that allows a user to extend the scalar type system of a database system by creating user-defined types that act as scalar types but that contain more complex structure and behavior. According to that invention, a user writes program code in a high-level programming language that implements a class that defines the structure of a user-defined type and methods that can be invoked on instances of the user-defined type. As used therein (and herein), the term "structure," when referring to a user-defined type, encompasses the set of fields or properties that implement the type. The type of each field in the UDT Patent Application could be a scalar SQL type or any previously defined user-defined type. The class defining a user-defined type is then compiled and registered with the database system. Specifically, a CLR class defining a user- defined type may be compiled into an assembly which is then registered with the database system via a CREATE ASSEMBLY data definition statement. After the assembly is registered, a user can register the class within the assembly that defines the user-defined type using a CREATE TYPE data definition statement. [0018] For the invention of the UDT Patent Application, the database system enforces a specific contract that the class must implement to enable the user-defined type to act as a scalar in the SQL type system. The term "contract," as used therein (and herein), refers to a technique that is used at runtime in object-oriented programming environments to check that code to be executed satisfies certain pre-conditions or requirements to ensure that it will execute properly. According to that invention, the contract against which a class that defines a user-defined type is compared comprises several requirements. First, the class must specify one of a plurality of different formats for persisting instances of the user-defined type in a database store. Second, the class must be capable of returning a null value for the user-defined type. Third, the class must provide a method for converting the user-defined type to and from another type, such as a string type. Once these requirements are satisfied, the database system enables instances of the user-defined type to be created. In one embodiment of that application, the user-defined type can be instantiated as a column value in a table, a variable, a parameter of a routine, or a return value of a routine. The database system stores metadata about the class defining the user-defined type for subsequent use in creating instances of the type. In another embodiment of that invention, the verification of the user-defined type contract is performed using the metadata describing the class that defines the type. [0019] The plurality of different formats for persisting instances of the user-defined type comprises a first format in which an instance of the user-defined type is automatically serialized in accordance with a native format of the database system, and a second format in which an instance of the user-defined type is serialized in a manner defined by the user authored class. Additionally, when the invention of the UDT Patent Application is embodied within MICROSOFT SQL SERVER, in which the MICROSOFT .NET CLR is integrated, a third format is available in which an instance of the user-defined type is serialized in accordance with a method provided by the MICROSOFT .NET Framework. [0020] For the invention of UDT Patent Application, expressions in the query language of the database system can include one or more references to an instance(s) of a user-defined type, such that evaluation of the expression requires invocation of a method on the instance of the user-defined type. When the database system receives such a query language expression, it translates the expression into a sequence of program code instructions that, when executed, invoke the required method on the instance of the user-defined type. The database system then returns the result of the method invocation as the result of evaluation of the query language expression. In one embodiment, the instance of the user-defined type is deserialized prior to invoking the method on the instance. [0021] Another feature of the that invention is the ability to change the value of an instance of a user-defined type through invocation of a mutator method. Specifically, the author of the class that defines the user-defined type includes a mutator method as part of the class. When invoked on an instance of the user-defined type, the mutator method enables a value of the user-defined type to be changed. This process may comprise deserializing the instance of the user-defined type, invoking the mutator method to change the value of the deserialized data of the instance, and then serializing the modified instance of the user-defined type to persist the changes. [0022] According to yet another feature of that invention, the class defining a user- defined type may further contain an attribute that specifies that serialized binary representations of instances of the user-defined type will be binary ordered. This allows binary comparisons to be made on instances of the type and also enables indexing to be performed on instances of the type. Specifically, for instances of a user-defined type that are binary ordered, when a query language expression that requires some comparison of two instances of the type is received by the database system (e.g., >, <, or =), the serialized binary representations of the two instances can be used to evaluate the expression, without deserializing either instance. Additionally, for a user-defined type that is binary ordered, a table in the database store can be created that has a column defined as the user-defined type. An index can then be created on the column. An index can also be created over a query language expression that references the user-defined type. In this case, a computed column is first generated over the expression, and then an index is created over the computed column.
SUMMARY [0023] Various embodiments of the present invention are directed to extending a UDT framework to support inheritance. Inheritance is one of the key tenets of object oriented programming and is a basic building block for most modern typesystems (such as the CLR typesystem or the XSD typesystem). With this extension, the object data modeling capabilities of the store are greatly improved. It enables a natural mapping from a common language runtime (CLR) typesystem to a database typesystem without the need for cumbersome and slow object to relational mapping technologies. Supporting concepts related to inheritance in the query language greatly simplify the SQL programming model for inheritance. [0024] While inheritance for user-defined types has been implemented in other database products, various embodiments of the present invention are directed to UDT inheritance solutions that possess one or more of the following capabilities not present in the existing art: • Seamless integration with the CLR typesystem. Several embodiments of the present invention are directed to UDT inheritance system and methods where the basic UDT contract is specified as a set of required custom attributes and interfaces on the managed type, and wherein inheritance extends this same concept and uses the managed type definition to drive the specification of inheritance to the SQL typesystem. This solution enables the developer to author inherited types in any CLS- compliant programming language of their choice, including but not limited to C#, C++ and VB.NET. • Full support for substitutability. For several embodiments of the present invention, if a site (variable, parameter, column definition, etc.) is declared to be of a particular UDT, a value of any of the subtypes of that UDT can be stored in that site. This notion of substitutability extends to all uses of the type including casting, conversion, assignment, and method invocation, as well as in the way result sets are processed by the client application. • Deep integration with the indexing and query subsystems. For numerous embodiments of the present invention, inheritance adds the notion of the exact runtime type of a value that can be different from the declared type. For example, SQL Server supports the creation of indexes over this kind of information, and also uses the index in predicates based on the type of the value. Inheritance would also add the notion of virtual behaviors that can be redefined (overridden) in subtypes, and this notion may be folded into the computation of indexability of a particular UDT function and may be verified at type creation time. • Queryable metadadata and catalog services. For various embodiments of the present inventino, the relationship between a type and its super-type is recorded in metadata at type creation time and is available through queryable catalog views. This lets applications compose queries to determine the substitutable extent of a particular type. [0025] In this regard, one embodiment of the present invention is directed to a database with an extensible type system for at least one user-defined type that comprises information for describing its structure as well as information for describing an inheritance relationship between itself and another user-defined type (either a subtype or a supertype / base type). For certain embodiments, the user-defined type is defined in something other than Sequential Query Language (SQL) statement such as, for example, a Common Language Runtime (CLR) statement, a statement in C, C++, and C# ("C-sharp"), and/or a visual basic statement. In any event, several embodiments are further directed to a system wherein the database is aware of the inheritance relationship between two user-defined types (one as the subtype and the other as the supertype / base type). [0026] For certain embodiments, the database is made aware of said inheritance relationship between the two user-defined types by an explicit registration of the user-defined types with said database. In this regard, one overarching method of the invention for several embodiments comprises: (a) compiling a type into an assembly; (b) registering said assembly with said database; (c) registering said type of said assembly with said database; and (d) using said type.
BRIEF DESCRIPTION OF THE DRAWINGS [0027] The foregoing summary, as well as the following detailed description of preferred embodiments, is better understood when read in conjunction with the appended drawings. For the purpose of illustrating the invention, there is shown in the drawings exemplary constructions of the invention; however, the invention is not limited to the specific methods and instrumentalities disclosed. In the drawings: Fig. 1 is a block diagram representing a computer system in which aspects of the present invention may be incorporated; Fig. 2 is a block diagram representing an exemplary network environment having a variety of computing devices in which the present invention may be implemented; Fig. 3 is a block diagram illustrating the serialization and deserialization of an instance of a user defined type that has been instantiated in managed code; Fig. 4 is a table illustrating a non-exhaustive list of properties for SqlUserDefinedType; Fig. 5 is pseudo-code illustrating that, if Address is a type, and if US Address is a subtype of address, then Addresses may be a table with a column addrcol of type Address. Fig. 6 is pseudo-code illustrating a client/server deserializer that uses the exact type of the value being deserialized to determine the CLR type that it should deserialize into; Fig. 7 is a table illustrating the behaviors and semantics for the CONVERT, CAST, and TREAT commands; and Fig. 8 is a table illustrating the routine properties the UDT methods may comprise.
DETAILED DESCRIPTION [0028] The subject matter of the present invention is described with specificity to meet statutory requirements. However, the description itself is not intended to limit the scope of this patent. Rather, the inventors have contemplated that the claimed subject matter might also be embodied in other ways, to include different steps or elements similar to the ones described in this document, in conjunction with other present or future technologies. Moreover, although the term "step" may be used herein to connote different aspects of methods employed, the term should not be interpreted as implying any particular order among or between various steps herein disclosed unless and except when the order of individual steps is explicitly described. [0029] In the embodiment described below, the foregoing features of the present invention are described as implemented in the MICROSOFT SQL SERVER database system. As mentioned above, SQL SERVER incorporates the MICROSOFT .NET Common Language Runtime (CLR) to enable managed code to be written and executed to operate on the data store of a SQL SERVER database. While the embodiment described below operates in this context, it is understood that the present invention is by no means limited to implementation in the SQL SERVER product. Rather, the present invention can be implemented in any database system that supports the execution of object-oriented programming code to operate on a database store, such as object oriented database systems and relational database systems with object relational extensions. Accordingly, it is understood that the present invention is not limited to the particular embodiment described below, but is intended to cover all modifications that are within the spirit and scope of the invention as defined by the appended claims.
Computer Environment [0030] Numerous embodiments of the present invention may execute on a computer. Fig. 1 and the following discussion is intended to provide a brief general description of a suitable computing environment in which the invention may be implemented. Although not required, the invention will be described in the general context of computer executable instructions, such as program modules, being executed by a computer, such as a client workstation or a server. Generally, program modules include routines, programs, objects, components, data structures and the like that perform particular tasks or implement particular abstract data types. Moreover, those skilled in the art will appreciate that the invention may be practiced with other computer system configurations, including hand held devices, multi processor systems, microprocessor based or programmable consumer electronics, network PCs, minicomputers, mainframe computers and the like. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote memory storage devices. [0031] As shown in Fig. 1, an exemplary general purpose computing system includes a conventional personal computer 20 or the like, including a processing unit 21, a system memory 22, and a system bus 23 that couples various system components including the system memory to the processing unit 21. The system bus 23 may be any of several types of bus structures including a memory bus or memory controller, a peripheral bus, and a local bus using any of a variety of bus architectures. The system memory includes read only memory (ROM) 24 and random access memory (RAM) 25. A basic input/output system 26 (BIOS), containing the basic routines that help to transfer information between elements within the personal computer 20, such as during start up, is stored in ROM 24. The personal computer 20 may further include a hard disk drive 27 for reading from and writing to a hard disk, not shown, a magnetic disk drive 28 for reading from or writing to a removable magnetic disk 29, and an optical disk drive 30 for reading from or writing to a removable optical disk 31 such as a CD ROM or other optical media. The hard disk drive 27, magnetic disk drive 28, and optical disk drive 30 are connected to the system bus 23 by a hard disk drive interface 32, a magnetic disk drive interface 33, and an optical drive interface 34, respectively. The drives and their associated computer readable media provide non volatile storage of computer readable instructions, data structures, program modules and other data for the personal computer 20. Although the exemplary environment described herein employs a hard disk, a removable magnetic disk 29 and a removable optical disk 31, it should be appreciated by those skilled in the art that other types of computer readable media which can store data that is accessible by a computer, such as magnetic cassettes, flash memory cards, digital video disks, Bernoulli cartridges, random access memories (RAMs), read only memories (ROMs) and the like may also be used in the exemplary operating environment. [0032] A number of program modules may be stored on the hard disk, magnetic disk 29, optical disk 31, ROM 24 or RAM 25, including an operating system 35, one or more application programs 36, other program modules 37 and program data 38. A user may enter commands and information into the personal computer 20 through input devices such as a keyboard 40 and pointing device 42. Other input devices (not shown) may include a microphone, joystick, game pad, satellite disk, scanner or the like. These and other input devices are often connected to the processing unit 21 through a serial port interface 46 that is coupled to the system bus, but may be connected by other interfaces, such as a parallel port, game port or universal serial bus (USB). A monitor 47 or other type of display device is also connected to the system bus 23 via an interface, such as a video adapter 48. In addition to the monitor 47, personal computers typically include other peripheral output devices (not shown), such as speakers and printers. The exemplary system of Fig. 1 also includes a host adapter 55, Small Computer System Interface (SCSI) bus 56, and an external storage device 62 connected to the SCSI bus 56. [0033] The personal computer 20 may operate in a networked environment using logical connections to one or more remote computers, such as a remote computer 49. The remote computer 49 may be another personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the personal computer 20, although only a memory storage device 50 has been illustrated in Fig. 1. The logical connections depicted in Fig. 1 include a local area network (LAN) 51 and a wide area network (WAN) 52. Such networking environments are commonplace in offices, enterprise wide computer networks, intranets and the Internet. [0034] When used in a LAN networking environment, the personal computer 20 is connected to the LAN 51 through a network interface or adapter 53. When used in a WAN networking environment, the personal computer 20 typically includes a modem 54 or other means for establishing communications over the wide area network 52, such as the Internet. The modem 54, which may be internal or external, is connected to the system bus 23 via the serial port interface 46. In a networked environment, program modules depicted relative to the personal computer 20, or portions thereof, may be stored in the remote memory storage device. It will be appreciated that the network connections shown are exemplary and other means of establishing a communications link between the computers may be used. [0035] While it is envisioned that numerous embodiments of the present invention are particularly well-suited for computerized systems, nothing in this document is intended to limit the invention to such embodiments. On the contrary, as used herein the term "computer system" is intended to encompass any and all devices capable of storing and processing information and/or capable of using the stored information to control the behavior or execution of the device itself, regardless of whether such devices are electronic, mechanical, logical, or virtual in nature.
Network Environment [0036] Fig. 2 provides a schematic diagram of an exemplary networked or distributed computing environment. The distributed computing environment comprises computing objects 10a, 10b, etc. and computing objects or devices 110a, 110b, 110c, etc. These objects may comprise programs, methods, data stores, programmable logic, etc. The objects may comprise portions of the same or different devices such as PDAs, televisions, MP3 players, personal computers, etc. Each object can communicate with another object by way of the communications network 14. This network may itself comprise other computing objects and computing devices that provide services to the system of Fig. 2, and may itself represent multiple interconnected networks. In accordance with an aspect of the invention, each object 10a, 10b, etc. or 110a, 110b, 110c, etc. may contain an application that might make use of an API, or other object, software, firmware and/or hardware, to request use of the processes used to implement the methods of the present invention. [0037] It can also be appreciated that an object, such as 110c, may be hosted on another computing device 10a, 10b, etc. or 110a, 110b, etc. Thus, although the physical environment depicted may show the connected devices as computers, such illustration is merely exemplary and the physical environment may alternatively be depicted or described comprising various digital devices such as PDAs, televisions, MP3 players, etc., software objects such as interfaces, COM objects and the like. [0038] There are a variety of systems, components, and network configurations that support distributed computing environments. For example, computing systems may be connected together by wired or wireless systems, by local networks or widely distributed networks. Currently, many of the networks are coupled to the Internet, which provides the infrastructure for widely distributed computing and encompasses many different networks. Any of the infrastructures may be used for exemplary communications made incident to the present invention. [0039] The Internet commonly refers to the collection of networks and gateways that utilize the TCP/IP suite of protocols, which are well-known in the art of computer networking. TCP/IP is an acronym for "Transmission Control Protocol/Internet Protocol." The Internet can be described as a system of geographically distributed remote computer networks interconnected by computers executing networking protocols that allow users to interact and share information over the network(s). Because of such wide-spread information sharing, remote networks such as the Internet have thus far generally evolved into an open system for which developers can design software applications for performing specialized operations or services, essentially without restriction. [0040] Thus, the network infrastructure enables a host of network topologies such as client/server, peer-to-peer, or hybrid architectures. The "client" is a member of a class or group that uses the services of another class or group to which it is not related. Thus, in computing, a client is a process, i.e., roughly a set of instructions or tasks, that requests a service provided by another program. The client process utilizes the requested service without having to "know" any working details about the other program or the service itself. In a client/server architecture, particularly a networked system, a client is usually a computer that accesses shared network resources provided by another computer, e.g., a server. In the example of Fig. 2, computers 110a, 110b, etc. can be thought of as clients and computer 10a, 10b, etc. can be thought of as servers, although any computer could be considered a client, a server, or both, depending on the circumstances. Any of these computing devices may be processing data in a manner that implicates the user-defined type techniques of the invention. [0041] A server is typically a remote computer system accessible over a remote or local network, such as the Internet. The client process may be active in a first computer system, and the server process may be active in a second computer system, communicating with one another over a communications medium, thus providing distributed functionality and allowing multiple clients to take advantage of the information-gathering capabilities of the server. Any software objects utilized pursuant to the invention may be distributed across multiple computing devices. [0042] Client(s) and server(s) may communicate with one another utilizing the functionality provided by a protocol layer. For example, HyperText Transfer Protocol (HTTP) is a common protocol that is used in conjunction with the World Wide Web (WWW), or "the Web." Typically, a computer network address such as an Internet Protocol (IP) address or other reference such as a Universal Resource Locator (URL) can be used to identify the server or client computers to each other. The network address can be referred to as a URL address. Communication can be provided over any available communications medium. [0043] Thus, Fig. 2 illustrates an exemplary networked or distributed environment, with a server in communication with client computers via a network/bus, in which the present invention may be employed. The network/bus 14 may be a LAN, WAN, intranet, the Internet, or some other network medium, with a number of client or remote computing devices 110a, 110b, 110c, 1 lOd, 1 lOe, etc., such as a portable computer, handheld computer, thin client, networked appliance, or other device, such as a VCR, TV, oven, light, heater and the like in accordance with the present invention. It is thus contemplated that the present invention may apply to any computing device in connection with which it is desirable to create user-defined types in a database store. [0044] In a network environment in which the communications network/bus 14 is the Internet, for example, the servers 10a, 10b, etc. can be servers with which the clients 110a, 110b, 110c, HOd, HOe, etc. communicate via any of a number of known protocols such as HTTP. Servers 10a, 10b, etc. may also serve as clients 110a, 110b, 110c, HOd, HOe, etc., as may be characteristic of a distributed computing environment. [0045] Communications may be wired or wireless, where appropriate. Client devices 110a, 110b, 110c, 1 lOd, 1 lOe, etc. may or may not communicate via communications network/bus 14, and may have independent communications associated therewith. For example, in the case of a TV or VCR, there may or may not be a networked aspect to the control thereof. Each client computer 110a, 110b, 110c, HOd, HOe, etc. and server computer 10a, 10b, etc. may be equipped with various application program modules or objects 135 and with connections or access to various types of storage elements or objects, across which files or data streams may be stored or to which portion(s) of files or data streams may be downloaded, transmitted or migrated. Any computer 10a, 10b, 110a, 110b, etc. may be responsible for the maintenance and updating of a database, memory, or other storage element 20 for storing data processed according to the invention. Thus, the present invention can be utilized in a computer network environment having client computers 110a, 110b, etc. that can access and interact with a computer network/bus 14 and server computers 10a, 10b, etc. that may interact with client computers 110a, 110b, etc. and other like devices, and databases 20.
UDTs and Managed Code [0046] Fig. 3 is a block diagram illustrating the serialization and deserialization of an instance of a user defined type. As shown, an instance of a user-defined type is persisted on disk through serialization of the object representing the instance in memory. When an application generates a query that includes a predicate or expression that references a method of an instance of a UDT, the persisted form of the instance is de-serialized (a process also referred to as "hydration") and the CLR allocates memory for the full object in order to receive its stored values. The CLR then invokes the appropriate method on the object that implements the behavior desired by the application or user.
UDT Inheritance [0047] As used herein, the following terms shall have the meanings indicated:
• Base Type: the type that a given type inherits from, also called as supertype, superclass, or proper ancestor in various inheritance models.
• Sub Type: a type that has the current type as its base type, either directly, or through another sub type.
• Site: Any context in the programming language which has an associated type definition. Examples include variable declarations, parameter definitions, column definitions, etc.
• Declared Type: the "compile time" type of a site, such the type of a column in a table, or a function parameter.
• Exact Type: the "runtime" type of a particular value. In a strongly typed system, the exact type has to be of the declared type, or be a sub type of the declared type.
• Substitutability: the property of a site where a value of the subtype can be "substituted" for a value of the basetype. For example, parameter substitutability implies, if a function is declared to take a parameter of a particular type, it should be possible to pass in a value of a subtype to it. [0048] For various embodiments of the present invention, UDTs are managed types implemented in an assembly registered with SQL Server. UDTs can be used in most contexts where a native type can be used, including table definitions variables and parameters. The methods, properties, and fields defined in the UDT that conform to the UDT contract can be invoked from T-SQL. [0049] For several embodiments, UDTs are assumed to be simple scalars with behavior. This assumption is reflected in the simple programming model and the serialization layouts supported by UDTs. For example, a file system may use the UDT abstraction to create "structured types" that are not simple scalars but, instead, could be types with a complex structure and behavior. [0050] The following pseudo-code describes the creation of a subtype for several embodiments of the present invention: CREATE TYPE [ type-schema-name. ] subtype-name UNDER [type-schema-name.]base-type-name EXTERNAL NAME assembly-name:clr-type-name
[0051] To establish an inheritance contract, and for several embodiments of the present invention, the UDT author has to annotate the base type in the type hierarchy with, for example, the SqlUserDefinedType custom attribute, and properties on this attribute specify invariants that apply to the entire type family (a type and all of its subtypes). A non-exhaustive list of properties for SqlUserDefinedType are illustrated in Fig. 4. Then, at type registration time, the user must add the "UNDER" clause to indicate the base SQL type under which a particular type must be registered, for example: /* create the Address type, with no supertype */ create type Address external name MyTypes ::Address
/^create the USAddress subtype under it */ create type USAddress under Address external name MyTypes :: USAddress
[0052] For several embodiments of the present invention, the base-type-name has to be registered as a valid UDT in the specified schema. In addition, the CLR type has to be a direct subtype of the CLR type that the base-type-name is defined over. The subtype should not define the SqlUserDefinedTypeAttribute, it should inherit the attribute from its parent. Furthennore, the base type must not be binary ordered. Likewise, all the out of band routine properties (SqlMethodAttribute annotations) that are specified in the base type must be consistent with the subtype definition — specifically, all indexable methods defined in the base type must continue to be indexable for routines that are overridden in the subtype — and this information might be gathered from the base type and verified by enumerating over all the routines in the subtype as part of the CREATE TYPE checks. [0053] For various embodiments of the present invention, the framework for UDT inheritance may be described in terms of the external surface area of the feature and its underlying implementation. In addition, values of the subtype is considered substitutable in column definitions; local variable and parameter declarations in batches, stored procedures, and functions; and query result sets where the result column can contain values that are of the declared type of the column or any of its subtypes. [0054] For several embodiments of the present invention, allowing an instance of a subtype to be stored in a column that is declared to be of the supertype has the following implications: (a) the serialization format should be the same for the base type and the subtype; and (b) the MaxByteSize value for the parent has to be big enough to allow storing an instance of the subtype. If there is insufficient space, at runtime, attempts to store a value of the subtype in a column of the base type will fail, and so to prevent this error the base type can be defined with unlimited. [0055] For various embodiments of the present invention, all assignments may preserve the exact type of the value, and assigning a value of a subtype to a variable of a basetype will always succeed while assigning a value with a declared type of the basetype to a variable of the subtype will require an explicit conversion that will succeed only if the exact type of the value is assignable to the target type. For example, if Address is a type, and if USAddress is a subtype of address, then Addresses may be a table with a column addrcol of type Address as illustrated in Fig. 5. [0056] In implementation for several embodiments of the present invention, information about the inheritance relationship between two types is a first class part of the scalar typesystem of the database, and this information is used to determine assignability and conversion between values. In certain embodiments, two new operators called IS OF and TREAT are introduced into the scalar typesystem, and these operators may be used to model type predicates and in-place conversion during scalar expression evaluation. To enable proper semantic reasoning and combining common operations (such as an IS OF predicate and a TREAT in the project list of a query), the TREAT operator is transformed during query compilation. As a further optimization, the IS OF operator may be rewritten in terms of the hierarchical_type_id to take advantage of any type specific indexes that may be available. When a UDT expression is encountered, the UDT expression compilation process is modified to account for the nature of the dispatch (virtual vs. static), and to disambiguate methods based on the full signature of the method, including the parameter types. This information is passed in from the outer compilation process and is used in method location. Once the method is found, the appropriate IL instruction is used to invoke the static dispatch or virtual method. Then at runtime, the UDT deserialization code uses the exact type of the value to create the object of the correct type and populate it with the persisted state. This object is pushed onto the execution stack and the method is invoked. [0057] For several embodiments, a client/server deserializer also uses the exact type of the value being deserialized to determine the CLR type that it should deserialize into. If the client has not encountered the type before, it makes an out of band request on a cloned connection to download the metadata about the CLR type on demand and uses this information to locate the CLR type. (See Fig. 6.) [0058] For several embodiments, it may be given that all methods, properties, and fields invoked from T-SQL are resolved dynamically using the exact type of the instance and not the declared type of the call site. Moreover, all inherited methods, properties, and fields that are defined in the supertype and can be callable directly from T-SQL will be allowed. Thus there will be no difference in the syntax for invoking declared methods versus inherited methods. [0059] For several embodiments of the present invention, the method for locating the target invocation can be characterized in pseudo-code as follows: If D is the declared type of the call site, and M is the method name, and PI ..Pn are the parameters to the method with Tl ..Tn being the types of the parameters, then if the query is "select <site of type D>.M(P1...Pn)", the invocation method would comprise: startType = D; Method targetMethod = null; while (true) { If (startType == null) throw new NoSuchMethodException (D, M) ; Method[] methods = GetMethods (startType, M, {Tl...Tn}) if (methods .Length == 0) startType = startType . BaseType; else if (methods .Length > 1) throw new OverloadedMethodExceptio (M) ; else { targetMethod = methods [0] ; break; } }
[0060] In regard to the method invocation used for several embodiments of the present invention, the method name matching uses binary collation. In addition, the parameter type check ensures that the CLR type for each parameter is implicitly convertible from a SQL parameter type. Moreover, method overloading is not allowed if there are two suitable methods in the same type, but it is allowed if the two methods take different numbers of parameters or they are defined in different types in the hierarchy. Similarly, if a method or a property returns an instance of a CLR subtype that is not registered with SQL, the system will raise an error at runtime. Furthermore, the actual dispatch instruction used depends on the method that was resolved — that is, if the method found is defined as a virtual or an overridden method, virtual dispatch is used, else, static dispatch is used. [0061] For various embodiments of the present invention, conversions from a type to its supertype (upcast) will always succeed, while onversions from a type to its subtype (downcast) will succeed if the value is of the correct type and the co version will fail if it is not of the correct type where the exact failure mode depends on the conversion operator used. [0062] For such embodiments, there are three conversion operators: CONVERT, CAST, and TREAT as follows: • CONVERT([schema.]type, target ype) -> value of [schema.]type or error if the conversion fails. • CAST( value as [schema.] targetjype) - value of [schema.]type or error if the convert fails. • TREAT(value as [schema.]target_type) - value of [schema.]type or NULL if the conversion fails.
For these embodiments, CAST and CONVERT may be existing operators that have been modified to understand inheritance and substitutability. TREAT, on the other hand, is SQL99 conformant syntax (§ 6.25 of the SQL standard) and is intended for use in downcasting or narrowing scenarios when an expression of a supertype is to be treated as an expression of one of its subtypes (the standard calls this subtype treatment). This operator is valid in two contexts: (a) to access the properties of that are defined in a subtype; and (b) to update properties that are defined in a subtype. At compile time, if the declared type of value is not a supertype of the target_type, an error will be reported and TREAT will fail. For example: select TREAT (person as Employee) . Salary from T where person is of (Employee) update T set TREAT (person as Employee) . Salary = 10000 where ID = x [0063] On the other hand, the standard does not support invoking mutator methods on a NULL instance, and SQL Server will also enforce this restriction for the results of the TREAT operator. If TREAT produces a NULL value, the system will raise an error on attempts to update the NULL value. In other words, logically TREAT (value as type_x) may be transformed to IF (value IS OF type_x) THEN value else NULL for several embodiments of the present invention, as represented by the table illustrated in Fig. 7 which, in general, illustrates the behaviors and semantics for the CONVERT, CAST, and TREAT commands. [0064] For several embodiments, and as part of the UDT extensions, a new property on SqlUserDefinedTypeAttribute and on SqlMethodAttribute may be used to control whether methods on a type should be invoked if the receiver (this) is a null value, though this can be overridden for specific method by setting it to true using a SqlMethodAttribute. For these embodiments, the default value is FALSE. In addition, if the return type of the method is a nullable type, the distinguished null value for the type is returned. If the return type is not nullable, the default clr value for the type is returned. The default value for reference types is null, the default value for value types is the result of calling the default constructor for the type. [0065] For various embodiments, all null values in the system are typed. However, since type predicates as specified in the standard returns unknown if the value is null, there is no way from SQL to determine the specific type of a null value. Hence, these embodiments may treat all null values as being of the declared type of the call site, and not the exact type of the value that was inserted into site. For example, declare @emp Employee set @emp = NULL insert into Persons values (Θemp) select pcol from Persons - returns a null value, the type of the instance is Person
[0066] For various embodiments, type predicates support both (a) the return all the instances of a type and all of its subtypes in a column, as well as (b) the return all the instances of a specific type in a column (as set forth in § 8.14 of the SQL99 standard). Consider the following: udtColumnOrValue IS [NOT] OF (type-specifier) type-specifier : := [ONLY] TYPE [, type-specifier]
[0067] If udtColumnOrValue is null, the result is unknown, otherwise the predicate returns a boolean result. [0068] Type predicates can be used in all scalar contexts where an expression that produces a Boolean is permitted such as, for example, instances of a type only: select convert (USAddress, addrcol) as USAddrCol from Addresses where addrcol is of (only USAddress) ;
This is in contrast to instances of a type and all of its subtypes: select convert (USAddress, addrcol) as USAddrCol from Addresses where addrcol is of (USAddress) ;
[0069] In addition, for several embodiments of the present invention the sys.assembly_types catalog view will have one additional column as follows:
[0070] In addition, and for numerous embodiments of the present invention, when a virtual method is overridden in a subtype, the overridden implementation has to be substitutable with respect to the routine properties specified in the base method. This matrix is checked at type registration time and an error is generated if an invalid combination is detected. The guiding principles here are that the subtype implementation should not break indexability of base method. Thus, if the base method definition is indexable, the overridden implementation should also be indexable. Moreover, subtype implementation should not invalidate expression compiled for base method definition (null receiver and arguments, sqlfacet, data access, mutator method invocation). On the other hand, subtype implementation can add behaviors that don't conflict with base but need a cast or treat to be activated (indexability). If "N" denotes "new in subtype," that is, where the subtype can set a property to true even if base type has value set to false or not defined, and if "S" denotes "same as base definition," that is, where the definition in the subtype is the same as in the base type, then the UDT methods may comprise the routine properties illustrated in Fig. 8. [0071] In addition to the foregoing, and for several embodiments of the present invention, every UDT value has to carry its specific type_id around, and this should never change once a UDT is created. Since there is no support for binary ordering with UDT inheritance, this approach does not affect binary comparisons for the type (as all the instances that will be binary compared will have the same type_id). Moreover, the DROP type should check that there are no columns defined of any of the supertypes that contain a value of the subtype (and thus the DROP type could be expensive as a result). Similarly, the add subtype will invalidate existing comp plans that reference the supertype for every type in the chain.
Conclusion [0072] The various system, methods, and techniques described herein may be implemented with hardware or software or, where appropriate, with a combination of both. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, may take the form of program code (i.e., instructions) embodied in tangible media, such as floppy diskettes, CD-ROMs, hard drives, or any other machine-readable storage medium, wherein, when the program code is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention. In the case of program code execution on programmable computers, the computer will generally include a processor, a storage medium readable by the processor (including volatile and non-volatile memory and/or storage elements), at least one input device, and at least one output device. One or more programs are preferably implemented in a high level procedural or object oriented programming language to communicate with a computer system. However, the program(s) can be implemented in assembly or machine language, if desired. In any case, the language may be a compiled or interpreted language, and combined with hardware implementations. [0073] The methods and apparatus of the present invention may also be embodied in the form of program code that is transmitted over some transmission medium, such as over electrical wiring or cabling, through fiber optics, or via any other form of transmission, wherein, when the program code is received and loaded into and executed by a machine, such as an EPROM, a gate array, a programmable logic device (PLD), a client computer, a video recorder or the like, the machine becomes an apparatus for practicing the invention. When implemented on a general-purpose processor, the program code combines with the processor to provide a unique apparatus that operates to perform the indexing functionality of the present invention. [0074] While the present invention has been described in connection with the preferred embodiments of the various figures, it is to be understood that other similar embodiments may be used or modifications and additions may be made to the described embodiment for performing the same function of the present invention without deviating there from. For example, while exemplary embodiments of the invention are described in the context of digital devices emulating the functionality of personal computers, one skilled in the art will recognize that the present invention is not limited to such digital devices, as described in the present application may apply to any number of existing or emerging computing devices or environments, such as a gaming console, handheld computer, portable computer, etc. whether wired or wireless, and may be applied to any number of such computing devices connected via a communications network, and interacting across the network. Furthermore, it should be emphasized that a variety of computer platforms, including handheld device operating systems and other application specific hardware/software interface systems, are herein contemplated, especially as the number of wireless networked devices continues to proliferate. Therefore, the present invention should not be limited to any single embodiment, but rather construed in breadth and scope in accordance with the appended claims.
[Remainder of Page Intentionally Left Blank]

Claims

What is Claimed:
1. A system comprising a database with an extensible type system for at least one user- defined type, wherein said at least one user-defined type comprises: information for describing the structure of said at least one user-defined type; and information for describing an inheritance relationship between itself (said at least one user-defined type) and a second user-defined type.
2. The system of claim 1 wherein said second user-defined type is a subtype of said at least one user-defined type.
3. The system of claim 1 wherein said second user-defined type is a supertype of said at least one user-defined type.
4. The system of claim 1 wherein said at least one user-defined type is defined in something other than Sequential Query Language (SQL) statement.
5. The system of claim 4 wherein said at least one user-defined type is defined by a Common Language Runtime (CLR) statement.
6. The system of claim 4 wherein said at least one user-defined type is defined by a statement in a programming language from among the following group of programming languages: C, C++, and C# ("C-sharp").
7. The system of claim 4 wherein said at least one user-defined type is defined by a visual basic statement.
8. The system of claim 1 wherein said database is aware of said inheritance relationship between said at least one user-defined type and said second user-defined type.
9. The system of claim 8 wherein said database is made aware of said inheritance relationship between said at least one user-defined type and said second user-defined type by an explicit registration of said at least one user-defined type with said database.
10. The system of claim 9 comprising: a subsystem for compiling a type into an assembly; a subsystem for registering said assembly with said database; a subsystem for registering said type of said assembly with said database; and a subsystem for using said type.
11. A method for providing, in a database, an extensible type system for at least one user- defined type, said method comprising: storing information for describing the structure of said at least one user-defined type in said at least one-user defined type; and storing information for describing an inheritance relationship between said at least one user-defined type and a second user-defined type in said at least one user-defined type.
12. The method of claim 11 further comprising creating said second user-defined type that is a subtype of said at least one user-defined type.
13. The method of claim 11 further comprising creating said at least one user-defined type that is a subtype of said second user-defined type.
14. The method of claim 11 further comprising defining said at least one user-defined type using something other than a Sequential Query Language (SQL) statement.
15. The method of claim 14 further comprising defining said at least one user-defined type using a Common Language Runtime (CLR) statement.
16. The method of claim 14 further comprising defining said at least one user-defined type using a programming language from among the following group of programming languages: C, C++, and C# ("C-sharp").
17. The method of claim 14 further comprising defining said at least one user-defined type using a visual basic statement.
18. The method of claim 11 comprising making said database aware of said inheritance relationship between said at least one user-defined type and said second user-defined type.
19. The method of claim 18 wherein making said database made aware of said inheritance relationship between said at least one user-defined type and said second user-defined type is performed by an explicit registration of said at least one user-defined type with said database.
20. The method of claim 19 comprising: compiling a type into an assembly; registering said assembly with said database; registering said type of said assembly with said database; and using said type.
21. A computer-readable medium comprising computer-readable instructions for a database with an extensible type system for at least one user-defined type, said instructions comprising instructions for: storing information describing the structure of said at least one user-defined type in said user-defined type; and storing information for describing an inheritance relationship between said at least one user-defined type and a second user-defined type in said at least one user defined type.
22. The computer-readable instructions of claim 21 further comprising instructions whereby said second user-defined type is a subtype of said at least one user-defined type.
23. The computer-readable instructions of claim 21 further comprising instructions whereby said second user-defined type is a supertype of said at least one user-defined type.
24. The computer-readable instructions of claim 21 further comprising instructions whereby said at least one user-defined type is defined in something other than Sequential Query Language (SQL) statement.
25. The computer-readable instructions of claim 24 further comprising instructions whereby said at least one user-defined type is defined by a Common Language Runtime (CLR) statement.
26. The computer-readable instructions of claim 24 further comprising instructions whereby said at least one user-defined type is defined by a statement in a programming language from among the following group of programming languages: C, C++, and C# ("C-sharp").
27. The computer-readable instructions of claim 24 further comprising instructions whereby said at least one user-defined type is defined by a visual basic statement.
28. The computer-readable instructions of claim 21 further comprising instructions whereby said database is aware of said inheritance relationship between said at least one user-defined type and said second user-defined type.
29. The computer-readable instructions of claim 28 further comprising instructions whereby said database is made aware of said inheritance relationship between said at least one user- defined type and said second user-defined type by an explicit registration of said at least one user-defined type with said database.
30. The computer-readable instructions of claim 29 further comprising instructions for: compiling a type into an assembly; registering said assembly with said database; registering said type of said assembly with said database; and using said type.
EP04779487A 2004-02-10 2004-07-29 Systems and methods for supporting inheritance for user-defined types Withdrawn EP1683046A4 (en)

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
US10/775,282 US6976029B2 (en) 2004-02-10 2004-02-10 System and method for providing user defined types in a database system
US10/837,929 US7539688B2 (en) 2004-02-10 2004-05-03 Systems and methods for supporting inheritance for user-defined types
PCT/US2004/024442 WO2005081668A2 (en) 2004-02-10 2004-07-29 Systems and methods for supporting inheritance for user-defined types

Publications (2)

Publication Number Publication Date
EP1683046A2 true EP1683046A2 (en) 2006-07-26
EP1683046A4 EP1683046A4 (en) 2009-07-08

Family

ID=34915771

Family Applications (1)

Application Number Title Priority Date Filing Date
EP04779487A Withdrawn EP1683046A4 (en) 2004-02-10 2004-07-29 Systems and methods for supporting inheritance for user-defined types

Country Status (4)

Country Link
EP (1) EP1683046A4 (en)
JP (1) JP5108309B2 (en)
KR (1) KR101440615B1 (en)
WO (1) WO2005081668A2 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8615730B2 (en) 2006-07-14 2013-12-24 Microsoft Corporation Modeled types-attributes, aliases and context-awareness
US10705802B2 (en) 2013-03-20 2020-07-07 Microsoft Technology Licensing, Llc Extensible and queryable strong types
JP6044960B2 (en) 2013-12-26 2016-12-14 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Method, apparatus and computer program for specializing serializer
WO2016175858A1 (en) * 2015-04-30 2016-11-03 Hewlett Packard Enterprise Development Lp Dynamic function invocation

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5761493A (en) * 1990-04-30 1998-06-02 Texas Instruments Incorporated Apparatus and method for adding an associative query capability to a programming language
US5864862A (en) * 1996-09-30 1999-01-26 Telefonaktiebolaget Lm Ericsson (Publ) System and method for creating reusable components in an object-oriented programming environment
US5696961A (en) * 1996-05-22 1997-12-09 Wang Laboratories, Inc. Multiple database access server for application programs
JP3747525B2 (en) * 1996-08-28 2006-02-22 株式会社日立製作所 Parallel database system search method
US6108659A (en) * 1998-12-22 2000-08-22 Computer Associates Think, Inc. Method and apparatus for executing stored code objects in a database

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
No further relevant documents disclosed *
See also references of WO2005081668A2 *

Also Published As

Publication number Publication date
EP1683046A4 (en) 2009-07-08
KR20060130480A (en) 2006-12-19
JP5108309B2 (en) 2012-12-26
WO2005081668A3 (en) 2006-05-18
KR101440615B1 (en) 2014-09-16
JP2007522558A (en) 2007-08-09
WO2005081668A2 (en) 2005-09-09

Similar Documents

Publication Publication Date Title
US7539688B2 (en) Systems and methods for supporting inheritance for user-defined types
US6941316B2 (en) System and method for object persistence in a database store
US7284010B2 (en) System and method for storing and retrieving a field of a user defined type outside of a database store in which the type is defined
US7376656B2 (en) System and method for providing user defined aggregates in a database system
EP1603057A2 (en) Systems and methods for the implementation of unordered and ordered collections in data store
EP1622046A2 (en) System and method for delayed fetching of designated members of a user defined type
JP5108309B2 (en) System and method for supporting user-defined type inheritance
KR101030368B1 (en) Systems and methods for the implementation of unordered and ordered collections in a data store
Ege et al. Using Java to add" stored procedures" to databases

Legal Events

Date Code Title Description
PUAI Public reference made under article 153(3) epc to a published international application that has entered the european phase

Free format text: ORIGINAL CODE: 0009012

17P Request for examination filed

Effective date: 20050621

AK Designated contracting states

Kind code of ref document: A2

Designated state(s): AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HU IE IT LI LU MC NL PL PT RO SE SI SK TR

AX Request for extension of the european patent

Extension state: AL HR LT LV MK

DAX Request for extension of the european patent (deleted)
A4 Supplementary search report drawn up and despatched

Effective date: 20090609

STAA Information on the status of an ep patent application or granted ep patent

Free format text: STATUS: THE APPLICATION HAS BEEN WITHDRAWN

18W Application withdrawn

Effective date: 20120926