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 14 ■ PARALLEL EXECUTION 623<br />

■Note If a parallel execution is not occurring in your system, do not expect to see the parallel execution<br />

servers in V$SESSION. They will be in V$PROCESS, but will not have a session established unless they are<br />

being used. The parallel execution servers will be connected to the database, but will not have a session<br />

established. See Chapter 5 for details on the difference between a session <strong>and</strong> a connection.<br />

In a nutshell, that is how parallel query—<strong>and</strong>, in fact, parallel execution in general—works.<br />

It entails a series of parallel execution servers working in t<strong>and</strong>em to produce subresults that<br />

are fed either to other parallel execution servers for further processing or to the coordinator<br />

for the parallel query.<br />

In this particular example, as depicted, we had BIG_TABLE spread across four separate<br />

devices, in a single tablespace (a tablespace with four data files). When implementing parallel<br />

execution, it is generally “optimal” to have your data spread over as many physical devices as<br />

possible. You can achieve this in a number of ways:<br />

• Using RAID striping across disks<br />

• Using ASM, with its built-in striping<br />

• Using partitioning to physically segregate BIG_TABLE over many disks<br />

• Using multiple data files in a single tablespace, thus allowing <strong>Oracle</strong> to allocate extents<br />

for the BIG_TABLE segment in many files<br />

In general, parallel execution works best when given access to as many resources (CPU,<br />

memory, <strong>and</strong> I/O) as possible. However, that is not to say that nothing can be gained from parallel<br />

query if the entire set of data were on a single disk, but you would perhaps not gain as<br />

much as would be gained using multiple disks. The reason you would likely gain some speed<br />

in response time, even when using a single disk, is that when a given parallel execution server<br />

is counting rows it is not reading them, <strong>and</strong> vice versa. So, two parallel execution servers may<br />

well be able to complete the counting of all rows in less time than a serial plan would.<br />

Likewise, you can benefit from parallel query even on a single CPU machine. It is doubtful<br />

that a serial SELECT COUNT(*) would use 100 percent of the CPU on a single CPU machine—it<br />

would be spending part of its time performing (<strong>and</strong> waiting for) physical I/O to disk. Parallel<br />

query would allow you to fully utilize the resources (the CPU <strong>and</strong> I/O, in this case) on the<br />

machine, whatever those resources may be.<br />

That final point brings us back to the earlier quote from Practical <strong>Oracle</strong>8i: Building<br />

Efficient <strong>Database</strong>s: parallel query is essentially nonscalable. If you allowed four sessions to<br />

simultaneously perform queries with two parallel execution servers on that single CPU machine,<br />

you would probably find their response times to be longer than if they just processed serially.<br />

The more processes clamoring for a scarce resource, the longer it will take to satisfy all requests.<br />

And remember, parallel query requires two things to be true. First, you need to have a<br />

large task to perform—for example, a long-running query, the runtime of which is measured<br />

in minutes, hours, or days, not in seconds or subseconds. This implies that parallel query is<br />

not a solution to be applied in a typical OLTP system, where you are not performing longrunning<br />

tasks. Enabling parallel execution on these systems is often disastrous. Second, you

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

Saved successfully!

Ooh no, something went wrong!