11g sort merge join
admin
2023-04-21 04:42:25
0

测试sort merge join

When the Optimizer Considers Sort Merge Joins

A hash join requires one hash table and one probe of this table, whereas a sort merge join requires two sorts.

The optimizer may choose a sort merge join over a hash join for joining large amounts of data when any of the following conditions is true:

The join condition between two tables is not an equijoin, that is, uses an inequality condition such as <, <=, >, or >=.

In contrast to sort merges, hash joins require an equality condition.

Because of sorts required by other operations, the optimizer finds it cheaper to use a sort merge.

If an index exists, then the database can avoid sorting the first data set. However, the database always sorts the second data set, regardless of indexes.
SQL> create table t1 (id number);

Table created.

SQL> create table t2 (id number);

Table created.

SQL> insert into t1 values(2);

1 row created.

SQL> insert into t1 values(1);

1 row created.

SQL> insert into t1 values(5);

1 row created.

SQL> insert into t1 values(3);

1 row created.

SQL> commit;

SQL> select * from t1;

        ID
----------
         2
         1
         5
         3

SQL> insert into t2 values(11);

1 row created.

SQL> insert into t2 values(9);

1 row created.

SQL> insert into t2 values(1);

1 row created.

SQL> commit;

SQL> select * from t2;

        ID
----------
        11
         9
         1

SQL> 

SQL> exec dbms_stats.gather_table_stats('SYS','T1');

PL/SQL procedure successfully completed.

SQL> exec dbms_stats.gather_table_stats('SYS','T2');

PL/SQL procedure successfully completed.

SQL> set autot off
SQL> create index ind_id on t1(Id);

Index created.

SQL> set autot traceonly
SQL> select * from t1,t2 where t1.id>t2.id;

Execution Plan
----------------------------------------------------------
Plan hash value: 1335671014

------------------------------------------------------------------------------
| Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |        |     2 |    12 |     4  (25)| 00:00:01 |
|   1 |  MERGE JOIN         |        |     2 |    12 |     4  (25)| 00:00:01 |
|   2 |   SORT JOIN         |        |     4 |    12 |     1   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN  | IND_ID |     4 |    12 |     1   (0)| 00:00:01 |
|*  4 |   SORT JOIN         |        |     3 |     9 |     3  (34)| 00:00:01 |
|   5 |    TABLE ACCESS FULL| T2     |     3 |     9 |     2   (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access(INTERNAL_FUNCTION("T1"."ID")>INTERNAL_FUNCTION("T2"."ID"))
       filter(INTERNAL_FUNCTION("T1"."ID")>INTERNAL_FUNCTION("T2"."ID"))

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          3  consistent gets
          0  physical reads
          0  redo size
        652  bytes sent via SQL*Net to client
        519  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          3  rows processed

相关内容

热门资讯

著名作曲家在沈病逝!《十五的月... 12月29日,著名作曲家铁源在沈阳因病逝世,代表作《十五的月亮》《在那桃花盛开的地方》家喻户晓。铁源...
玩家分享攻略“决胜奕福辅助器?... 家人们!今天小编来为大家解答决胜奕福透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
【特稿】“人工智能时代”领衔德... “人工智能时代”领衔德国年度十大热词 李函林 德国语言协会近日公布2025年度十大热词,其中热度最高...
AI和算力的升级大幅提高了轮式... 一、从“看见”到“看懂” · 传统方式:依赖预先编程的规则和简单的传感器(如磁条、二维码)进行导航,...
【第一财经】“新青鸟拼三张真的... 【第一财经】“新青鸟拼三张真的有挂吗?”(果然有透视挂)您好,新青鸟拼三张这个游戏其实有挂的,确实是...
【今日要闻】“富豪麻将开挂器?... 网上科普关于“富豪麻将有没有挂”话题很是火热,小编也是针对富豪麻将作*弊开挂的方法以及开挂对应的知识...
最新引进“新圣游炸/金/花有没... 家人们!今天小编来为大家解答新圣游炸/金/花透视挂怎么安装这个问题咨询软件客服徽9752949的挂在...
最新引进“新皇豪牛牛到底有挂吗... 最新引进“新皇豪牛牛到底有挂吗?”(必胜开挂神器)您好,新皇豪牛牛这个游戏其实有挂的,确实是有挂的,...
玩家分享攻略“鱼扑克有挂吗?”... 网上科普关于“鱼扑克有没有挂”话题很是火热,小编也是针对鱼扑克作*弊开挂的方法以及开挂对应的知识点,...
最新引进“微乐陕西挖坑开挂器?... 网上科普关于“微乐陕西挖坑有没有挂”话题很是火热,小编也是针对微乐陕西挖坑作*弊开挂的方法以及开挂对...