Queries
Aquery in the 5800 system query language is translated into an equivalent query for the
underlyingdatabase that implements the query engine. The database used in a live 5800 system
isSun's High Availability Database (HADB).The database used by the 5800 system emulator is
ApacheTMDerby. Since the SQL query language used by HADB and Derby dier in substantial
ways,a subset of the query language is provided for portability between the cluster and the 5800
systememulator to enable application development in the emulator environment and
subsequentdeployment of the applications to a live 5800 system.

Translatinga Query to the Underlying Database

Thefollowing provides a summary of the translation of the 5800 system queries to SQL queries
thatare presented to the underlying database.
Themetadata schema species 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
thatmatches the format of the table layout in the schema.
Whentranslating a 5800 system query to SQL, each eld name in the query is translated into a
referenceto the particular column and particular table that represents that eld. Typed literal
valuesare translated into a form that the extended metadata cache knows how to deal with.
Specically,most literal values are replaced with an equivalent dynamic parameter. Thus, the
listof dynamic parameters that the underlying database uses combines both the dynamic
parametersand also many of the literal values from the 5800 system query. Finally, an implicit
INNERJOIN is introduced between all the tables containing the translated query elds.
Everythingelse (usually database expression syntax) is left unchanged, allowing almost all the
databaseengine's powerful query syntax to be used with 5800 system queries.
Thepresence of the INNER JOIN has important consequences when queries are evaluated. An
objectis 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
eldAand eldB are non-null, because of this implicit inner join.

AttributeFormat in Queries

Anystring in double quotes (for example, "lename") and any dotted string in Java Identier
format(for example, mp3.title) will automatically be treated as an attribute name. The double
quotescan optionally be omitted even on a non-dotted name as long as the attribute does not
matchan SQL reserved word in any of the Sun StorageTek 5800 underlying metadata databases.
Attributenames must appear in the current 5800 system schema to be used in a query. This is
becausethe proper type information about each attribute must be derived to build the query.
Queries
Chapter4 • Sun StorageTek 5800 System Query Language 117