zoukankan      html  css  js  c++  java
  • 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)

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    机器学习实践笔记3(树和随机森林)
    Cocos2d-x3.1回调函数具体解释
    base 64 编解码器
    HDU 4915 Parenthese sequence _(:зゝ∠)_ 哈哈
    跟我extjs5(03--在项目过程中加载文件)
    备份和还原数据库
    Android学习–Android app 语言切换功能
    Android app内语言环境切换
    Android学习–Android app 语言切换功能
    swift:自定义UICollectionViewFlowLayout
  • 原文地址:https://www.cnblogs.com/tracy/p/1783201.html
Copyright © 2011-2022 走看看