Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

12.1.1 SQL and the Adjacency List Model > 12.1.1 SQL and the Adjacency List Mod... - Pg. 230

12.1 Adjacency List Model Graphs 221 While still procedural under the covers, you can use recursive CTEs instead of loops and perhaps gain advantages from the query optimizer and parallelism. The very general skeleton of such queries is WITH RECURSIVE SolutionGraph (source_node, dest_node, <wgt>, ..) AS (SELECT source_node, dest_node, <wgt>, <other attributes>, <possible counts> FROM AdjacencyListGraph UNION ALL SELECT G1.source_node, G2.dest_node, <computation on wgt>, <computation on other attributes>, <increment counts> FROM SolutionGraph AS G1, Graph AS G2 WHERE G2.source_node = G1.dest_node AND G2.dest_node < > G1.source_node