在执行计划中,有时会出现cartesian笛卡尔乘积,简单的说一下什么叫cartesian?就是有两个集合,每个集合的任意一个成员都要与另外一个集合的任意一个成员有关联...下面是关于cartesian的一些实验:
sql> set linesize 2000
sql> select * from tab;
tname tabtype clusterid
------------------------------ ------- ----------
t table
rep_t_log table
sql> select * from t,rep_t_log
execution plan
----------------------------------------------------------
plan hash value: 2235198130
----------------------------------------------------------------------------------
| id | operation | name | rows | bytes | cost (%cpu)| time |
----------------------------------------------------------------------------------
| 0 | select statement | | 20000 | 429k| 16 (7)| 00:00:01 |
| 1 | merge join cartesian| | 20000 | 429k| 16 (7)| 00:00:01 |
| 2 | table access full | rep_t_log | 2 | 30 | 3 (0)| 00:00:01 |
| 3 | buffer sort | | 10000 | 70000 | 13 (8)| 00:00:01 |
| 4 | table access full | t | 10000 | 70000 | 6 (0)| 00:00:01 |
----------------------------------------------------------------------------------
note
-----
- dynamic sampling used for this statement
sql>
如果强制不允许merge join cartesian出现,可以通过设置隐含参数“_optimizer_mjc_enabled”
sql> alter session set _optimizer_mjc_enabled = false;
session altered.
sql> select * from t,rep_t_log;
execution plan
----------------------------------------------------------
plan hash value: 4018263157
--------------------------------------------------------------------------------
| id | operation | name | rows | bytes | cost (%cpu)| time |
--------------------------------------------------------------------------------
| 0 | select statement | | 20000 | 429k| 16 (7)| 00:00:01 |
| 1 | nested loops | | 20000 | 429k| 16 (7)| 00:00:01 |
| 2 | table access full| rep_t_log | 2 | 30 | 3 (0)| 00:00:01 |
| 3 | table access full| t | 10000 | 70000 | 6 (0)| 00:00:01 |
--------------------------------------------------------------------------------
note
-----
- dynamic sampling used for this statement
sql> conn / as sysdba
connected.
在整个系统级禁用笛卡尔乘积
sql> alter system set _optimizer_mjc_enabled = false;
system altered.
sql> conn test/test
connected.
sql> set autotrace trace exp
sql> select * from t,rep_t_log;
execution plan
----------------------------------------------------------
plan hash value: 4018263157
--------------------------------------------------------------------------------
| id | operation | name | rows | bytes | cost (%cpu)| time |
--------------------------------------------------------------------------------
| 0 | select statement | | 20000 | 429k| 16 (7)| 00:00:01 |
| 1 | nested loops | | 20000 | 429k| 16 (7)| 00:00:01 |
| 2 | table access full| rep_t_log | 2 | 30 | 3 (0)| 00:00:01 |
| 3 | table access full| t | 10000 | 70000 | 6 (0)| 00:00:01 |
--------------------------------------------------------------------------------
note
-----
- dynamic sampling used for this statement
当出现merge join cartesian时,,sql的执行效率可能会很低,对于系统的隐藏参数,一般不应该改变。
