>데이터 베이스 >MySQL 튜토리얼 >Oracle中的merge join Cartesian

Oracle中的merge join Cartesian

WBOY
WBOY원래의
2016-06-07 17:00:301139검색

在执行计划中,有时会出现CARTESIAN笛卡尔乘积,简单的说一下什么叫cartesian?就是有两个集合,每个集合的任意一个成员都要与另外

在执行计划中,有时会出现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的执行效率可能会很低,对于系统的隐藏参数,一般不应该改变。

linux

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.