w3school.com has a tutorial for xquery and the section entitled "XQuery Example" they outline three queries. I have run the queries through VXQuery's Algebricks code branch and query plans. Below are the three queries in both their xquery form, the vxquery plans, and a commentary and/or questions about the breakdown.
w3school tutorial: http://www.w3schools.com/xquery/xquery_example.asp vxquery command: sh ./vxquery-core/target/appassembler/bin/vxq -compileonly xquery_example_1.xq -showtet === Query 1 === doc("books.xml") assign [$$2] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}doc, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}promote, Args:[function-call: vxquery:{http://www.w3.org/2005/xpath-functions}data, Args:[$$1], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE({http://www.w3.org/2001/XMLSchema}string QUANT_QUESTION)]]] -- |UNPARTITIONED| assign [$$1] <- [{http://www.w3.org/2001/XMLSchema}string QUANT_ONE(books.xml)] -- |UNPARTITIONED| empty-tuple-source -- |UNPARTITIONED| Thoughts on the order of operations and details. 1. Default start with an empty tuple. 2. Assign the source file name [$$1] as a string. 3. Take the string file name and pass it as an argument to the data functions (doc). 4. Ready to use in [$$2] What do these keywords mean? UNPARTITIONED QUANT_ONE QUANT_QUESTION === Query 2 === doc("books.xml")/bookstore/book/title assign [$$17] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[$$16]] -- |UNPARTITIONED| subplan { aggregate [$$16] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sequence, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$14, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@69198891 QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(title), org.apache.vxquery.types.AnyType@281acd47, nilled = true))]]] -- |UNPARTITIONED| unnest $$14 at $$15 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$12] -- |UNPARTITIONED| assign [$$13] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$12]] -- |UNPARTITIONED| assign [$$12] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[$$11]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| subplan { aggregate [$$11] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sequence, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$9, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@69198891 QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(book), org.apache.vxquery.types.AnyType@281acd47, nilled = true))]]] -- |UNPARTITIONED| unnest $$9 at $$10 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$7] -- |UNPARTITIONED| assign [$$8] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$7]] -- |UNPARTITIONED| assign [$$7] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[$$6]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| subplan { aggregate [$$6] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sequence, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$4, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@69198891 QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(bookstore), org.apache.vxquery.types.AnyType@281acd47, nilled = true))]]] -- |UNPARTITIONED| unnest $$4 at $$5 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$2] -- |UNPARTITIONED| assign [$$3] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$2]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| assign [$$2] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}doc, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}promote, Args:[function-call: vxquery:{http://www.w3.org/2005/xpath-functions}data, Args:[$$1], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE({http://www.w3.org/2001/XMLSchema}string QUANT_QUESTION)]]] -- |UNPARTITIONED| assign [$$1] <- [{http://www.w3.org/2001/XMLSchema}string QUANT_ONE(books.xml)] -- |UNPARTITIONED| empty-tuple-source -- |UNPARTITIONED| Starts out the exact same way as the first for doc("books.xml"). The processing continues for the extra query details. … 5. The data is passed to count function to save the count to [$$3]. 6. Set up a vxquery operator is set up to iterate over the data in $$4. 7. I see that we have the word "bookstore" in the query now. Looks like we have a sequence for each child based on the interator supplied from the data in books.xml. I want to say that [$$6] now represents the data for each bookstore tuple. … Looks like the next set of operations are similar to 5, 6 and 7 except that we now have a sort on distinct "bookstore" tuples. 8. Sort distinct nodes from the output of [$$6] and save them to [$$7]. 9. Assign the count to [$$8]. 10. Set up a vxquery operator is set up to iterate over the data in $$7. 11. Now we see the next part of the query for "book". In this section we set up a sequence of all the books from the data supplied in the iterator $$14. … Repeat again for "title" … Finally sort the complete output. Looks like we assign a count, but do not use it. Is that true? Why does the iterator have to variables? What do these keywords mean? QUANT_STAR === Query 3 === doc("books.xml")/bookstore/book[price<30] assign [$$19] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[$$18]] -- |UNPARTITIONED| subplan { aggregate [$$18] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sequence, Args:[$$13]] -- |UNPARTITIONED| subplan { select (function-call: vxquery:{urn:org.apache.vxquery.operators-ext}if-then-else, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}instance-of, Args:[$$17, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE({http://www.w3.org/2001/XMLSchema-extensions}numeric QUANT_ONE)], function-call: vxquery:{urn:org.apache.vxquery.operators-ext}value-eq, Args:[$$17, $$14], function-call: vxquery:{http://www.w3.org/2005/xpath-functions}boolean, Args:[$$17]]) -- |UNPARTITIONED| assign [$$17] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}general-lt, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$15, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyItemType@37bd2664 QUANT_STAR)], function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$16, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyItemType@37bd2664 QUANT_STAR)]]] -- |UNPARTITIONED| assign [$$16] <- [{http://www.w3.org/2001/XMLSchema}integer QUANT_ONE(30)] -- |UNPARTITIONED| assign [$$15] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$13, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@b551d7f QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(price), org.apache.vxquery.types.AnyType@7cb25b9d, nilled = true))]] -- |UNPARTITIONED| unnest $$13 at $$14 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$11] -- |UNPARTITIONED| assign [$$12] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$11]] -- |UNPARTITIONED| assign [$$11] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$9, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@b551d7f QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(book), org.apache.vxquery.types.AnyType@7cb25b9d, nilled = true))]]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| unnest $$9 at $$10 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$7] -- |UNPARTITIONED| assign [$$8] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$7]] -- |UNPARTITIONED| assign [$$7] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sort-distinct-nodes-asc-or-atomics, Args:[$$6]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| subplan { aggregate [$$6] <- [function-call: vxquery:{urn:org.apache.vxquery.operators-ext}sequence, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}child, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}treat, Args:[$$4, {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(org.apache.vxquery.types.AnyNodeType@b551d7f QUANT_STAR)], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE(NodeTest(NameTest(bookstore), org.apache.vxquery.types.AnyType@7cb25b9d, nilled = true))]]] -- |UNPARTITIONED| unnest $$4 at $$5 <- function-call: vxquery:{urn:org.apache.vxquery.operators-ext}iterate, Args:[$$2] -- |UNPARTITIONED| assign [$$3] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}count, Args:[$$2]] -- |UNPARTITIONED| nested tuple source -- |UNPARTITIONED| } -- |UNPARTITIONED| assign [$$2] <- [function-call: vxquery:{http://www.w3.org/2005/xpath-functions}doc, Args:[function-call: vxquery:{urn:org.apache.vxquery.operators-ext}promote, Args:[function-call: vxquery:{http://www.w3.org/2005/xpath-functions}data, Args:[$$1], {http://www.w3.org/2001/XMLSchema-extensions}type QUANT_ONE({http://www.w3.org/2001/XMLSchema}string QUANT_QUESTION)]]] -- |UNPARTITIONED| assign [$$1] <- [{http://www.w3.org/2001/XMLSchema}string QUANT_ONE(books.xml)] -- |UNPARTITIONED| empty-tuple-source -- |UNPARTITIONED| The plan is completely the same up until books. The first sub plan is identical to what seen have seen. Once we have the "bookstore" tuples, the "book" tuples are pulled out. We sort, count and create an iterator. 1. The books are assigned to $$11 2. The prices are sorted, counted and created iterator into $$15. 3. Since we need 30 as a parameter we assign it to $$16 4. $$17 is the less than operator on the price and 30 variables. 5. The select function pulls out only the values that are TRUE. 6. The result is created into a sequence 7. The final output is sorted. how do you define a subplan? Is that for each level of the query?
