Merge join Cartesian in Oracle

Source: Internet
Author: User

In the Execution Plan, the CARTESIAN cartesian Product sometimes appears. Simply put, What Is CARTESIAN? There are two sets. Any member of each set must be associated with any member of another set... below are some experiments on 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>

If merge join Cartesian is not allowed, you can set the implicit parameter "_ 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.

Disable Cartesian product throughout the system level

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

When merge join Cartesian occurs, the SQL Execution efficiency may be very low. The hidden parameters of the system should not be changed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.