These are quotes from Oracle docs:
[Optional] Merge by combining the two aggregation contexts and return a single context. This operation combines the results of aggregation over subsets in order to obtain the aggregate over the entire set. This extra step can be required during either serial or parallel evaluation of an aggregate. If needed, it is performed before step 4:
,
The ODCIAggregateMerge() interface is invoked to compute super aggregate values in such rollup operations.
We have an aggregate function, that we do NOT want to ever run in parallel.
The reason is that the merging of contexts would be resource consuming and would force us to use different data structures than we are using now, effectively offseting any performance benefits from parallel execution.
Thus, we did not declare our function as parallel_enabled, and instead return ODCIconst.Error in ODCIAggregateMerge 'just in case'.
However, the first quote docs claim, that merge may occur even in serial evaluation.
Super-aggregates (rollup, cube) are obvious examples, but are there any others?
I've been totally unable to reproduce it with simple group by, merge is never called without parallel_enabled and it seems that always only one context is created within the group.
Is it safe to assume that without the parallel_enabled set, merge will never be run?
Have you ever seen a counterexample to that rule?
GROUP BY GROUPING SETS(...)
? The documentation forODCIAggregateMerge
in Oracle 19c added this line: "If the user-defined aggregate *is a window function*, and it is not possible to make an implementation of ODCIAggregateMerge(), ODCIConst.Errorshould be returned. This error is translated as an Oracle user error." I infer from that that there is at least one analytic function case that will invoke a merge, but I can't say what it would be. – Solubilizewith t as (select 1 x from dual union all select 2 from dual) select t.x, count(1) from t group by rollup(t.x)
Here for null x aggregation contexts can be simply merged instead of invoking function for the second time. What I'm looking for is cases beside super-aggregates. – Cletacleti