Queries
A query in the 5800 system query language is translated into an equivalent query for the
underlying database that implements the query engine. The database used in a live 5800 system
is Sun's High Availability Database (HADB). The database used by the 5800 system emulator is
Apache
TM
Derby. Since the SQL query language used by HADB and Derby dier in substantial
ways, a subset of the query language is provided for portability between the cluster and the 5800
system emulator to enable application development in the emulator environment and
subsequent deployment of the applications to a live 5800 system.
Translating a Query to the Underlying Database
The following provides a summary of the translation of the 5800 system queries to SQL queries
that are presented to the underlying database.
The metadata schema species the layout of elds into tables and columns. When the schema is
committed, a particular set of actual tables and columns is created in the underlying database
that matches the format of the table layout in the schema.
When translating a 5800 system query to SQL, each eld name in the query is translated into a
reference to the particular column and particular table that represents that eld. Typed literal
values are translated into a form that the extended metadata cache knows how to deal with.
Specically, most literal values are replaced with an equivalent dynamic parameter. Thus, the
list of dynamic parameters that the underlying database uses combines both the dynamic
parameters and also many of the literal values from the 5800 system query. Finally, an implicit
INNER JOIN is introduced between all the tables containing the translated query elds.
Everything else (usually database expression syntax) is left unchanged, allowing almost all the
database engine's powerful query syntax to be used with 5800 system queries.
The presence of the INNER JOIN has important consequences when queries are evaluated. An
object is only returned by a query when all of the elds referenced by the query itself and all of
the elds referenced in the select list of the query all have non-null values. Queries with OR
clauses, in particular, can produce non-intuitive results. As an extreme example, consider a
query: "eldA is not null OR eldB is not null." This query will not select an object unless both
eldA and eldB are non-null, because of this implicit inner join.
Attribute Format in Queries
Any string in double quotes (for example, "lename") and any dotted string in Java Identier
format (for example, mp3.title) will automatically be treated as an attribute name. The double
quotes can optionally be omitted even on a non-dotted name as long as the attribute does not
match an SQL reserved word in any of the Sun StorageTek 5800 underlying metadata databases.
Attribute names must appear in the current 5800 system schema to be used in a query. This is
because the proper type information about each attribute must be derived to build the query.
Queries
Chapter4 • SunStorageTek 5800SystemQuery Language 117