查询复杂sql的表的大小

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可以查询出相关表的大小:

SQL> col segment_name for a20
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;

OWNER          SEGMENT_NAME     SEGMENT_TYPE  Size(Mb)
------------------------------ -------------------- ------------------ ----------
SH          COUNTRIES     TABLE      .0625
SH          PRODUCTS      TABLE      .0625
SH          TIMES      TABLE         .5
SH          CUSTOMERS     TABLE         12
SH          SALES      TABLE PARTITION       128

Elapsed: 00:00:05.35

时间: 2024-08-03 08:05:05

查询复杂sql的表的大小的相关文章

检测SQL Server表占用空间大小SQL

检测SQL Server表占用空间大小SQL,要先选择需要查询的数据库,然后点击执行下面脚本. CREATE TABLE #T (NAME nvarchar(200),ROWS char(11),reserved varchar(18) ,Data varchar(18) ,index_size varchar(18) ,Unused varchar(18) ) GO INSERT #T EXEC SP_MSFOREACHTABLE 'EXEC sp_spaceused "?"' SE

用sql统计数据库表的大小

查看mysql数据库大小的四种办法,分别有以下四种:第一种:进去指定schema 数据库(存放了其他的数据库的信息)use information_schema第二种:查询所有数据的大小select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES(http://www.6ddd.com)第三种:查看指定数据库的大小,比如说:数据库apoylselect concat(round(sum(DATA_LENGT

T-SQL实用查询之分析数据库表的大小

IF OBJECT_ID('tempdb..#TB_TEMP_SPACE') IS NOT NULL DROP TABLE #TB_TEMP_SPACE GO CREATE TABLE #TB_TEMP_SPACE( NAME VARCHAR(500) ,ROWS INT ,RESERVED VARCHAR(50) ,DATA VARCHAR(50) ,INDEX_SIZE VARCHAR(50) ,UNUSED VARCHAR(50) ) GO SP_MSFOREACHTABLE 'INSER

MySQL中查询所有数据库占用磁盘空间大小和单个库中所有表的大小的sql语句

查询所有数据库占用磁盘空间大小的SQL语句: select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables group by TABLE_SCHEMA order by data_lengt

SQL多表连接查询

SQL多表连接查询 本文主要列举两张和三张表来讲述多表连接查询. 新建两张表: 表1:student  截图如下: 表2:course  截图如下: (此时这样建表只是为了演示连接SQL语句,当然实际开发中不会这样建表,实际开发中这两个表会有自己不同的主键.) 一.外连接 外连接可分为:左连接.右连接.完全外连接. 1.左连接  left join 或 left outer join SQL语句:select * from student left join course on student.

查询Oracle 数据库中带有lob字段的某一个表的大小

注意:由于lob字段有独立的lob segment来存储,故对于带有lob字段的表,不能仅仅查询dba_segments. 以下脚本来自: How to Compute the Size of a Table containing Outline CLOBs and BLOBs[Article ID 118531.1] 经过修改:改为了NVL(SUM(S.BYTES),0) SQL> col "TOTAL TABLE SIZE" format 99999999999999 ---

SQL中查看数据库各表的大小

SQL中查看数据库各表的大小 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,如何快速的查询数据库中各表中数据的大小. 以下有两种方法供参考: 第一种: create table #t(name varchar(255), rows bigint, reserved varchar(20), data varchar(20), index_size varchar(20), unused varchar(20)) exec sp_MSforeachtable "insert i

SQL联表查询

数据库中最最常用的语法----select.简单的select语法很直白: select column from table where expression: 从((from)存储数据的地方(table)按照(where)一定的条件(expression)查找(select)我要的数据(column); 但是在实际工作中用到的比较多的往往还是多联表查询,所以在这里记下自己学习多联表查询的心得. 首先聊一聊笛卡尔积,这是几乎所有数据库书籍在讲多联表查询时第一个要讲的东西,我等P民也只能是把笛卡尔

查询DB表实际大小

1.查询DB表实际大小(保证clob/blob/nclob lob大字段)  select round(sum(bytes/1024/1024/1024),2) ||'G' from dba_segments where owner='用户'   and segment_name ='表' OR segment_name IN (select SEGMENT_NAME from dba_LOBS where TABLE_NAME='表' and owner='用户'); 如果不是dba用户可以用