Analytical vs aggregate functions

You Asked

Are analytical functions replacement for aggregate functions? Some of the developers here
are hurrying in replacing the group by aggregate functions with analytical functions just
because they learnt something new :-).. Are the analytical functions faster
always(compared to aggregate)?

What about the amount of work done by Analytics, say if we don't mind rows to be collapsed and
return all rows with a column for aggregates. Would the analytics do less work. My guess is they
would do the same amount, because they need to perform aggregation anyway.

Something like say

Select sum(sal) over (partition by emp.dept) sal_per_Dept
from emp

vs

select sum(sal), emp.dept from emp group by emp.dept
 

and we said...

say you have 100 deptnos

with an average of 100 employees per deptno

 

 

which would you rather have sitting in your temp?  100 rows, or 10,000

 

 

I don't even know why we are having this discussion - it seems so blatantly obvious that

 

a) you use aggregation when you needs to, well, AGGREGATE

b) you use analytics when you don't want to AGGREGATE

 

Even if they performed IDENTICALLY - I cannot understand why we would be having this discussion -

 

 

select sum(sal), deptno from emp group by deptno;

 

versus

 

select distinct sum(sal) over (partition by deptno), deptno from emp;

 

it just seems obvious which is the "right" approach.

 

 

select owner, count(*) from big_table group by owner

 

call     count       cpu    elapsed       disk      query    current        rows

------- ------  -------- ---------- ---------- ---------- ----------  ----------

Parse        1      0.00       0.00          0          0          0           0

Execute      1      0.00       0.01          0          0          0           0

Fetch        3      0.84       0.83      12856      14465          0          26

------- ------  -------- ---------- ---------- ---------- ----------  ----------

total        5      0.84       0.84      12856      14465          0          26

 

Rows     Row Source Operation

-------  ---------------------------------------------------

     26  HASH GROUP BY (cr=14465 pr=12856 pw=0 time=845645 us)

1000000   TABLE ACCESS FULL BIG_TABLE (cr=14465 pr=12856 pw=0 time=1011134 us)

********************************************************************************

select distinct owner, count(*) over (partition by owner) from big_table

 

call     count       cpu    elapsed       disk      query    current        rows

------- ------  -------- ---------- ---------- ---------- ----------  ----------

Parse        1      0.00       0.00          0          0          0           0

Execute      1      0.00       0.00          0          0          0           0

Fetch        3      2.37       2.32      12856      14465          0          26

------- ------  -------- ---------- ---------- ---------- ----------  ----------

total        5      2.37       2.32      12856      14465          0          26

 

Rows     Row Source Operation

-------  ---------------------------------------------------

     26  HASH UNIQUE (cr=14465 pr=12856 pw=0 time=2325741 us)

1000000   WINDOW SORT (cr=14465 pr=12856 pw=0 time=2709348 us)

1000000    TABLE ACCESS FULL BIG_TABLE (cr=14465 pr=12856 pw=0 time=1000114 us)

魔兽就是毒瘤,大家千万不要玩。
原文地址:https://www.cnblogs.com/tracy/p/1783201.html