UDFs and Database Extenders
Download
Report
Transcript UDFs and Database Extenders
CS240A
OR DBMS and
DB Extenders
Carlo Zaniolo
Department of Computer Science
University of California, Los Angeles
OR DBMS: New Features
①
O-O constructs: Type Hierarchies and Path Joins
②
External Functions (User Defined Functions---UDFs)
Scalar
Table
Functions and BLOBS
Functions
Aggregate
UDFs (not supported in DB2)
Application
specific function libraries: a.k.a. Extenders,Data
Blades, Cartridges, Snapins.
2
O-O constructs: Type Hierarchies
3
O-O constructs: Joins by Path Expressions
Path expressions greatly simplies queries that select attributes from a set of related objects by
permitting relationships to be explicitly traversed using the dereference operator -->. For
example, to find the employee name and salary, as well as the corresponding department name
and budget, forall employees who work in departments that have budgets that exceed $150,000
per person, we could simply write:
References:
Michael J. Carey et al: O-O, What Have They Done to DB2 ?, VLDB 1999, pp. 542-553.
C. Zaniolo: The database language GEM. In Pro-ceedings SIGMOD 1983, pages 207--218, 1983.
S. Tsur and C. Zaniolo: An implementation of GEM---supporting a semantic data model on a relational back-end. SIGMOD 1984, pages 286--295.
4
ObjectRelational DBMSs:
Extensibility in SQL1999
Large Objects: BLOBs CLOBs. Also locators to large
objects
External Functions (User Defined Functions---UDFs):
Defined
in C++ or JAVA and linked into DB2. OLEs
also supported.
The
linchpin of database extenders
5
UDFs in DB2
UDFs can be called from SQL, which passes them arguments
(e.g., a blob) and and expect a single value back.
UDFs cannot directly access the DB
Scalar functions (no memory), scratchpad functions (memory),
table functions (return set of tuples).
No aggregate functions (in DB2)
FENCED, or NOT FENCED (fast and dangerous)
UDFs are Hard to Write and Debug
Impedance mismatch ... many qualifiers: DETERMINISTIC,
DBINFO, EXTERNAL ACTION, SCRATCHPAD
6
Table Functions—DB2
CREATE FUNCTION GET_EMPS()
RETURNS TABLE( EMPNO CHAR(6), SALARY CURRENCY, BONUS
CURRENCY, COMM CURRENCY)
LANGUAGE SQL READS SQL DATA
RETURN
(SELECT EMPNO, SALARY, BONUS, COMM FROM EMPS
WHERE
(SALARY+BONUS+COMM) >
CURRENCY((SELECT MAX(SALARY) FROM EMPS))
);
SELECT …. FROM TABLE(table_function(a1,…)) AS <name>
Table functions can also be defined in a C or Java (e.g., to access
external files and join them with DB2 tables).
7
A Growing List---for DB2
Other vendors have many more
DB2 Image Extender
DB2 Audio Extender
DB2 Video Extender
DB2 Text Extender
DB2 Spatial Extender
DB2 Video Charger Ext.
EcoWin Time Series
MapInfo SpatialWare TI
Extender
Fillmore SQL Expander
XML Extender
IBM Net Search Ext.
IBM Net Search Ext.
Prime DES Encryption and
Key Management
OANDA Currency Ext.
Protegrity Secure.Data
8
Basics: e.g. Audio Extenders
Import and export audio clips and their attributes into and out of a database. When
you import an audio clip, the DB2 Audio Extender stores and maintains audio
attributes such as number of audio channels, transfer time, and sampling rate.
Secure and recover audio data. Audio clips and their attributes that you store in a
DB2 database are afforded the same security and recovery protection as traditional
data. Also access control.
Query audio clips based on related business data or by audio attributes. You can
search for audio clips based on data that you maintain, such as a name, number, or
description; or by data that the DB2 Audio Extender maintains, such as the format of
the audio or the date and time that it was last updated.
Play audio clips. You can use the DB2 Audio Extender to retrieve an audio clip. You
can then use the DB2 Audio Extender to invoke your favorite audio browser to play
the audio clip. The DB2 Audio Extender supports a variety of audio file formats, such
as WAVE and MIDI, and can work with different file-based audio servers.
9
Extenders’ Architecture
The DB2 Audio Extender defines a new data type and
functions for audio
using DB2 Universal Database's built-in support for userdefined types and user-defined functions
It also exploits DB2 UDB's support for large objects of up to 2
gigabytes, and
uses DB2 triggers to provide integrity checking across
database tables ensuring the referential integrity of audio data.
10
Image Extender
Import and export: DB2 Image Extender stores and
maintains image attributes such as size in bytes,
format, height, width, and number of colors.
Convert the format of images: scale an image, rotate it,
do black-white image inversion, compression
Query images by user attributes, DB2-generated
attributes or QBIC: QBIC lets you use visual examples
of colors or texture patterns as search criteria
11
DB2 Video Extender
Automatic Scene Change Detection
Video Storyboards
12
Text Extender
DB2 Text Extender offers a rich set of text search features that
allow for more complex and precise queries as well as an
improved recall---patent research, legal docs
Dictionary-based linguistic support for many languages such as
Arabic, Brazil, Canadian French, Catalan, Danish, Dutch, English
(US and UK), Finnish, French, German, Hebrew, Icelandic,
Italian, Norwegian, Portugese, Russian, Spanish, Swedish, Swiss
German and Thai.
DB2 Net Search Extender contains a DB2 stored procedure that
adds the power of fast full-text retrieval
13
DB2 Spatial Extender
DB2 Spatial Extender allows you to gather spatial data
and attach non-spatial business data attributes to it.
With the Spatial Extender, your business data and
spatial data are now integrated, making the task of
creating a GIS as straightforward as creating any other
information system.
More integrated than standard extenders
14
XML Extenders
Extracts XML elements and attributes into traditional SQL data
types, leveraging DB2s sophisticated indexing and SQL query
Provides storage, retrieval, and updates of XML documents in a
single column
Composes existing DB2 data into XML documents
Stores XML documents as a collection of DB2 data, in multiple
columns and tables
Manages your DTD repository
Integrates the powerful search functions of Text Extender for
searching one or more sections within a set of XML documents
15
XML
An Extender
Or the blueprints for future evolution of
database systems ?
16