<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Schema-based Query Optimization for XQuery Queries</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Sven Groppe</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Stefan Böttcher</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Paderborn, Faculty 5</institution>
          ,
          <addr-line>Fürstenallee 11, D-33102 Paderborn</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <fpage>80</fpage>
      <lpage>95</lpage>
      <abstract>
        <p>XQuery is widely used for querying XML documents. Within this paper, we examine optimization rules for XQuery queries that exploit type information of the input XML document given in XML Schema. These optimization rules are applicable for all XQuery expressions and are very useful e.g. in the scenario of XQuery queries on XQuery views. The basic idea is to transform the XML Schema definition into a graph, which is extended to a graph representing the XQuery expression. The latter graph is used to delete subexpressions of the XQuery expression that are not used to retrieve the final result of the given XQuery expression. We further include experimental results that demonstrate the improvement of our optimization.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>
        The W3C has developed XQuery [
        <xref ref-type="bibr" rid="ref25">25</xref>
        ] for querying XML documents in recent years.
XQuery evaluators have not only been implemented for single XML documents, but
XQuery has also been integrated in many XML databases and XML-enabled
databases. However, query optimization for XQuery is still a major challenge.
      </p>
      <p>In this paper, we introduce a new optimization technique for the following class of
XQuery expressions. We call the class of XQuery expressions CXQuery, which consist
of all XQuery expressions, which contain at least one sub-expression, which
generates either no output at all or an intermediate result, which is not used to compute the
final result of the query. Our optimization technique identifies and eliminates those
sub-expressions of queries of CXQuery which do not generate any output or generate
superfluous intermediate results.</p>
      <p>Even if queries are well designed, queries of CXQuery often occur in the following
important scenario of queries on views. A view describes how a certain section of the
stored data in the database is transformed. Now, a user can query the view to retrieve
all or a subset of the transformed data of the view. Inside database management
systems, the query on the view and the view itself are composed and then evaluated as
one composed query. Whenever the user restricts the view by the query and does not
query for all the data of the view, the composed query can in general belong to the
class CXQuery. In these cases, applying our new optimization technique saves time of
processing the composed query. We show by experimental results that the execution
of the optimized query is much faster than computing the complete query, whenever
the size of all data is relatively large and we can avoid unnecessary computation of
unneeded intermediate results.</p>
      <p>The rest of the paper is organized as follows. Section 2 outlines an optimization
example. Section 3 describes our general approach for optimizing XQuery queries.
Section 4 presents a performance analysis. Section 5 refers to the related work, and
we end up with the summary and conclusions in Section 6.</p>
    </sec>
    <sec id="sec-2">
      <title>2 Optimization Example</title>
      <p>In order to illustrate our optimization, we start with an example. Let us consider the
following XQuery query in Fig. 1, which is composed of a view definition in line (1)
to line (19) and of a user defined query on this view in line (21). The XQuery query
in Fig. 1 shall be applied to the input XML document of Fig. 2 that fulfills the XML
schema definition of Fig. 3.
&lt;xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;
&lt;xsd:element name='conference'&gt;
&lt;xsd:complexType&gt;
&lt;xsd:choice minOccurs=1 maxOccurs='unbounded'&gt;
&lt;xsd:element name='tutorial'&gt;
&lt;xsd:complexType&gt;
&lt;xsd:element ref='author' minOccurs=0 maxOccurs='unbounded'/&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:attributeGroup ref='name'/&gt;
&lt;/xsd:element&gt;
&lt;xsd:element name='paper'&gt;
&lt;xsd:complexType&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element ref='author' minOccurs=0 maxOccurs="unbounded"/&gt;
&lt;xsd:element name='references' minOccurs=0 maxOccurs=1&gt;
&lt;xsd:complexType&gt;
&lt;xsd:element ref='conference' minOccurs=0
maxOccurs='unbounded'/&gt;
&lt;/xsd:complexType&gt;
&lt;/xsd:element&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:attributeGroup ref='name'/&gt;
&lt;/xsd:element&gt;
&lt;/xsd:choice&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:attributeGroup ref='name'/&gt;
&lt;/xsd:element&gt;
&lt;xsd:element name='author'&gt;
&lt;complexType mixed='true'/&gt;
&lt;/xsd:element&gt;
&lt;xsd:attributeGroup name='name'&gt;
&lt;xsd:attribute name='name' use='required'/&gt;
&lt;/xsd:attributeGroup&gt;
&lt;/xsd:schema&gt;</p>
      <p>When the XQuery query in Fig. 1 is evaluated on the XML document 'p.xml'
outlined in Fig. 2 and its XML Schema definition outlined in Fig. 3, at first the
variable $view is computed. Its content is presented in Fig. 4.</p>
      <p>&lt;root&gt;
&lt;result&gt;
&lt;single_result&gt;
&lt;tutorial name="Web Services"&gt;</p>
      <p>&lt;author&gt;Expert&lt;/author&gt;
&lt;/tutorial&gt;
&lt;/single_result&gt;
&lt;single_result&gt;
&lt;paper
name="Solving unsolved problems"&gt;
&lt;author&gt;Problem Solver&lt;/author&gt;
&lt;author&gt;Problem Searcher&lt;/author&gt;
&lt;/paper&gt;
&lt;/single_result&gt;
&lt;/result&gt;
&lt;/root&gt;</p>
      <p>Thereafter, the result of the entire query of Fig. 1 is computed, the result of which
is presented in Fig. 5.
&lt;tutorial name="Web Services"&gt;</p>
      <p>&lt;author&gt;Expert&lt;/author&gt;
&lt;/tutorial&gt;</p>
      <p>
        Note that the result in Fig. 5 is only a part of the fragment computed by the
variable $view. Although XQuery evaluators process the complete query in Fig. 1, and
therefore can optimize the complete query, current implementations ([
        <xref ref-type="bibr" rid="ref15 ref18 ref22">6, 15, 18, 22</xref>
        ])
always compute the entire content of the variable $view either at once or one XML
node after the next XML node by using an iterator. After that, current
implementations project to the required part of $view.
      </p>
      <p>In comparison, our approach computes a variable assignment of $view which
only contains those computations for the required part, which is used to compute the
final result. For example, the query in Fig. 6 is an optimized query of the query in
Fig. 1. Within Section 4, we present experimental results, which show the speed-up
factor of such optimized queries.</p>
      <p>let $view :=
&lt;root&gt;
&lt;result&gt;
{
for $a in
document('p.xml')/conference/tutorial
let $b :=
&lt;single_result&gt;{$a}&lt;/single_result&gt;
return $b
}
&lt;/result&gt;
&lt;/root&gt;
return $view/result/single_result/tutorial</p>
      <p>In the following subsections, we describe how to eliminate sub-expressions in
variable assignments like $view so that only the required part is computed. This
optimization technique can be used in the important scenario of XQuery queries on
XQuery views, because one way to reformulate an XQuery query Q according to an
XQuery view V is to use the pattern presented in Fig. 7. Whenever there is a reference
in the XQuery query Q to the view V, the variable $view is used to access the view.
let $view := &lt;root&gt; { V } &lt;/root&gt;
return Q</p>
    </sec>
    <sec id="sec-3">
      <title>3 The General Optimization Approach</title>
      <p>We design the optimization step of reducing the XQuery query independently of the
current instance of the XML document. The advantage is that the approach can
optimize the XQuery query in advance without connecting to any database. As the output
of XQuery expressions often contains whole sub-trees of the input XML document,
we can use schema information of the input XML document in order to optimize
queries. For this purpose, we introduce the ordered schema graph, which is based on
the schema of the input XML document. We use this ordered schema graph for search
algorithms, which are outlined in Section 3.2 and Section 3.4.</p>
      <sec id="sec-3-1">
        <title>3.1 Ordered Schema Graph</title>
        <p>The ordered schema graph is generated from an XML Schema definition. As an
example, see the XML Schema definition in Fig. 3 and the ordered schema graph in Fig.
8.</p>
        <p>Each node of an ordered schema graph represents an element node of the schema,
the document node or a dummy node (called :EMPTY node). The :EMPTY node
represents a whole choice expression or a whole sequence expression. There are three
kinds of edges: parent-child edges represent a parent child relationship between
element nodes, the document node and/or :EMPTY nodes. A sibling edge represents a
directed sibling relationship between element nodes, the document node and/or
:EMPTY nodes. Finally, an expression edge represents a relationship to a whole
choice expression or a whole sequence expression between element nodes, the
document node and :EMPTY nodes.</p>
        <sec id="sec-3-1-1">
          <title>N1:DocumentNode</title>
        </sec>
        <sec id="sec-3-1-2">
          <title>N2:conference</title>
          <p>name CDATA</p>
        </sec>
        <sec id="sec-3-1-3">
          <title>N3:EMPTY</title>
          <p>tutorial</p>
          <p>We present here the general rules for generating the ordered schema graph from an
XML Schema definition:
• We create a start node of type :DocumentNode, the child of which is a node
representing that element, which is the root node of the XML document. In the
example of Fig. 3 and Fig. 8, N1 represents the document node and N2 represents
the root element node.
• We add all (required, implied and fixed) attributes of any type of the
corresponding XML element E to the nodes representing E. In the example of Fig. 3 and
Fig. 8, we add the attribute name to the node N2.
• We transform the right-hand side of an element declaration according to the
following rules:
o Nodes of the ordered schema graph representing elements are the
parents of the representation of the right-hand sides of their element
declarations. In the example of Fig. 3 and Fig. 8, N1 is the parent of N2.
o Whenever an element E1 can be a following sibling node of another
element E2, we insert a sibling edge from E2 to E1. This is the case for
repetitions of elements (see right-hand sides of element declarations of
conference, tutorial, paper and references in Fig. 3 and
Fig. 8) and for sequences of elements (see right-hand side of paper).</p>
          <p>Whenever the XML Schema defines an element to be a complexType defined
by a choice (see right-hand side of conference) or a sequence (see right-hand side
of paper), then we create an extra :EMPTY node for easy access to the whole choice
expression or the whole sequence expression, respectively. As an example, see node
N3 in Fig. 8 representing the xsd:choice element in Fig. 3 and node N7
representing the xsd:sequence element in Fig. 3.
3.2 Satisfiability of an XPath Expression According to a Schema
Definition: An XPath expression XP is satisfiable according to a schema, if and only
if there exists at least one document, which is valid according to the schema, where
XP is evaluated to a non-empty result.</p>
          <p>
            The problem of satisfiability of certain subclasses of XPath expressions (without
respect to a schema) is in NP [
            <xref ref-type="bibr" rid="ref14">14</xref>
            ]. We present here a fast (but incomplete)
satisfiability test for XPath expressions according to a schema. The test is incomplete in the
following way. The test returns not satisfiable if we are sure that the XPath
expression is not satisfiable according to a schema. Otherwise the test returns may be
satisfiable.
          </p>
          <p>1.</p>
        </sec>
        <sec id="sec-3-1-4">
          <title>N1:DocumentNode</title>
          <p>N2:conference2.
name CDATA
3., 8.</p>
        </sec>
        <sec id="sec-3-1-5">
          <title>N3:EMPTY</title>
          <p>paper</p>
          <p>We use a modified XPath evaluator to test whether or not the XPath expression XP
is satisfiable according to a schema. The input of the modified XPath evaluator is the
schema and XP. First, the ordered schema graph is created according to the schema
by using the rules summarized in Section 3.1. After that, we execute the modified
XPath evaluator, which performs the task to check whether or not all elements and
attributes of paths within XP are available at the required hierarchical position. The
modified XPath evaluator starts at the node of type :DocumentNode representing
the document node. Within the ordered schema graph, there is all necessary
information in order to execute the modified XPath evaluator, as the parent-child-axis and the
next-sibling-axis are available in the ordered schema graph. The evaluator passes
empty nodes without consuming an element of the XPath expression XP. In
comparison to an XML document, the ordered schema graph can contain loops. Therefore,
the modified XPath evaluator must consider loops when it revisits a node but did not
process the next location step within XP. For this purpose, the modified XPath
evaluator marks all the nodes that contribute to a successful evaluation of XP.</p>
          <p>As an example, see the steps 1, …, 9 performed on the ordered schema graph of
Fig. 9 for the successful evaluation of the XPath query
/conference/paper/references/conference/paper. As in step 9 the
whole XPath expression is processed, this XPath query is considered to be satisfiable.</p>
          <p>In general, with this technique, we can test whether or not a schema definition
allows only XML documents for which a given XPath expression XP can never be
successfully evaluated, i.e. for which the evaluation of the XPath expression returns
an empty set.
3.3 XQuery Graph
paper
subgraph of ordered schema graph
tutorial
For the optimization rules, we consider that subset of XQuery, where the XQuery
expression must conform to following rule Start in EBNF notation.
Start ::= (FunctionDecl)* FLRExpr.</p>
          <p>FunctionDecl ::= "declare" "function" QName "(" ("$"</p>
          <p>QName ("," "$" QName)*)? ")" "{" ExprSingle "}".</p>
          <p>FLRExpr ::= (ForClause | LetClause)+ "return" ExprSingle.</p>
          <p>ForClause ::= "for" "$" VarName "in" ExprSingle.</p>
          <p>LetClause ::= "let" "$" VarName ":=" ExprSingle.</p>
          <p>ExprSingle ::= FLRExpr|IfExpr|PathExpr.</p>
          <p>IfExpr ::= "if" "(" ExprSingle ")" "then" ExprSingle "else" ExprSingle.
PathExpr ::= ("/" RelativePathExpr?) |</p>
          <p>("//"RelativePathExpr) | RelativePathExpr.</p>
          <p>RelativePathExpr ::= (Step | PrimaryExpr)(("/"|"//")</p>
          <p>(Step | PrimaryExpr))*.</p>
          <p>Step ::= ("child" | "descendant" | "attribute" | "self" |
"descendant-or-self" | "following-sibling" | "following" |
"parent" |"ancestor" | "preceding-sibling" | "preceding" |
"ancestor-or-self") "::" (QName | "node()" | "*").
PrimaryExpr ::= "$" QName | Constructor | FunctionCall.</p>
          <p>Constructor ::= ("element" | "attribute") QName "{" ExprSingle "}".
FunctionCall ::= QName "(" (ExprSingle ("," ExprSingle)*)? ")".</p>
          <p>This subset of XQuery contains nested for-let-return clauses, if
expressions, element and attribute constructors, declarations of functions and function calls.</p>
          <p>We present here the general rules for generating the XQuery graph from an
XQuery expression: We generate an own XQuery graph for each variable assignment
$view of the XQuery expression. Every expression within the variable assignment
of $view, which generates output, gets its own new node N representing the output.
Variables (and also nested variables) are replaced with their content. We set a new
node N as parent node of every node in the XQuery graph representing output, which
could be generated as child node to the output of node N by the XQuery evaluator.
Furthermore, we relate the new node N with every node in the XQuery graph
representing output, which could be generated as sibling node to the output of node N by
the XQuery evaluator, by a directed sibling relation. If the next generated output of
the XQuery evaluator is a sub-tree of the input XML document specified by an XPath
expression XP, we search within the ordered schema graph by the modified XPath
evaluator as before, and we retrieve a node set SN of nodes of the ordered schema
graph. We first copy the nodes of SN and copy all descendant nodes and all sibling
nodes, which can be reached from the nodes of SN by parent-child relationships and
sibling relationships. We copy also all parent-child relationships and sibling
relationships for the copied nodes. Finally, we set the current node as parent node of the
copies of SN. In the example of Fig. 10, which represents the XQuery graph of the
XQuery query of Fig. 1, these copies consists of the node N2 and its descendant
nodes N3 to N10, and the node N14 and its descendant node N15. We label the
association with the XPath expression of the XQuery expression (or we use a reference;
here, line number (5) and (12)).</p>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>3.4 Optimization</title>
        <p>This section outlines how the XQuery graph is used to optimize queries. In the
following paragraphs, we describe the general rules for optimizing the query.</p>
        <p>The first step of the optimization approach is as follows: Whenever the content of
a variable $view is queried by an XPath expression XP by $view/XP in the
XQuery query, we process the following optimization steps. We execute the modified
XPath evaluator on the XQuery graph of the variable assignment of $view with the
input XPath query XP. In the case of the XQuery expression in Fig. 1, the XPath
query XP is /result/single_result/tutorial for $view. The modified
XPath evaluator marks all nodes within the XQuery graph that contribute to a
successful evaluation of the query XP in the same way as an XPath query is evaluated on
the ordered schema graph.</p>
        <sec id="sec-3-2-1">
          <title>N3:EMPTY</title>
        </sec>
        <sec id="sec-3-2-2">
          <title>N7:EMPTY</title>
          <p>(8)</p>
          <p>Successful evaluation of
/result/single_result
/tutorial
1.</p>
        </sec>
        <sec id="sec-3-2-3">
          <title>N1:DocumentNode</title>
          <p>(3)
2.</p>
        </sec>
        <sec id="sec-3-2-4">
          <title>N11:result</title>
          <p>Fig. 11. Marked nodes of ordered schema graph for</p>
          <p>/result/single_result/tutorial</p>
          <p>Within a second step, we do not delete all the sub-expressions within the XQuery
expression from which the marked nodes in the XQuery graph are generated and
which do not assign variables, which are used in sub-expressions of marked nodes.
The for-statement defines how often and in which order the result-statement is
executed. Therefore, we do not delete for-statements, except if their
returnstatement is reduced to an empty statement.</p>
          <p>We delete all other unmarked sub-expressions and finally the optimized query
remains.</p>
          <p>The pseudo code of the entire algorithm for optimizing XQuery queries is given in
Fig. 12, which expects an XQuery query Q as input and which returns the optimized
XQuery query Q’ as output.</p>
          <p>In the case of the XQuery query in Fig. 1, we first generate the XQuery graph
shown in Fig. 10 for the variable assignment of $view. Then we mark the nodes
shown in Fig. 11, and finally we optimize to the XQuery query in Fig. 6.
Algorithm OptimizeQuery
Input: XQuery query Q conforming to rule Start in Section 3.3
Output:Optimized XQuery query Q’
(1) Generate abstract syntax tree T of Q
(2) Compute XQuery graph XG with marked nodes of T
(3) Mark all nodes in T, which correspond to marked nodes in XG
(4) while(all children of a symbol ExprSingle of a LetClause
expression are unmarked) do
(5) delete the whole LetClause expression
(6) For all nodes n in T do
(7) If(n and its child nodes are unmarked and
(n is a symbol ExprSingle and
not(n is a parameter of a function call or</p>
          <p>n is a condition of an if-statement))
) then
(8) delete n (and its children)
(9) Compute Q’ from the remaining nodes of T</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4 Performance Analysis</title>
      <p>
        The test system for all experiments is a 1.7 GHz Intel Pentium 4 processor with 128
Megabyte RAM, Windows 2000 as the operating system and Java VM build version
1.4.2. We use the XQuery evaluator of Saxon version 7.9 [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ].
      </p>
      <p>We have generated test input XML documents of different size valid according to
the schema of Fig. 3 for all experiments, where every paper and tutorial
element contains exactly one empty author element. Furthermore, we have used the
XQuery query of Fig. 1 and the optimized query of Fig. 6. In the figures, we present
the average of 10 experiments.</p>
      <p>In the first experiment, the test input XML documents consist of the same amount
of paper and tutorial elements. We increase the file size of the input XML
documents from approximately 8 Kilobytes to approximately 8 Megabytes. Fig. 13
shows the evaluation time depending on the filesize in Kilobytes. The evaluation of
the optimized query is approximately 1.8 times faster than the evaluation of the
original query for file sizes larger than 1.5 Megabytes. Fig. 14 presents how much faster
the evaluation of the optimized query is than the evaluation of the non-optimized
query.</p>
      <p>filesize in kilobytes
speed−up factor of the optimized reformulated query
50
s
nd40
o
c
e
s
in30
e
m
i
t
n20
o
i
t
a
u
l
va10
E
0</p>
      <p>0
2
1.8
1.6</p>
      <p>In the second experiment, the size of the input XML document is constant (here
approximately 2 Megabytes), but we vary the amount of paper and tutorial
elements (see Fig. 15). The speed-up factor of the optimized query varies from 14.6,
when there are no tutorial elements, to 1, when there are only tutorial
elements (see Fig. 16).
speed−up factor of the optimized reformulated query
0
10
20 30 40 50 60 70 80
Amount of tutorial elements in %
90
100
Fig. 16. Speed-up factor of Experiment 2</p>
    </sec>
    <sec id="sec-5">
      <title>5 Related Work</title>
      <p>
        The contributions [
        <xref ref-type="bibr" rid="ref10 ref20 ref8">8, 10, 20</xref>
        ] introduce an algebra for XQuery. Additionally, they list
transformation and optimization rules based on the introduced algebra, but they do
not contain the optimization approach presented in this paper.
      </p>
      <p>[2] describes how the language XQuery can be extended to support views. It
describes the language extensions but does not describe how to optimize.</p>
      <p>
        [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ] projects XML documents to a sufficient XML fragment before processing
XQuery queries. It contains a static path analysis of XQuery queries, which computes
a set of projection paths formulated in XPath. Our approach optimizes the XQuery
expression itself and does not project XML documents.
      </p>
      <p>
        Whereas the complexity of XPath query evaluation on XML documents is
examined in [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], we consider the complexity of our XPath query evaluation algorithm on
an XQuery graph, which is a part of the proposed optimization steps for XQuery
queries.
      </p>
      <p>
        [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] uses graph schemas to optimize regular path expressions within queries for
semistructured data. In comparison, we do not optimize a path expression according
to a schema, but avoid unnecessary transformation steps by eliminating query code
for the generation of output, which is not used further. Furthermore, we introduce an
ordered schema graph (and an XQuery graph as extended version for XQuery
expressions), which contain additional information in comparison to graph schemas like a
sibling relationship, and we deal with XPath as path language.
      </p>
      <p>
        [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] deals with the problem of satisfiability of XPath expressions without respect
to schema information as e.g. by an XML schema definition. In comparison, we
introduce a fast (but incomplete) test that checks whether or not a given XPath
expression is valid according to a given schema and according to a given XQuery
expression.
      </p>
      <p>
        [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ] deals with the test of satisfiability of tree pattern queries, which cover a
fragment of XPath, without respect to a schema and with respect to an acyclic schema.
[
        <xref ref-type="bibr" rid="ref16">16</xref>
        ] discusses, when the test of satisfiability is NP-complete and when there exist
polynomial time algorithm for the test of satisfiability. In comparison, we introduce a
fast (but incomplete) satisfiability test according to a given schema, which can be also
a cyclic schema, and according to a given XQuery expression.
      </p>
      <p>
        Papakonstantinou et al. [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ] studies the inference of DTDs for views of XML data,
but uses the language loto-ql for the definition of XML views, which is less powerful
than XQuery. Furthermore, our approach optimizes all XQuery queries and cannot be
only used in the scenario of XQuery queries on XQuery views.
      </p>
      <p>[4] investigates XML document specifications with schemas and integrity
constraints. It deals with the consistency problem, i.e. whether or not there exists an
XML document that both conforms to the schema and satisfies the constraints. In
comparison, we investigate XPath and XQuery expressions and present a fast (but
incomplete) test that checks whether or not a given XPath expression is valid
according to a given schema.</p>
      <p>
        [
        <xref ref-type="bibr" rid="ref21">5, 21</xref>
        ] describe frameworks for publishing relational data in XML. Both
frameworks allow specifying view definitions formulated in XQuery, and optimize the
reformulated query of a user-defined query according to a view by deleting
unnecessary parts. We follow this idea; however, we optimize even more, as we also consider
the restrictions of copied sub-trees of the input XML document within the
userdefined query and view.
      </p>
      <p>
        Our work was inspired by contributions in [
        <xref ref-type="bibr" rid="ref11 ref12 ref13">11, 12, 13</xref>
        ], which deal with XPath
query reformulation according to an XSLT view and its optimization. In comparison,
in this paper we describe general optimization rules, which are especially applicable
for query reformulation on an XQuery view.
      </p>
      <p>In comparison to all other approaches, we focus on the optimization of XQuery
queries based on the schema of the input XML document in order to eliminate
unnecessary query code, which computes not used intermediate results.</p>
    </sec>
    <sec id="sec-6">
      <title>6 Summary and Conclusions</title>
      <p>In this paper we have examined general optimization rules, which are applicable for
all XQuery queries, and which are very useful for example in the scenario of XQuery
queries on XQuery views. First, we have introduced a tester, which checks whether or
not a given schema allows only XML documents, where the evaluation of a given
XPath expression returns an empty set for all valid XML documents. In the second
step, we have extended the tester. The extended tester optimizes variable assignments
of XQuery queries so that computations of unnecessary intermediate results are
eliminated.</p>
      <p>We have shown by experimental results that the evaluation of the optimized
queries saves processing costs depending on the amount of saved unnecessary
intermediate results.</p>
      <p>Future work will include further optimization rules, which, for example, also
optimize the order of operations within the XQuery expression.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <string-name>
            <surname>Altinel</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Franklin</surname>
            ,
            <given-names>M. J.</given-names>
          </string-name>
          :
          <article-title>Efficient Filtering of XML documents for Selective Dissemination of Information</article-title>
          .
          <source>In Proceedings of 26th International Conference on Very Large Databases</source>
          , Cairo, Egypt (
          <year>2000</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <surname>Chen</surname>
            ,
            <given-names>Y. B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ling</surname>
            ,
            <given-names>T. W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>M. L.</given-names>
          </string-name>
          :
          <article-title>Designing Valid XML Views</article-title>
          ,
          <string-name>
            <surname>ER</surname>
          </string-name>
          <year>2002</year>
          , LNCS
          <volume>2503</volume>
          (
          <year>2002</year>
          )
          <fpage>463</fpage>
          -
          <lpage>477</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <surname>Deutsch</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Tannen</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>Reformulation of XML Queries and Constraints</article-title>
          ,
          <source>In ICDT</source>
          <year>2003</year>
          , LNCS
          <volume>2572</volume>
          (
          <year>2003</year>
          )
          <fpage>225</fpage>
          -
          <lpage>241</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <string-name>
            <surname>Fan</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Libkin</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>On XML Integrity Constraints in the Presence of DTDs</article-title>
          ,
          <source>Journal of the ACM</source>
          , Vol.
          <volume>49</volume>
          , No.
          <volume>3</volume>
          (
          <year>2002</year>
          )
          <fpage>368</fpage>
          -
          <lpage>406</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <string-name>
            <surname>Fernández</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kadiyska</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Suciu</surname>
            ,
            <given-names>D.:</given-names>
          </string-name>
          <article-title>SilkRoute: A Framework for Publishing Relational Data in XML, ACM Transactions on Database Systems</article-title>
          , Vol.
          <volume>27</volume>
          , No.
          <volume>4</volume>
          (
          <year>2002</year>
          )
          <fpage>438</fpage>
          -
          <lpage>493</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          <string-name>
            <surname>Fernández</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Siméon</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chen</surname>
          </string-name>
          . C.,
          <string-name>
            <surname>Choi</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dinoff</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gapeyev</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Marian</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Michiels</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Onose</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Petkanics</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Radhakrishnan</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Re</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Resnick</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sur</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vyas</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wadler</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          :
          <source>Galax pre-release 0.4.0</source>
          (
          <issue>2004</issue>
          ) http://www.galaxquery.org
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Fernández</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Suciu</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          :
          <article-title>Optimizing Regular Path Expressions Using Graph Schemas</article-title>
          ,
          <source>Proceedings of the Fourteenth International Conference on Data Engineering (ICDE)</source>
          , Orlando, Florida, USA (
          <year>1998</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Fisher</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lam</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wong</surname>
            ,
            <given-names>R. K.</given-names>
          </string-name>
          :
          <article-title>Algebraic Transformation and Optimization for XQuery</article-title>
          ,
          <source>APWeb</source>
          <year>2004</year>
          , LNCS
          <volume>3007</volume>
          (
          <year>2004</year>
          )
          <fpage>201</fpage>
          -
          <lpage>210</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Gottlob</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Koch</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pichler</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          :
          <article-title>The Complexity of XPath Query Evaluation</article-title>
          ,
          <source>In Proceedings of the 22th ACM SIGMOD-SIGACT-SIGART symposium of Principles of database systems (PODS</source>
          <year>2003</year>
          ), San Diego, California, USA (
          <year>2003</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Grinev</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kuznetsov</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Towards an Exhaustive Set of Rewriting Rules for XQuery Optimisation: BizQuery Experience</article-title>
          ,
          <string-name>
            <surname>ADBIS</surname>
          </string-name>
          <year>2002</year>
          , LNCS
          <volume>2435</volume>
          (
          <year>2002</year>
          )
          <fpage>340</fpage>
          -
          <lpage>345</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Groppe</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Böttcher</surname>
            ,
            <given-names>S.:</given-names>
          </string-name>
          <article-title>XPath Query Transformation based on XSLT stylesheets</article-title>
          ,
          <source>Fifth International Workshop on Web Information and Data Management (WIDM'03)</source>
          , New Orleans, Louisiana, USA (
          <year>2003</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Groppe</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Böttcher</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Birkenheuer</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          :
          <article-title>Efficient Querying of transformed XML documents</article-title>
          ,
          <source>6th International Conference of Enterprise Information Systems (ICEIS</source>
          <year>2004</year>
          ), Porto, Portugal (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Groppe</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Böttcher</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Heckel</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Birkenheuer</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          :
          <article-title>Using XSLT Stylesheets to Transform XPath Queries</article-title>
          . Eighth East-European
          <source>Conference on Advances in Databases and Information Systems (ADBIS</source>
          <year>2004</year>
          ), Budapest, Hungary (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Hidders</surname>
            , J.: Satisfiability of XPath Expressions,
            <given-names>DBPL</given-names>
          </string-name>
          <year>2003</year>
          , LNCS
          <volume>2921</volume>
          (
          <year>2004</year>
          )
          <fpage>21</fpage>
          -
          <lpage>36</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>Kay</surname>
            ,
            <given-names>M.H.</given-names>
          </string-name>
          :
          <article-title>Saxon - The XSLT</article-title>
          and
          <string-name>
            <surname>XQuery Processor</surname>
          </string-name>
          (
          <year>2004</year>
          ) http://saxon.sourceforge.net
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <surname>Lakshmanan</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ramesh</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhao</surname>
            ,
            <given-names>Z.</given-names>
          </string-name>
          :
          <article-title>On Testing Satisfiability of Tree Pattern Queries</article-title>
          ,
          <source>In Proceedings of the 30th VLDB Conference (VLDB</source>
          <year>2004</year>
          ), Toronto, Canada (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17.
          <string-name>
            <surname>Marian</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Siméon</surname>
          </string-name>
          , J.:
          <article-title>Projecting XML Documents</article-title>
          .
          <source>In Proceedings of the 29th VLDB Conference</source>
          , Berlin, Germany (
          <year>2003</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          18.
          <string-name>
            <surname>Oracle</surname>
          </string-name>
          ,
          <string-name>
            <surname>Oracle XQuery Technology - Preview</surname>
          </string-name>
          (
          <year>2004</year>
          ) http://www.oracle.com/technology/tech/xml/xquery/index.html
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          19.
          <string-name>
            <surname>Papakonstantinou</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vianu</surname>
          </string-name>
          , V.:
          <article-title>DTD Inference for Views of XML Data</article-title>
          ,
          <source>In Proceedings of the Nineteenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS</source>
          <year>2000</year>
          ), Dallas, Texas, USA (
          <year>2000</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          20.
          <string-name>
            <surname>Paparizos</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wu</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lakshmanan</surname>
            ,
            <given-names>L. V. S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jagadish</surname>
            ,
            <given-names>H.V.</given-names>
          </string-name>
          :
          <article-title>Tree Logical Classes for Efficient Evaluation of XQuery</article-title>
          ,
          <source>SIGMOD</source>
          <year>2004</year>
          , Paris, France (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          21.
          <string-name>
            <surname>Shanmugasundaram</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kiernan</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shekita</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fan</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Funderburk</surname>
          </string-name>
          , J.:
          <article-title>Querying XML Views of Relational Data</article-title>
          ,
          <source>In Proceedings of the 27th VLDB Conference</source>
          , Roma, Italy, (
          <year>2001</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          22.
          <string-name>
            <surname>Software</surname>
            <given-names>AG</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Tamino</surname>
            <given-names>XML</given-names>
          </string-name>
          Server (
          <year>2004</year>
          ) http://www.softwareag.com/tamino/News/tamino_41.htm
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          23.
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mulchandani</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rundensteiner</surname>
            ,
            <given-names>E.A.</given-names>
          </string-name>
          :
          <article-title>Updating XQuery Views Published over Relational Data: A Round-Trip Case Study</article-title>
          ,
          <year>Xsym 2003</year>
          , LNCS
          <volume>2824</volume>
          (
          <year>2003</year>
          )
          <fpage>223</fpage>
          -
          <lpage>237</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          24. W3C,
          <string-name>
            <surname>XML Path</surname>
          </string-name>
          <article-title>Language (XPath) Version 1</article-title>
          .0 (
          <issue>1999</issue>
          ) http://www.w3.org/TR/xpath
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          25. W3C,
          <article-title>XQuery 1.0: An XML Query Language</article-title>
          , W3C Working Draft (
          <year>2003</year>
          ) http://www.w3.org/TR/xquery
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>