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)

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    HTTP请求下载文件格式
    MT7621 加 openWRT 用HTTP和远程服务器通信
    MT7621加 OPENWRT 移植MQTT(paho.mqtt.c) 进行数据的收发
    MT7621安装的openwrt出现无法删除文件的问题
    GAI_LIB = -lanl
    error: expected declaration specifiers or '...' before numeric constant void free(void *);
    environment variable 'STAGING_DIR' not defined
    ubuntu安装 make4.2
    gcc在root权限下查不到版本
    【原创】大叔经验分享(113)markdown语法
  • 原文地址:https://www.cnblogs.com/tracy/p/1783201.html
Copyright © 2011-2022 走看看