Various techniques are described for processing database commands that
include MINUS and/or INTERSECT operators. According to one technique, the
database server executes the MINUS/INTERSECT in a specialized rowsource
in parallel. In one approach, the specialized rowsource implements a sort
merge-join like solution, where: a DISTINCT SORT is performed on each
input, a left and right pointer is maintained on the respective input
streams of tuples, the left or right pointer is incremented based on
whether there is a match between the tuples pointed-to by the pointers,
and the tuple of the left side is returned (or not returned) based on
whether there is a match. Techniques are described for generating
multiple query plans for executing a query, where each of the query plans
includes a plan portion for executing, in parallel, the operation
associated with a MINUS/INTERSECT operator. Cost estimates are generated
for the query plans. The database server selects from the query plans a
particular query plan to execute based, at least in part, on the cost
estimates.