The exchange operator
marks the boundary between a producer and a consumer operator (the
operators below the exchange operator produce
data and those above it consume data). In an earlier example (Example
A) that showed parallel scan of the titles table (select * from
titles
), the exchange:emit and
the scan operator produce data. This is shown
briefly.
select * from titles The type of query is SELECT. ROOT:EMIT Operator |EXCHANGE Operator (Merged) |Executed in parallel by 3 Producer and 1 Consumer processes. | | |EXCHANGE:EMIT Operator | | | | |RESTRICT Operator | | | | | | |SCAN Operator | | | | FROM TABLE | | | | titles | | | | Table Scan.
In this example, one consumer process reads data from a pipe (which is used as a medium to transfer data across process boundaries) and hands it off to the emit operator, which in turn routes the result to the client. The exchange operator also spawns worker processes, which are called producer threads. The exchange:emit operator is responsible for writing the data into a pipe managed by the exchange operator.
Figure 4-1: Binding of thread to plan fragments in query plan
Figure 4-1 shows the process boundary between a producer and a consumer task. There are two plan fragments in this query plan. The plan fragment with the scan and the exchange:emit operators are being cloned three ways and then a three-to-one exchange operator writes it into a pipe. The emit operator and the exchange operator are run by a single process, which means there is a single clone of that plan fragment.