Could XQuery Whiteboard perform better?
Yes. In particular, the use of the “table:” URI in the fn:doc function causes the creation of an XML document that represents the entire table. In many cases only a small number of the elements representing the tables columns and rows are actually used. A better approach would be to construct only those columns that are needed, and to push some of the XQuery predicates on the constructed document into an inner SQL query.