05.11.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 13 ■ PARTITIONING 573<br />

35 '$POS$', x.pos),<br />

36 '$PNAME$', x.pname );<br />

37 end loop;<br />

Now, we’ll take that query <strong>and</strong> select out the partition position (PNAME) <strong>and</strong> the count of<br />

rows in that partition (CNT). Using RPAD, we’ll construct a rather rudimentary but effective<br />

histogram:<br />

38<br />

39 open p_cursor for<br />

40 'select pname, cnt,<br />

41 substr( rpad(''*'',30*round( cnt/max(cnt)over(),2),''*''),1,30) hg<br />

42 from (' || substr( l_text, 1, length(l_text)-11 ) || ')<br />

43 order by oc';<br />

44<br />

45 end;<br />

46 /<br />

Procedure created.<br />

If we run this with an input of 4, for four hash partitions, we would expect to see output<br />

similar to the following:<br />

ops$tkyte@ORA10G> variable x refcursor<br />

ops$tkyte@ORA10G> set autoprint on<br />

ops$tkyte@ORA10G> exec hash_proc( 4, :x );<br />

PL/SQL procedure successfully completed.<br />

PN CNT HG<br />

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

p1 12141 *****************************<br />

p2 12178 *****************************<br />

p3 12417 ******************************<br />

p4 12105 *****************************<br />

The simple histogram depicted shows a nice, even distribution of data over each of the<br />

four partitions. Each has close to the same number of rows in it. However, if we simply go<br />

from four to five hash partitions, we’ll see the following:<br />

ops$tkyte@ORA10G> exec hash_proc( 5, :x );<br />

PL/SQL procedure successfully completed.<br />

PN CNT HG<br />

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

p1 6102 **************<br />

p2 12180 *****************************<br />

p3 12419 ******************************<br />

p4 12106 *****************************<br />

p5 6040 **************

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

Saved successfully!

Ooh no, something went wrong!