查询复杂sql的表的大小

发布时间:2020-07-28 15:06:52 作者:llc018198
来源:网络 阅读:349

1.先explain plan for 目标sql:

explain plan for WITH sales_countries AS
 (SELECT /*+ gather_plan_statistics */
   cu.cust_id, co.country_name
    FROM sh.countries co, sh.customers cu
   WHERE cu.country_id = co.country_id),
top_sales AS
 (SELECT p.prod_name,
         sc.country_name,
         s.channel_id,
         t.calendar_quarter_desc,
         s.amount_sold,
         s.quantity_sold
    FROM sh.sales s
    JOIN sh.times t
      ON t.time_id = s.time_id
    JOIN sh.customers c
      ON c.cust_id = s.cust_id
    JOIN sales_countries sc
      ON sc.cust_id = c.cust_id
    JOIN sh.products p
      ON p.prod_id = s.prod_id),
sales_rpt AS
 (SELECT prod_name product,
         country_name country,
         channel_id channel,
         substr(calendar_quarter_desc, 6, 2) quarter,
         SUM(amount_sold) amount_sold,
         SUM(quantity_sold) quantity_sold
    FROM top_sales
   GROUP BY prod_name,
            country_name,
            channel_id,
            substr(calendar_quarter_desc, 6, 2))
SELECT *
  FROM (SELECT product, channel, quarter, country, quantity_sold
          FROM sales_rpt) pivot(SUM(quantity_sold) FOR(channel, quarter) IN((5, '02') AS
                                                                            catalog_q2,
                                                                            (4, '01') AS
                                                                            internet_q1,
                                                                            (4, '04') AS
                                                                            internet_q4,
                                                                            (2, '02') AS
                                                                            partners_q2,
                                                                            (9, '03') AS
                                                                            tele_q3))
 46   ORDER BY product, country
 47  /
Explained.
Elapsed: 00:00:00.37

SQL>

2.用以下sql可以查询出相关表的大小:
SELECT owner,

       segment_name,

       segment_type,

       SUM(bytes / 1024 / 1024) "Size(Mb)"

  FROM dba_segments

 WHERE owner IN (SELECT /*+ no_unnest */

                  object_owner

                   FROM plan_table)

   AND segment_name IN (SELECT /*+ no_unnest */

                         object_name

                          FROM plan_table)

 GROUP BY owner, segment_type, segment_name

UNION ----table in the index

SELECT owner,

       '*' || segment_name,

       segment_type,

       SUM(bytes / 1024 / 1024) "Size(Mb)"

  FROM dba_segments

 WHERE owner IN (SELECT table_owner

                   FROM dba_indexes

                  WHERE owner IN (SELECT /*+ no_unnest */

                                   object_owner

                                    FROM plan_table)

                    AND index_name IN (SELECT /*+ no_unnest */

                                        object_name

                                         FROM plan_table))

   AND segment_name IN

       (SELECT /*+ no_unnest */

         table_name

          FROM dba_indexes

         WHERE owner IN (SELECT /*+ no_unnest */

                          object_owner

                           FROM plan_table)

           AND index_name IN (SELECT /*+ no_unnest */

                               object_name

                                FROM plan_table))

 GROUP BY owner, segment_type, segment_name

 ORDER BY 3, 4;
推荐阅读:
  1. 查询DB表实际大小
  2. 查询oracle数据中所有表的大小

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

oracle 性能优化

上一篇:Python基于当前时间怎么批量创建文件

下一篇:Mongodb如何实现打卡签到系统

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》