Database Reference
In-Depth Information
for
RA
query q , we can define Meta ( q ) recursively:
l
-f q
. This may seem incorrect, but we
want to gather only attributes that are truly used in q , hence the real work is
done in other clauses.
-f q
¼
R , for any relation R , Meta
ð
q
Þ¼;
Meta ( E ), where
Att ( c ) is the set of all attribute names used in condition c (note that we assume
sets, that is, duplicates are removed).
-f q
¼ s c ( E ), for any
RA
expression E , Meta ( q )
¼
Att ( c )
[
¼ p L ( E ), for any
RA
expression E and attribute list L , Meta ( q )
¼
L (note
that, for q to be a correct expression, L
sch ( E )).
-f q is one of E 1 ./ c E 2 , E 1 [
E 2 , E 1
E 2 ,or E 1 \
E 2 , for any
RA
expressions
E 1 and E 2 , Meta ( q )
¼
Meta ( E 1 )
[
Meta ( E 2 ) (again, we assume that duplicates
are removed).
-f q
GB L , F ( L 0 ) ( E ), where GB represents the group by operator, L and L 0 are
subsets of sch ( E ) and F is a list of aggregate functions, Meta ( q )
¼
L 0 [
¼
L
[
Meta ( E ).
If q is an SQL query, the set Meta
ð
q
Þ
can be obtained either by translating
q to
(note that most query processors do this in order to execute the
query), or directly from SQL by gathering all attribute names used in the
SELECT clause (including any attributes used with aggregates), and in
the conditions in the WHERE clause, as well as the attributes in the
GROUP BY and HAVING clause if they are present, 5 plus recursively adding
any attributes names in any subquery in q , be it in the SELECT, FROM, or
WHERE clauses. It is important to note that Meta
RA
is a superset of the
schema of q ( D ), the table produced as an answer to q in D , and it includes all
attributes involved in formulating q . This is done to help users understand the
semantics of the query.
ð
q
Þ
for write statement w ,if w is an insertion into table R , a deletion from table R ,or
a modification of some tuples in table R , then Meta ( w )
l
sch ( R ). 6
¼
The key point is that there is a unique set of metadata attached to each query or
write statement. Hence, once Meta ( q )or Meta ( w ) is computed, we can extract the
corresponding set of rowids from the Catalog tables, and use the procedure above
(outerjoin) to add any user annotation to the metadata of the command. For a query
q , this means adding to the top row of q ( D ) (where the schema is usually displayed)
any user-created content found. Note that we include content related to attributes in
the WHERE clause, which may not be part of the schema of the answer table. Such
content could be displayed also at the top of the answer, previous to the data. Again,
how to best display this information is considered a matter of user interface, and not
dealt with here.
5
Note that the SQL standard allows for some attributes to appear in the GROUP BY clause and not
in the SELECT clause, so this check is necessary.
6 While an update statement may involve more than one table, the typical usage of SQL is to make
changes in one table at a time.
Search WWH ::




Custom Search