Table 2: Sample data for the Bonuses table
Bonus Name Bonus Formula ((NUMBER, NUMBER)−→NUMBER) Description
Bonus for the CEO (DummyArgument0, DummyArgument1) −→ 2,000,000 The year-end bonus for the CEO is $2,000,000.
Bonus for managers (BaseSalary, Performance) −→ BaseSalary × (0.10 + (CASE WHEN Per-
formance ≥ -0.05 THEN Performance ELSE 0 END))
The year-end bonus for a manager is determined by a function of
their Performance.
Bonus for Sales personnel (DummyArgument0, Commission) −→ Commission The year-end bonus for Sales personnel is a lump sum commission
Bonus for Production person-
nel
(BaseSalary, Performance) −→ BaseSalary × (0.02 + (CASE WHEN Per-
formance ≥ -0.005 THEN Performance ELSE 0 END))
The year-end bonus for Production personnel is determined by a
function of their Performance.
Bonus for R&D personnel (DummyArgument0, NumberOfProjectsCompleted) −→ 1000 × Num-
berOfProjectsCompleted
The year-end bonus for R&D personnel is determined by a function
of the number of completed research projects.
Bonus for HR personnel (DummyArgument0, DummyArgument1) −→ 500 The year-end bonus for a HR personnel is $500.
Personal Achievement Bonus (DummyArgument0, DummyArgument1) −→ 1000 The personal achievement bonus is $1,000.
called eval. The overriding child implementations of
this method can be dynamically dispatched and used
for table-driven programming.
Using ORDBMS’s dynamic method dispatch is a
natural solution to implement table-driven program-
ming in SQL. However, object types were not de-
signed specifically for table-driven programming and
thus there are some limitations with this approach:
• Object type is quite heavy. Object types are cre-
ated and maintained in data definition language
(DDL) and stored in system catalog. A table-driven
application may possess thousands or even millions
of items of business logic. Creating millions of ob-
ject types to wrap this business logic can create a
great burden on the database system catalog.
• Code wrapped in objects is still not data. Be-
cause code wrapped in methods are attached to ob-
jects, they are not data (Gray et al., 2003) in the
sense that they cannot be accessed or manipulated
like ordinary data.
• Dynamic dispatch process is complex. To dy-
namically look for a pertinent method in an ob-
ject type hierarchy, an ORDBMS execution engine
would search either from the root object (DB2’s
approach) or from leaf objects (ORACLE’s ap-
proach). Either way is quite complex.
5 RELATED WORK
The idea of storing functional expressions (not func-
tions) as data values has been proposed before. Stone-
braker’s “Quel as a Data Type” (Stonebraker et al.,
1984; Stonebraker et al., 1987) treated QUEL queries,
statements and commands as a specialized kind of
string. A stored query could be used to represent a
set of records. The paper appeared just as the object-
oriented database movement started to gain momen-
tum, and perhaps for this reason failed to be imple-
mented in commercial systems.
The work of SQL Spreadsheets (Witkowski et al.,
2003) introduces spreadsheet-like computations into
RDBMS through SQL extensions. It provides an
efficient alternative to simplify complicated OLAP
queries that otherwise are implemented in nested
views, subqueries, and complex joins. However
spreadsheet formulas are statically embedded in new
SQL clauses, making it difficult to handle either dy-
namically changing formulas or a large number of
business formulas.
6 CONCLUSIONS
In this paper, we discuss the idea of applying the
table-driven programming methodology in SQL for
enterprise database applications. The main goal is to
integrate data and functions within a RDBMS in a re-
lational manner. Using an existing ORDBMS, devel-
opers can use a flat object type hierarchy with poly-
morphic methods embedded in child types to emulate
this table-driven design. However, code wrapped in
an object is still not data and heavy – management of
object methods relies on DDL statements, instead of
DML. To avoid ORDBMS limitations, we currently
work on putting lightweight functions in RDBMS to
allow direct table-driven programming in SQL.
REFERENCES
Gray, J. et al. (2003). The Lowell Report. In Halevy, A. Y.,
Ives, Z. G., and Doan, A., editors, SIGMOD 2003,
page 680. ACM.
IBM et al. (2002). IBM DB2 Universal Database SQL Ref-
erence Volume 1 Version 8. IBM.
ORACLE et al. (2003). Oracle Database Application De-
veloper’s Guide - Object-Relational Features 10g Re-
lease 1 (10.1). Oracle.
Stonebraker, M., Anderson, E., Hanson, E. N., and Ruben-
stein, W. B. (1984). Quel as a Data Type. In Yor-
mark, B., editor, SIGMOD 1984, pages 208–214.
ACM Press.
Stonebraker, M., Anton, J., and Hanson, E. N. (1987). Ex-
tending a Database System with Procedures. TODS,
12(3):350–376.
Witkowski, A. et al. (2003). Spreadsheets in RDBMS for
OLAP. In Halevy, A. Y., Ives, Z. G., and Doan, A.,
editors, SIGMOD 2003, pages 52–63. ACM.
TABLE-DRIVEN PROGRAMMING IN SQL FOR ENTERPRISE INFORMATION SYSTEMS
427