Processing is
done in the EMIT
operator,
and requires that the EMIT
operator’s input
stream be sorted according to any order by requirements
in the query. The processing is similar to what is done in the GROUP
SORTED AGGREGATE
operator.
Each row read from the child is checked to see if it starts a new group. If it does not, aggregate functions are applied as appropriate to the query’s requested groups. If a new group is started, the current group and its aggregated values are returned to the user. A new group is then started and its aggregate values are initialized from the new row’s values. This example collects an ordered list of all cities and reports a count of the number of entries for each city after the city list.
select city from authors order by city compute count(city) by city QUERY PLAN FOR STATEMENT 1 (at line 1). STEP 1 The type of query is SELECT. 2 operator(s) under root Emit with Compute semantics ROOT:EMIT Operator (VA = 2) |SORT Operator (VA = 1) | Using Worktable1 for internal storage. | | |SCAN Operator (VA = 0) | | FROM TABLE | | authors | | Table Scan. | | Forward Scan. | | Positioning at start of table. | | Using I/O Size 2 Kbytes for data pages. | | With LRU Buffer Replacement Strategy for data pages.
In this example, the EMIT
operator’s
input stream is sorted on the city attribute. For each row, the compute
by count value is incremented. When a new city value is
fetched, the current city’s values and associated count
value is returned to the user. The new city value becomes the new compute
by grouping value and its count is initialized to one.