90 lines
5.7 KiB
HTML
90 lines
5.7 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="SMP and recursive queries" />
|
|
<meta name="abstract" content="Recursive queries can benefit as much from symmetric multiprocessing (SMP) as do other queries on the system." />
|
|
<meta name="description" content="Recursive queries can benefit as much from symmetric multiprocessing (SMP) as do other queries on the system." />
|
|
<meta name="DC.Relation" scheme="URI" content="rzajqrecursive.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="rzajqrctesmp" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>SMP and recursive queries</title>
|
|
</head>
|
|
<body id="rzajqrctesmp"><a name="rzajqrctesmp"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">SMP and recursive queries</h1>
|
|
<div><p>Recursive queries can benefit as much from symmetric multiprocessing
|
|
(SMP) as do other queries on the system.</p>
|
|
<div class="section"><p>Recursive queries and parallelism however present some unique
|
|
requirements. Because the initialization fullselect of a recursive query (the
|
|
fullselect that seeds the initial values of the recursion), is likely to produce
|
|
only a small fraction of the ultimate results that cycle through the recursion
|
|
process, the query optimizer does not want each of the threads running in
|
|
parallel to have a unique queue object that feeds only itself. This results
|
|
in some threads having way too much work to do and others threads quickly
|
|
depleting their work. The best way to do this is to have all the threads share
|
|
the same queue allowing a thread to enqueue a new recursive key value just
|
|
as a waiting thread is there to dequeue that request. A shared queue allow
|
|
all threads to actively contribute to the overall depletion of the queue entries
|
|
until no thread is able to contribute more results. Having multiple threads
|
|
share the same queue however requires some management by the Query runtime
|
|
so that threads do not prematurely end. Some buffering of the
|
|
initial seed values might be necessary. Illustrated in the query below, where
|
|
there are two fullselects that seed the recursion, a buffer is provide so
|
|
that no thread hits a dequeue state and terminates before the query has seeded
|
|
enough recursive values to get things going. </p>
|
|
<p>The following Visual Explain
|
|
diagram illustrates the plan for the following query run with <samp class="codeph">CHGQRYA
|
|
DEGREE(*NBRTASKS 4)</samp>. It illustrates that the results of the multiple
|
|
initialization fullselects are buffered up and that multiple threads (illustrated
|
|
by the multiple arrow lines) are acting on the enqueue and dequeue request
|
|
nodes. As with all SMP queries, the multiple threads (in this case 4) are
|
|
putting their results in to a Temporary List object which become the output
|
|
for the main query.</p>
|
|
<pre>cl:chgqrya degree(*nbrtasks 4);
|
|
|
|
<strong>WITH</strong> destinations (departure, arrival, connects, cost )<strong>AS</strong>
|
|
(
|
|
<strong>SELECT</strong> f.departure, f.arrival, 0 , ticket
|
|
<strong>FROM</strong> flights f WHERE f.departure='Chicago'
|
|
<strong>UNION ALL</strong>
|
|
<strong>SELECT</strong> t.departure, t.arrival, 0 , ticket
|
|
<strong>FROM</strong> trains t WHERE t.departure='Chicago'
|
|
<strong>UNION ALL</strong>
|
|
<strong>SELECT</strong>
|
|
r.departure,b.arrival, r.connects+1 ,
|
|
r.cost+b.ticket
|
|
<strong>FROM</strong> destinations r, flights b
|
|
<strong>WHERE</strong> r.arrival=b.departure
|
|
<strong>UNION ALL</strong>
|
|
<strong>SELECT</strong>
|
|
r.departure,b.arrival, r.connects+1 ,
|
|
r.cost+b.ticket
|
|
<strong>FROM</strong> destinations r, trains b
|
|
<strong>WHERE</strong> r.arrival=b.departure)
|
|
<strong>SELECT</strong> departure, arrival, connects,cost
|
|
<strong>FROM</strong> destinations;</pre>
|
|
<img src="rzajq566.gif" alt="Visual
Explain diagram of example query with SMP" /></div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajqrecursive.htm" title="Certain applications and data are recursive by nature. Examples of such applications are a bill-of-material, reservation, trip planner or networking planning system where data in one results row has a natural relationship (call it a parent, child relationship) with data in another row or rows. Although the kinds of recursion implemented in these systems can be performed by using SQL Stored Procedures and temporary results tables, the use of a recursive query to facilitate the access of this hierarchical data can lead to a more elegant and better performing application.">Recursive query optimization</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |