Oracle使用物化视图提高group by性能

前端之家收集整理的这篇文章主要介绍了Oracle使用物化视图提高group by性能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  • 情况介绍
    现有表OE.PRODUCT_INFORMATION数据量为800万,求出各个供应商供应产品的数量

  • 无使用物化视图,只在建立SUPPLIER_ID建立索引,执行时间为15s左右

    SELECT SUPPLIER_ID,COUNT(*) FROM OE.PRODUCT_INFORMATION GROUP BY SUPPLIER_ID ORDER BY SUPPLIER_ID;
  • 使用物化视图(MATERIALIZED VIEW),时间为50ms左右

    --Create a mv log before creating a mv
    CREATE MATERIALIZED VIEW LOG ON OE.PRODUCT_INFORMATION WITH ROWID,SEQUENCE (SUPPLIER_ID),PRIMARY KEY INCLUDING NEW VALUES;
    
    CREATE MATERIALIZED VIEW PI_MV_ON_SUPPLIERS BUILD IMMEDIATE REFRESH FAST ON COMMIT AS SELECT SUPPLIER_ID,COUNT(SUPPLIER_ID) FROM OE.PRODUCT_INFORMATION GROUP BY SUPPLIER_ID SELECT * FROM PI_MV_ON_SUPPLIERS;

    click Materialized View Log and Materialized View for more information

原文链接:https://www.f2er.com/oracle/211019.html

猜你在找的Oracle相关文章