文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

11g sort merge join

2024-04-02 19:55

关注

测试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
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯