|
在另一个磁盘新建表空间测试
SQL> conn / as sysdba
已连接。
SQL> create tablespace ts datafile 'e:\temp\ts.dbf' size 100M;
表空间已创建。
已用时间: 00: 00: 00.50
SQL> alter user scott default tablespace ts quota unlimited on ts;
用户已更改。
已用时间: 00: 00: 00.01
SQL> conn scott/tiger
已连接。
SQL> create table big(id int,a int,b int);
表已创建。
已用时间: 00: 00: 00.02
SQL> create table e(a int);
表已创建。
已用时间: 00: 00: 00.01
SQL> insert into big select level l,mod(level,7),mod(level,29) from dual connect by level<=1e6;
已创建 1000000 行。
已用时间: 00: 00: 02.96
SQL> insert into e select mod(level,13)from dual connect by level<=1e4;
已创建 10000 行。
已用时间: 00: 00: 00.04
SQL> commit;
提交完成。
已用时间: 00: 00: 00.00
SQL>
SQL> set autot on
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错
SQL>
SQL> select b.b,
2 max(b.id) , /*很快*/
3 min(b.id) min_used
4 from big b,
5 (select distinct e.a
6 from e
7 where e.a like '1%') m
8 where b.a>=3
9 and b.a<=4
10 and b.b= m.a
11 group by b.b;
B MAX(B.ID) MIN_USED
-------------------- -------------------- --------------------
1 999863 59
10 999988 10
11 999989 11
12 999961 157
已用时间: 00: 00: 00.41
执行计划
----------------------------------------------------------
Plan hash value: 375847392
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 70M| 3482M| 991 (38)| 00:00:12 |
| 1 | SORT GROUP BY NOSORT | | 70M| 3482M| 991 (38)| 00:00:12 |
| 2 | MERGE JOIN | | 70M| 3482M| 991 (38)| 00:00:12 |
| 3 | SORT JOIN | | 296K| 11M| 639 (4)| 00:00:08 |
| 4 | VIEW | VW_GBC_5 | 296K| 11M| 639 (4)| 00:00:08 |
| 5 | HASH GROUP BY | | 296K| 11M| 639 (4)| 00:00:08 |
|* 6 | TABLE ACCESS FULL| BIG | 296K| 11M| 626 (2)| 00:00:08 |
|* 7 | SORT JOIN | | 3077 | 40001 | 8 (13)| 00:00:01 |
|* 8 | TABLE ACCESS FULL | E | 3077 | 40001 | 7 (0)| 00:00:01 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - filter("B"."A"<=4 AND "B"."A">=3)
7 - access("ITEM_1"="E"."A")
filter("ITEM_1"="E"."A")
8 - filter(TO_CHAR("E"."A") LIKE '1%')
Note
-----
- dynamic sampling used for this statement (level=2)
SQL>
SQL> select b.b,
2 max(b.id) - /*很慢*/
3 min(b.id) min_used
4 from big b,
5 (select distinct e.a
6 from e
7 where e.a like '1%') m
8 where b.a>=3
9 and b.a<=4
10 and b.b= m.a
11 group by b.b;
B MIN_USED
-------------------- --------------------
11 999978
1 999804
10 999978
12 999804
已用时间: 00: 00: 09.63
执行计划
----------------------------------------------------------
Plan hash value: 2033372611
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 31M| 1561M| 2525 (76)| 00:00:31 |
| 1 | HASH GROUP BY | | 31M| 1561M| 2525 (76)| 00:00:31 |
|* 2 | HASH JOIN | | 31M| 1561M| 789 (22)| 00:00:10 |
|* 3 | TABLE ACCESS FULL| E | 3077 | 40001 | 7 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| BIG | 296K| 11M| 627 (3)| 00:00:08 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"."B"="E"."A")
3 - filter(TO_CHAR("E"."A") LIKE '1%')
4 - filter("B"."A">=3 AND "B"."A"<=4)
Note
-----
- dynamic sampling used for this statement (level=2)
SQL>
SQL> exec dbms_stats.gather_table_stats(ownname => 'scott',tabname => 'big',estimate_percent => 100,method_opt=> 'for all columns') ;
PL/SQL 过程已成功完成。
已用时间: 00: 00: 06.22
SQL>
SQL> exec dbms_stats.gather_table_stats(ownname => 'scott',tabname => 'e',estimate_percent => 100,method_opt=> 'for all columns') ;
PL/SQL 过程已成功完成。
已用时间: 00: 00: 00.02
SQL>
SQL>
SQL>
SQL> select b.b,
2 max(b.id) , /*很快*/
3 min(b.id) min_used
4 from big b,
5 (select distinct e.a
6 from e
7 where e.a like '1%') m
8 where b.a>=3
9 and b.a<=4
10 and b.b= m.a
11 group by b.b;
B MAX(B.ID) MIN_USED
-------------------- -------------------- --------------------
1 999863 59
10 999988 10
11 999989 11
12 999961 157
已用时间: 00: 00: 00.30
执行计划
----------------------------------------------------------
Plan hash value: 69571800
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 13 | 182 | 644 (4)| 00:00:08 |
| 1 | HASH GROUP BY | | 13 | 182 | 644 (4)| 00:00:08 |
|* 2 | HASH JOIN | | 128K| 1751K| 638 (3)| 00:00:08 |
| 3 | VIEW | VW_GBF_5 | 13 | 39 | 8 (13)| 00:00:01 |
| 4 | HASH GROUP BY | | 13 | 39 | 8 (13)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| E | 500 | 1500 | 7 (0)| 00:00:01 |
|* 6 | TABLE ACCESS FULL | BIG | 285K| 3069K| 628 (3)| 00:00:08 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"."B"="ITEM_1")
5 - filter(TO_CHAR("E"."A") LIKE '1%')
6 - filter("B"."A">=3 AND "B"."A"<=4)
SQL>
SQL> select b.b,
2 max(b.id) - /*很慢*/
3 min(b.id) min_used
4 from big b,
5 (select distinct e.a
6 from e
7 where e.a like '1%') m
8 where b.a>=3
9 and b.a<=4
10 and b.b= m.a
11 group by b.b;
B MIN_USED
-------------------- --------------------
11 999978
1 999804
10 999978
12 999804
已用时间: 00: 00: 09.71
执行计划
----------------------------------------------------------
Plan hash value: 2033372611
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 13 | 182 | 903 (32)| 00:00:11 |
| 1 | HASH GROUP BY | | 13 | 182 | 903 (32)| 00:00:11 |
|* 2 | HASH JOIN | | 4926K| 65M| 660 (6)| 00:00:08 |
|* 3 | TABLE ACCESS FULL| E | 500 | 1500 | 7 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| BIG | 285K| 3069K| 628 (3)| 00:00:08 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"."B"="E"."A")
3 - filter(TO_CHAR("E"."A") LIKE '1%')
4 - filter("B"."A">=3 AND "B"."A"<=4)
SQL>
|
|