The SQL Standard (ISO/IEC 9075) S J Cannan Technical Manager S J Cannan Technical Manager Where it...

Post on 29-Dec-2015

218 views 3 download

transcript

The SQL Standard (ISO/IEC 9075)

S J Cannan

Technical Manager

S J Cannan

Technical Manager

Where it isandwhere it is going

The SQL Standard (ISO/IEC 9075)

Goal: Portability of SQL applications

Effect: Increase and stabilisation of the database market

Mechanism: Joint efforts between implementers and users

Joint effort among several countries

Past History

1987 SQL1989 SQL + Integrity Enhancement1992 SQL (2)1995 SQL/CLI1996 SQL/PSM1999 SQL (3)2000 SQL/OLB2000 SQL/OLAP2000 SQL/MED

1987 SQL1989 SQL + Integrity Enhancement1992 SQL (2)1995 SQL/CLI1996 SQL/PSM1999 SQL (3)2000 SQL/OLB2000 SQL/OLAP2000 SQL/MED

The SQL Standard (ISO/IEC 9075)

Current Structure

ISO/IEC 9075-1 Framework

ISO/IEC 9075-2 Foundation

ISO/IEC 9075-3 Call-level interface

ISO/IEC 9075-4 Persistent Stored Modules

ISO/IEC 9075-5 Language Bindings

ISO/IEC 9075-9 Management of External Data

ISO/IEC 9075-10 Object Language Bindings

ISO/IEC 9075:Amd1 SQL/OLAP

The SQL Standard (ISO/IEC 9075)

WorkingDraft

Proposals

FinalCommittee

Draft

CommitteeDraft

Comments

InternationalStandard

Comm

ents

Yes/NoDraft

InternationalStandard

TechnicalCorrigenda

Proposals

NWI

The SQL Standard (ISO/IEC 9075)

The Standardisation Process

ISO/IEC 9075-1:Framework (SQL/Framework)

Description of Parts

Terminology

Basic Concepts

Basic Conformance Clause

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Foundation (SQL/Foundation)

Data Definition

Data Manipulation

Data Access Control

Transaction Management

Information Schema

Miscellaneous

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: MOOSE

Large Objects

Arrays

User-defined types

Subtypes and inheritance

Encapsulation

Substitutability

Transforms

Large Objects

Arrays

User-defined types

Subtypes and inheritance

Encapsulation

Substitutability

Transforms

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Data Access

Data Manipulation Statements

INSERT

UPDATE

DELETE

SELECT

The SQL Standard (ISO/IEC 9075)

Comparison (=, <, >, <=, >=, <>)value BETWEEN [A]SYMMETRIC value2 AND value3value IN subquery or (value-list)value [NOT] LIKE pattern [ESCAPE char]row-value IS [NOT] NULLrow-value comp-op ALL|[SOME|ANY] subqueryEXISTS subqueryUNIQUE subqueryrow-value MATCH [UNIQUE]

[SIMPLE|PARTIAL|FULL] subqueryrow-value1 OVERLAPS row-value2value [NOT] SIMILAR TO pattern [ESCAPE char]row-value1 IS DISTINCT FROM row-value2value IS [NOT] OF ( type-list )

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2:Predicates

SensitivityASENSITIVESENSITIVEINSENSITIVE

implies READ ONLY

Holdable

ORDER BYcolumns not in select listexpressions

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Cursors

WITH New_Price AS (SELECT Source, Destination, Carrier, Cost * discount_rate AS New_CostFROM Flights f join Discounts d on d.carrier=f.carrier ) SELECT a.Source, a.Destination, a.Carrier, a.New_Cost, b.Carrier, b.New_CostFROM New_Price a, New_Price bWHERE (a.Source, a.Destination) =(b.Source, b.Destination) AND a.Carrier <> b.Carrier AND a.NewCost >= b.New_Cost

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Common Table Expressions

• Fixpoint theory• Unique solutions

• Transformation on the right hand side of a recursive definition must be monotonically increasingDisallow:

• negation that crosses recursion• aggregation that crosses recursion• INTERSECT ALL• EXCEPT ALL• EXCEPT DISTINCT (on right hand side)• FULL OUTER JOIN (LEFT|RIGHT with

recursion on right|left)The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Recursion

ISO/IEC 9075-2: Recursion

WITH RECURSIVE Even (N) AS ( VALUES (0) UNION SELECT M + 1 FROM Odd ) Odd (M) AS ( SELECT N + 1 FROM Even )SELECT * FROM Even WHERE N < 12;

Mutual Recursion

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Recursion

SELECT CASE WHEN abbreviation = ‘CA’ THEN ‘California’ WHEN abbreviation = ‘SD’ THEN ‘South Dakota’ WHEN ... ELSE ‘Unknown’END FROM statesWHERE ...

SELECT emp_name, deptno FROM employeeWHERE ( CASE bonus + commission WHEN 0 THEN NULL ELSE salary/(bonus+commission) ) > 10

Used to “implement” COALESCESELECT COALESCE (nickname, first_name, surname, ‘Unknown’) FROM people

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: F261 Case expression

Enhances query capabilities

CUBE

ROLLUP

GROUPING SETS

Expressions in ORDER BY

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: OLAP

Find the total sales per region and sales manager during each month of 1996, with subtotals for each month, and concluding with the grand total:

SELECT month, region, sales_mgr, SUM (price) FROM Sales WHERE year = 1996 GROUP BY ROLLUP (month, region, sales_mgr);

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: OLAP

MONTH REGION SALES_MGR SUM(price)April Central Chow 25000April Central Smith 15000April Central - 40000April NorthWest Smith 15000April NorthWest - 15000April - - 55000May Central Chow 25000May Central - 25000May NorthWest Smith 15000May NorthWest - 15000May - - 40000- - - 95000

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: OLAP

Find the total sales per region and sales manager during each month of 1996, with subtotals for each month, region and sales manager and concluding with the grand total:

SELECT month, region, sales_mgr, SUM(price) FROM Sales WHERE year = 1996 GROUP BY CUBE (month, region, sales_mgr);

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: OLAP

The SQL Standard (ISO/IEC 9075)

MONTH REGION SALES_MGR SUM(price)April Central Chow 25000April Central Smith 15000April Central - 40000April NorthWest Smith 15000April NorthWest - 15000April - Chow 25000April - Smith 30000April - - 55000May Central Chow 25000May Central - 25000May NorthWest Smith 15000May NorthWest - 15000May - Chow 25000May - Smith 15000May - - 40000- Central Chow 50000- Central Smith 15000- Central - 65000- NorthWest Smith 30000- NorthWest - 30000- - Chow 50000- - Smith 45000- - - 95000

ISO/IEC 9075-2: OLAP

ISO/IEC 9075-2: Data Protection

PrivilegesGRANT, REVOKESELECT, UPDATE, DELETE, INSERT,

REFERENCE, UNDER, TRIGGER, USAGE

RolesCREATE, GRANT, REVOKE, DROP

The SQL Standard (ISO/IEC 9075)

Enhanced security mechanisms

Simplifies definition of complex sets of privileges

CREATE/DROP role

GRANT/REVOKE privileges to roles

GRANT/REVOKE roles to users and other roles

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Roles

ISO/IEC 9075-2: Data Description

The Information Schema

short name views

The Definition Schema

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-2: Miscellaneous

Transaction Statements

Connection Statements

Diagnostic Statements

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-3: Call Level Interface (SQL/CLI)

“SQL for Shrink-wrapped software”

Resource control

SQL connection control

Execution of SQL statements

Diagnostics

SQL implementation information

The SQL Standard (ISO/IEC 9075)

Application

CLI Driver

Database Management System

Server

Client

Call

Return

Call

Return

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-3: Call Level Interface (SQL/CLI)

Flow of control

Assignments

Condition handlers

Signal and Resignal conditions

SQL path specification

Declarations

ISO/IEC 9075-4: Persistent Stored Modules (SQL/PSM)

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-5: Host Language Bindings (SQL/Bindings)

Embedded SQL Static SQL Dynamic SQL

Support for: Ada, C, COBOL,

FORTRAN, MUMPS, Pascal, PL/I

Direct SQL

The SQL Standard (ISO/IEC 9075)

Embedded SQL

SQL ModuleStandard

Programming Language

Precompiler

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-5: Host Language Bindings (SQL/Bindings)

ISO/IEC 9075:Conformance

• Core

• Features

• Packages

The SQL Standard (ISO/IEC 9075)

• All of SQL:1992 Entry level• Some Transitional SQL:1992 features• Some Intermediate SQL:1992 features• Some Full SQL:1992 features• The following new features of SQL:1999

• Distinct data types• WITH HOLD cursors• SQL-invoked routines (no PATHs)

• CALL statement • RETURN statement• ROUTINES and PARAMETERS view• SQL-invoked routines written in SQL and an external

language • Value expression in order by clause

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075: Conformance

PKG001 Enhanced datetime facilitiesPKG002 Enhanced integrity managementPKG003 OLAP facilitiesPKG004 PSMPKG005 CLIPKG006 Basic object supportPKG007 Enhanced object supportPKG008 Active databasePKG009 SQL/MM support

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075: Conformance

Packages

ISO/IEC 9075-9: SQL/Management of External Data

Datalink data type

Foreign tables

Foreign servers

Foreign data wrappers

User mappings

The SQL Standard (ISO/IEC 9075)

Simple embedding of static SQL statements in Java programs

Permit assembly of binary components produced by different tools

Binary portabilityHardwareOperating SystemsDatabase Systems

Co-exist with JDBCThe SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-10:Object Language Bindings (SQL/OLB)

Objectives

ISO/IEC 9075-10:Object Language Bindings (SQL/OLB)

Based on JSQL

Extends Java to include SQL constructs as statements and expressions

A JSQL translator that transforms those JSQL clauses into standard Java code that accesses the database through a call interface

An alternative to JDBC (JavaSoft)

Static instead of Dynamic

Tighter integration

The SQL Standard (ISO/IEC 9075)

Simple

Static

compile time syntax and type checking

Strongly typed cursors

iterators

Pre-compilation

Permits vendor customisation

at deployment

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-10:Object Language Bindings (SQL/OLB)

Advantages

ISO/IEC 9075-10:Object Language Bindings (SQL/OLB)

SQLJprogram

SQLChecker

Java Frontend

SQLJ Translator

Java Class Files

SQLJ Profiles

SQLJ JAR FILE

Profile Customizer

Utility

SQLJ Customizations

SQLJ translator framework

ISO/IEC 9075Amd1:SQL/OLAP

• ROLLUP

• CUBE

• Unary grouped table aggregate functions• Binary grouped table aggregate functions• Inverse distribution functions• What-if functions• Numeric Functions

• WindowsThe SQL Standard (ISO/IEC 9075)

WindowsCumulative sum and centred average:

SELECT SH.Territory, SH.Month, SH.Sales,SUM (SH.Sales) OVER Wa AS Cumulative_sum,AVG (SH.Sales) OVER Wb AS Centred_averageFROM Sales_history AS SHWINDOW WRoot AS ( PARTITION BY SH.Territory ORDER BY SH.Month ASC ), Wa AS ( W12root ROWS UNBOUNDED PRECEDING ), Wb AS ( W12root ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING);The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075Amd1:SQL/OLAP

SQL 4

The SQL Standard (ISO/IEC 9075)

?Revised SQL 3

+

SQL/JRTJava in Database Procedures

Java Data types in SQL

SQL/XML

SQL/Replication

SQL/Temporal

Direct use of existing Java libraries

Any Java static method callable as a stored procedure

Portable across DBMS’s

Deployable across tiers

Implementation transparent for user

Equivalent functionality

Body of SQLJ stored procedure routines can use JDBC and/or SQLJ to access SQL, or Java computation

ISO/IEC 9075:SQL/JRT

The SQL Standard (ISO/IEC 9075)

– Use Java classes as SQL data types for:• Columns of SQL tables and views.• Parameters of SQL routines.

– Advantage to SQL:• A type extension mechanism.• A supplement to SQL:1999 ADTs.

– Advantage to Java:• Direct support for Java objects in SQL databases.• No need to map Java objects to SQL scalar or

BLOB types.

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075:SQL/JRT

– Specifications for the representation of SQL data (specifically rows and tables of rows, as well as views and query results) in XML form, and vice versa.

– Specifications associated with mapping SQL schemata to and from XML schemata. This may include performing the mapping between existing arbitrary XML and SQL schemata.

– Specifications for the representation of SQL Schemas in XML.

– Specifications for the representation of SQL actions (insert, update, delete).

– Specifications for messaging for XML when used with SQL.

– Specifications of the (perhaps “a”) manner in which SQL language can be used with XML.

The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075:SQL/XML

Scope

SQL/Replication

1-TierC/S

N-TierC/S

MobileDevices

Head-OfficeServers

Web &Thin-Client

Relational Transport Layer

no new relational concepts; business-rule driven

every site a peer; update-anywhere

every site autonomous, all transactions local; no point of failure

automatic, transparent; just add a database wherever needed

all a user’s favourite tools: Java/VB/HTML/X/C++/Perl/Delphi/…, 1-tier/N-tier/Web/Windows/Unix…; OLTP/OLAP/DSS/…

An “Ideal” DistributedSystem

The SQL Standard (ISO/IEC 9075)

SQL/Replication

The SQL Standard (ISO/IEC 9075)

good (if ‘local and one server’

is enough)

immediate

one site

one site

one site

Performance

DataCurrency

Autonomy/Availability

Points ofFailure

Scalability

poor for updates

immediate

poor

many

< 20 sites

local

parallelisedpropagation

full, local

any subset live(repl. clustering,

failover)

1000+(auto detection,

auto config,dyn. load bal.)

local

propagated

full, local (if update-anywhere)

one or many(for repl.)

< 100 sites(hub/spoke)

CentralServer

Traditional Synchronous:

N-PhaseCommit

Queue-BasedAsynchronous

Replication

IdealAsynchronous

Replication

Approaches

LocalDatabase

Size

10% changeper month

4:1 compression

RequiredBandwidth for

Trickle Replication

(Office Hours)

1 GBWorkgroup

Server1.1M / day

28.8Kmodem

50 MBMobileLaptop

60K / dayCell, 28.8K

modem

1 TBHeadquarters /

Warehouse1G / day 256K ISDN

RegionalServer

20 GB 23M / day56K

modem

Rate of Change

The SQL Standard (ISO/IEC 9075)

SQL/Replication

SQL/Replication

SingleSystemImage

DecreasinglyConsistent

Image

single server, or 2PC

single “master” for all changes

“multi-master,” update-anywhere

hub-and-spoke

log replaynet change

parallelised

IncreasingPropagation

Time

conflic

tsco

nflic

t avoid

ance

The SQL Standard (ISO/IEC 9075)

One Valid Time Line

Transaction Time Line

Upwards compatible

Structural constraints

Simple Syntax

No interest according to database vendors

Religious wars in standards body The SQL Standard (ISO/IEC 9075)

ISO/IEC 9075-7: Temporal (SQL/Temporal)

SQL/MM

Multimedia & Application PackagesBased on the facilities of SQL:1999A multi-part standard

Multimedia & Application PackagesBased on the facilities of SQL:1999A multi-part standard

Full TextSpatialStill ImageStill GraphicsAnimationFull Motion VideoSeismicMusic

Data Mining

end…