05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 14 ■ PARALLEL EXECUTION 647<br />

173 130978<br />

174 130925<br />

175 129863<br />

176 106154<br />

177 140772<br />

178 140778<br />

179 90475<br />

8 rows selected.<br />

It’s not as evenly distributed as the <strong>Oracle</strong> built-in parallelism in this case, but it’s pretty<br />

good. If you recall, earlier you saw how many rows were processed by each parallel execution<br />

server <strong>and</strong>, using the built-in parallelism, the row counts were very close to each other (they<br />

were off only by one or two). Here we had a job that processed as few as 90,475 rows <strong>and</strong> one<br />

that processed as many as 140,778. Most of them processed about 130,000 rows in this case.<br />

Suppose, however, that you do not want to use the rowid processing—perhaps the query<br />

is not as simple as SELECT * FROM T <strong>and</strong> involves joins <strong>and</strong> other constructs that make using<br />

the rowid impractical. You can use the primary key of some table instead. For example, say<br />

you want to break that same BIG_TABLE into ten pieces to be processed concurrently by primary<br />

key. You can do that easily using the NTILE built-in analytic function. The process is<br />

rather straightforward:<br />

big_table-ORA10G> select nt, min(id), max(id), count(*)<br />

2 from (<br />

3 select id, ntile(10) over (order by id) nt<br />

4 from big_table<br />

5 )<br />

6 group by nt;<br />

NT MIN(ID) MAX(ID) COUNT(*)<br />

---------- ---------- ---------- ----------<br />

1 1 100000 100000<br />

2 100001 200000 100000<br />

3 200001 300000 100000<br />

4 300001 400000 100000<br />

5 400001 500000 100000<br />

6 500001 600000 100000<br />

7 600001 700000 100000<br />

8 700001 800000 100000<br />

9 800001 900000 100000<br />

10 900001 1000000 100000<br />

10 rows selected.<br />

Now you have ten nonoverlapping primary key ranges—all of nice, equal size—that you<br />

can use to implement the same DBMS_JOB technique as shown earlier to parallelize your<br />

process.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!