This page will demonstrate why SQL’s natural operation is performed at a higher level of processing giving it advantages over XQuery for automatic processing that greatly increases its level of nonprocedural processing. The hierarchical structure in Figure 1 is the structure that is to be processed.
A / \ BD || CE Figure 1
The ANSI SQL Left Outer Join’s hierarchical syntax can model hierarchical structures and their hierarchical semantics define their hierarchical processing. This means they can be processed directly by the relational processor to support hierarchical processing. The ANSI SQL Left Outer Join string below in Figure 2 models the structure in Figure 1. It will process the structure left to right going down the left path and then down the right path.
SELECT * FROM A LEFT JOIN B ON A.a=B.b LEFT JOIN C ON B.b=C.c LEFT JOIN D ON A.a=D.d LEFT JOIN E ON D.d=E.e Figure 2
The ANSI SQL Left Outer Join string below in Figure 3 also models the structure in Figure 1. It processes the structure width first. Both methods model the same structure. These SQL data structure definitions can be built automatically from metadata sources such as XML Schemas. The SQL hierarchical structure definition is easily extractible to support advanced nonprocedural hierarchical operations.
SELECT * FROM A LEFT JOIN B ON A.a=B.b LEFT JOIN D ON A.a=D.d LEFT JOIN C ON B.b=C.c LEFT JOIN E ON D.d=E.e Figure 3
XQuery does not have this data modeling capability. It requires more lower level nested looping user specifications shown in a simplified XQuery form in Figure 4 to process the structure shown in Figure 1.The looping goes down the left path first and then the right path. This is the same as the SQL data modeling shown for Figure 2 except the XQuery hierarchical structure definition is not easily determined automatically to support advanced automatic nonprocedural processing.
FOR $A in //A FOR $B in //B[$A.a=B.b] FOR $C in //C[$B.b=C.c] FOR $D in //D[$A.a=D.d] FOR $E in //E[$D.d=E.e] Figure 4
For XQuery to process the structure in Figure 1 using width first processing in the same way SQL data model processing was shown in Figure 3 see Figure 5. It is different than the top down processing. This demonstrates that XQuery operations are at a lower level closer to the control flow than SQL which is at a higher level driven automatically by the hierarchical structure being processed making SQL more nonprocedural and accurate.
FOR $A in //A FOR $B in //B[$A.a=B.b] FOR $D in //D[$A.a=D.d] FOR $C in //C[$B.b=C.c] FOR $E in //E[$D.d=E.e] Figure 5 More information on comparing SQL’s higher level hierarchical processing to XQuery’s can be found in my recent Database Journal article: SQL’s Optimized Hierarchical Data Processing Driven by its Data Structure located at: http://www.databasejournal.com/features/article.php/3877281/article.htm