ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 何为buffer sort?

何为buffer sort?

原创 Linux操作系统 作者:lsq_008 时间:2009-12-21 15:15:23 0 删除 编辑

buffer sort is an optimization -- in this case, it is buffering the results
of
that full scan so as to avoid having to perform. LIOS on the data over and
over
and over in the cartesian join. the data may or may not actually be sorted
for
real.

在进行MERGE JOIN CARTESIAN操作时,有时会产生buffer sort,可以理解为在buffer中的排序:

SQL> create table big tablespace users as select * from dba_objects;

Table created.

SQL> create table small tablespace users as select * from dba_objects where rownum=1;

Table created.

SQL>
SQL>  exec dbms_stats.gather_table_stats(user,'big',cascade=>true);

PL/SQL procedure successfully completed.

SQL>   exec dbms_stats.gather_table_stats(user,'small',cascade=>true);

PL/SQL procedure successfully completed.

SQL> set autot traceonly
SQL> select * from big,small;

9459 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2081875483

------------------------------------------------------------------------------
| Id  | Operation            | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |       |  9459 |  1422K|    32   (0)| 00:00:01 |
|   1 |  MERGE JOIN CARTESIAN|       |  9459 |  1422K|    32   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL  | SMALL |     1 |    70 |     3   (0)| 00:00:01 |
|   3 |   BUFFER SORT        |       |  9459 |   775K|    29   (0)| 00:00:01 |
|   4 |    TABLE ACCESS FULL | BIG   |  9459 |   775K|    29   (0)| 00:00:01 |
------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
        761  recursive calls
          0  db block gets
        223  consistent gets
          0  physical reads
          0  redo size
     448751  bytes sent via SQL*Net to client
       7311  bytes received via SQL*Net from client
        632  SQL*Net roundtrips to/from client
          5  sorts (memory)
          0  sorts (disk)
       9459  rows processed

将隐含参数_optimizer_sortmerge_join_enabled设置为false,可以禁止改操作:

SQL>  alter session set "_optimizer_sortmerge_join_enabled"=false;

Session altered.

SQL>  select * from big,small;

9459 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 53924517

----------------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |  9459 |  1422K|    32   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |       |  9459 |  1422K|    32   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| SMALL |     1 |    70 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL| BIG   |  9459 |   775K|    29   (0)| 00:00:01 |
----------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
        749  consistent gets
          0  physical reads
          0  redo size
     448751  bytes sent via SQL*Net to client
       7311  bytes received via SQL*Net from client
        632  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
       9459  rows processed

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10972173/viewspace-623194/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
十余年大型金融及电信系统数据库管理经验,曾服务于中国建设银行、中国移动。对oracle,mysql数据库有深入了解。 擅长python开发,独立开发了开源数据库自动化监控运维平台Power Monitor。

注册时间:2008-02-29

  • 博文量
    335
  • 访问量
    1369130