Database Reference
In-Depth Information
result or a single XML document. The created element contains the content that cor-
responds to the content that is created as a result of the embedded SQL/XML query.
3.2 Computing the SQL Query for Generating the Compressed XML Document
After creating the XML schema based on the SQL/XML query, we have to look up
the data to create the compressed structure and the compressed text data. Therefore,
we transform the given SQL/XML query SX into an SQL query SQ that returns all
text values of the resulting XML document in document order. At the same time, we
enrich SQ such that it returns additional data that helps to assign the tuples TSQ of
SQ's result to that sub-query of SQ which TSQ corresponds to.
For example, Fig. 2 shows the SQL query derived from the SQL/XML query given
in Table 2.
(1) SELECT
(2) 1 AS QueryID,
(3) "n"."N_NAME" AS COL_1_1,
(4) "n"."N_NATIONKEY"
AS COL_1_2,
(5) null AS COL_2_1
(6) FROM "NATION" "n"
(7) WHERE "n"."N_NATIONKEY" < 5
(8) UNION ALL
(9) SELECT
(10) 2 AS Q u eryID,
(11) "n"."N_NAME" AS COL_1_1,
(12) "n"."N_NATIONKEY" AS COL_1_2,
(13) "c"."C_NAME" AS COL_2_1
(14) FROM "NATION" "n", "CUSTOMER" "c"
(15) WHERE "n"."N_NATIONKEY" < 5 AND
(16) "c"."C_NATIONKEY"="n"."N_NATIONKEY"
(17) ORDER BY COL_1_2, COL_1_1, COL_2_1
Fig. 2. SQL query derived from the SQL/XML query of Table 2
In the best case, the result of the computed SQL query SQ not only returns the text
values of the resulting XML document in document order, but it also reflects the nest-
ing of the XML elements, the text values refer to.
In order to derive this information, we compute the query given in Fig. 2 which has
the result shown in Table 3.
The query result in Table 3 is being used as follows. The first column is the query
ID to which the tuple belongs to. Query_ID 1 refers to the outer query (lines 3-16) of
the SQL/XML query shown in Table 2 and Query ID2 refers to the inner query (lines
7-14) of the SQL/XML query shown in Table 2. By splitting the results of Table 3 at
each tuple with query ID “1” and building m=4 groups of n tuples with query ID 2
where n ≥ 0, we can derive the required information on the nesting of the XML ele-
ments. The value in column COL_1_1 builds the N_NAME of each group, the value
in column COL_1_2 the N_NATIONKEY, the size n of each group is the value of
COUNT and the values in COL_2_1 build the values of the column C_NAME.
Given an SQL/XML query SX, we compute the corresponding SQL query Q as
follows:
Whenever SX does not contain embedded queries and only contains a call to the
XMLAGG function, we can simply concatenate columns that are referred to within
SX (as output columns or as columns within the ORDER BY-clause) to the SELECT-
clause of SQ. Furthermore, we can adopt the FROM- and the WHERE-clauses of SQ
from the FROM- and the WHERE-clauses of SX, and we can adopt the ORDER BY-
clause of SQ from the XMLAGG function.
Search WWH ::




Custom Search