搜索
首页数据库mysql教程Oracle 中的动态采样(dynamic sampling)相关示例

1.1首先回顾下动态采样(dynamic sampling)的相关知识点 这个特性,使数据库随机的扫描表中少量的block,用来增强数据库的统计信息。 1.1.1 目的 动态采样增加了那些丢失的或者不足的优化器统计信息。使用动态采样可以让优化器更好的选择谓词。动态采样能够

1.1首先回顾下动态采样(dynamic sampling)的相关知识点

这个特性,使数据库随机的扫描表中少量的block,用来增强数据库的统计信息。

1.1.1 目的

动态采样增加了那些丢失的或者不足的优化器统计信息。使用动态采样可以让优化器更好的选择谓词。动态采样能够补充类似表中block个数,相关的索引block个数,表的集势(ronded个数),相关的连接列的统计信息(提供extendedstatistics的功能)。

1.1.2 动态采样概念

动态采样默认为启动状态,可以设置OPTIMIZER_DYNAMIC_SAMPLING=0来禁用掉这一特性。

OPTIMIZER_DYNAMIC_SAMPLING也是和动态采样最重要的参数,它控制着动态采样级别。

1.1.3 OPTIMIZER_DYNAMIC_SAMPLING动态参数说明

OPTIMIZER_DYNAMIC_SAMPLING

Property

Description

Parameter type

Integer

Default value

If OPTIMIZER_FEATURES_ENABLE is set to 10.0.0 or higher, then 2

If OPTIMIZER_FEATURES_ENABLE is set to 9.2.0, then 1

If OPTIMIZER_FEATURES_ENABLE is set to 9.0.1 or lower, then 0

Modifiable

ALTER SESSIONALTER SYSTEM

Range of values

0 to 10

 

 

Dynamic Sampling Levels

 Oracle 中的动态采样(dynamic sampling)相关示例

10g以上oracle database 的OPTIMIZER_DYNAMIC_SAMPLING参数默认值为2。

 

1.2 应用场景

下面列举3个动态采样的典型应用场景

1.2.1    缺失统计信息

当查询中的一个或者多个表没有统计信息,那么优化器就会收集关于表的基本信息用来执行优化操作。

 

1.创建表

 

 

dexter@DAVID> create table tuning8_tab1nologging as

  2  select level as id , 'name'|| level as name

  3  from dual

  4  connect by level

 

Table created.

2.创建索引

_dexter@DAVID> create indexidx_tuning8_tab1_id on tuning8_tab1(id) ;

 

Index created.

3.查询测试

先看一下参数的设置

_dexter@DAVID> show parameter samp

 

NAME                                 TYPE        VALUE

----------------------------------------------- ------------------------------

optimizer_dynamic_sampling           integer     2

 

 

_dexter@DAVID> select * from tuning8_tab1where id=2 ;

 

       ID NAME

---------- --------------------------------------------

        2 name2

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 3712969662

 

---------------------------------------------------------------------------------------------------

| Id  | Operation                   | Name                | Rows  | Bytes | Cost (%CPU)| Time     |

---------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                     |     1 |   37 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID|TUNING8_TAB1        |     1 |   37 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_TUNING8_TAB1_ID |     1 |      |     1   (0)| 00:00:01 |

---------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -access("ID"=2)

 

Note

-----

   -dynamic sampling used for this statement (level=2)

 

 

Statistics

----------------------------------------------------------

         0  recursive calls

         0  db block gets

         4  consistent gets

         3  physical reads

         0  redo size

       596  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

1 rows processed

 

 

动态采样已经起作用了。

 

 

 

1.2.2    缺失extendedstatistics

 

oracle提供相关性统计信息,这里简单演示了一种情况,说明动态采样可以使oracle数据库更加智能的选择查询计划,进而提升性能。(其实使用dbms_stats设置特定的参数一样可以达到这种目的)

 

1. 基于all_objects视图创建表

 

create table tect9_tab2 nologging

as select decode( mod(rownum,2), 0, 'D', 'R' )col1,

decode( mod(rownum,2), 0, 'R', 'D' ) col2, t.*

from all_objects t

2. 创建复合索引

create index idx_comp_tect9_tab2_col1_col2 ontect9_tab2(col1,col2) ;

 

3. 收集统计信息

execdbms_stats.gather_table_stats(user,'tect9_tab2',method_opt=>'for all indexedcolumns size 254' );

 

dexter@STARTREK> execdbms_stats.gather_table_stats(user,'tect9_tab2',method_opt=>'for all indexedcolumns size 254' );

 

PL/SQL procedure successfully completed.

 

 

4. 查询测试

数据总量为72566

dexter@STARTREK> select count(*) fromtect9_tab2 ;

 

 COUNT(*)

----------

    72566

 

已经收集了统计信息,所以常规的查询都可以得到正确的执行计划。

 

 

dexter@STARTREK> select * from tect9_tab2where col1='D' ;

 

Execution Plan

----------------------------------------------------------

Plan hash value: 3262335044

 

--------------------------------------------------------------------------------

| Id  |Operation         | Name       | Rows | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------

|   0 |SELECT STATEMENT  |            | 35484 |  3499K|  302   (1)| 00:00:01 |

|*  1|  TABLE ACCESS FULL| TECT9_TAB2 | 35484|  3499K|   302  (1)| 00:00:01 |

--------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   1 -filter("COL1"='D')

这里也是正确的

dexter@STARTREK> select * from tect9_tab2where col1='D' and col2='R' ;

 

Execution Plan

----------------------------------------------------------

Plan hash value: 3262335044

 

--------------------------------------------------------------------------------

| Id  |Operation         | Name       | Rows | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------

|   0 |SELECT STATEMENT  |            | 17348 |  1711K|  301   (1)| 00:00:01 |

|*  1|  TABLE ACCESS FULL| TECT9_TAB2 | 17348|  1711K|   301  (1)| 00:00:01 |

--------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   1 -filter("COL2"='R' AND "COL1"='D')

 

这里按照常理来说是正确的,但是在本环境中,oracle其实有更智能的一面:

因为col1和col2 之间有关联,col1=’D’的时候col2=’D’的记录是没有的,但是这里预计的条数为18133条,预计错误,oracle是否有更智能的选择呢?

dexter@STARTREK> select * from tect9_tab2where col1='D' and col2='D' ;

 

Execution Plan

----------------------------------------------------------

Plan hash value: 3262335044

 

--------------------------------------------------------------------------------

| Id  |Operation         | Name       | Rows | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------

|   0 |SELECT STATEMENT  |            | 18133 |  1788K|  302   (1)| 00:00:01 |

|*  1|  TABLE ACCESS FULL| TECT9_TAB2 | 18133|  1788K|   302  (1)| 00:00:01 |

--------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   1 -filter("COL1"='D' AND "COL2"='D')

 

 

 

5. using Dynamic Samping

可以看到,使用动态采样,虽然预计得到的条数为但是已经比较接近真实环境了,这里选择索引扫描作为access path。

 

select /*+ dynamic_sampling(t 2) */ * fromtect9_tab2 t where col1='D' and col2='D' ;

 

dexter@STARTREK> select /*+dynamic_sampling(t 2) */ * from tect9_tab2 t where col1='D' and col2='D' ;

 

Execution Plan

----------------------------------------------------------

Plan hash value: 1707542874

 

-------------------------------------------------------------------------------------------------------------

| Id  | Operation                   | Name                          | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                               |     5 |  505 |     2   (0)| 00:00:01 |

|   1 | TABLE ACCESS BY INDEX ROWID| TECT9_TAB2                    |     5 |  505 |     2   (0)| 00:00:01 |

|*  2 |  INDEX RANGE SCAN          |IDX_COMP_TECT9_TAB2_COL1_COL2 |     5 |       |    1   (0)| 00:00:01 |

-------------------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -access("COL1"='D' AND "COL2"='D')

 

Note

-----

   -dynamic sampling used for this statement (level=2)

  

 

 

 

 

 

1.2.3    对于一个经常大规模被修改的表使用动态采样

 

如果一个表中的数据,经常执行大批量的加载或者更新,那么在每一次加载或者更新操作后都需要手动的执行收集统计信息的操作。

因为如果不手动的收集,因为统计信息过旧,优化器可能会选择效率较差的access path,影响效率。

其实还有另外一种做法可以避免这样的事情发生,那就是使用动态采样特性。

当一个表没有统计信息的时候,oracle数据库就会使用动态采样来协助优化器。所以对于上述的环境中,就可以删除、并且锁定表的统计信息。这样每次执行查询操作的时候,动态采样的特性都会被使用。

 

下面给出示例:

 

1.创建表

 

_dexter@DAVID> create table tuning8_tab3nologging

  2  as

  3  select level as id , 'name'||level as name

  4  from dual

  5  connect by level

 

Table created.

2.创建索引

_dexter@DAVID> create indexidx_tuning8_tab3_id on tuning8_tab3(id) ;

 

Index created.

3.收集统计信息

_dexter@DAVID> @gather_tab

Enter value for tbname: tuning8_tab3

 

PL/SQL procedure successfully completed.

 

 

4.查询测试

_dexter@DAVID>

_dexter@DAVID>

_dexter@DAVID> set autotrace on

_dexter@DAVID> select * from tuning8_tab3where id=1 ;

 

       ID NAME

------------------------------------------------------

        1 name1

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 1647674320

 

---------------------------------------------------------------------------------------------------

| Id  | Operation                   | Name                | Rows  | Bytes | Cost (%CPU)| Time     |

---------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                     |     1 |   13 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID|TUNING8_TAB3        |     1 |   13 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_TUNING8_TAB3_ID |     1 |      |     1   (0)| 00:00:01 |

---------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -access("ID"=1)

 

 

Statistics

----------------------------------------------------------

         1  recursive calls

         0  db block gets

          4 consistent gets

         0  physical reads

         0  redo size

       596  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

非常正常,优化器选择了最优的accesspath 。

 

5.加载数据

 

_dexter@DAVID> insert into tuning8_tab3select 10 , 'namess' from dual connect by level

 

50000 rows created.

 

_dexter@DAVID> commit ;

 

Commit complete.

 

6.查询测试

 

可以看到,优化器选择了索引扫描作为accesspath。

_dexter@DAVID> select count(name) fromtuning8_tab3 where id=10 ;

 

COUNT(NAME)

-----------

     50001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 2464990924

 

----------------------------------------------------------------------------------------------------

| Id  | Operation                    | Name                | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT             |                     |     1 |   13 |     2   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |                     |     1 |   13 |            |          |

|   2 |   TABLE ACCESS BY INDEX ROWID|TUNING8_TAB3        |     1 |   13 |     2   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_TUNING8_TAB3_ID |     1 |      |     1   (0)| 00:00:01 |

----------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   3 -access("ID"=10)

 

 

Statistics

----------------------------------------------------------

         0  recursive calls

         0  db block gets

        414 consistent gets

         0  physical reads

     11588  redo size

       531  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

          1 rows processed

 

但是其实全表扫描才是最优的

 

_dexter@DAVID> select /*+full(tuning8_tab3) */ count(name) from tuning8_tab3 where id=10 ;

 

COUNT(NAME)

-----------

     50001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 926892911

 

-----------------------------------------------------------------------------------

| Id  |Operation          | Name         | Rows | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |              |     1 |   13 |    10   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE    |              |     1 |   13 |            |          |

|*  2 |   TABLE ACCESS FULL| TUNING8_TAB3 |     1 |   13 |    10   (0)| 00:00:01 |

-----------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=10)

 

 

Statistics

----------------------------------------------------------

         1  recursive calls

         1  db block gets

        204  consistent gets

         0  physical reads

       176  redo size

       531  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

7.解决方法

7.1每次加载后收集统计信息

问题已经出现了,当然在每次大规模加载数据后,可以收集一次表的统计信息。

 

_dexter@DAVID> @gather_tab

Enter value for tbname: tuning8_tab3

 

PL/SQL procedure successfully completed.

 

_dexter@DAVID> select count(name) fromtuning8_tab3 where id=10 ;

 

COUNT(NAME)

-----------

     50001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 926892911

 

-----------------------------------------------------------------------------------

| Id  | Operation          | Name         | Rows | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |              |     1 |   10 |    69   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE    |              |     1 |   10 |            |          |

|*  2 |   TABLE ACCESS FULL| TUNING8_TAB3 | 50079|   489K|    69  (0)| 00:00:01 |

-----------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=10)

 

 

Statistics

----------------------------------------------------------

         0  recursive calls

         0  db block gets

       268  consistent gets

         0  physical reads

         0  redo size

       531  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

7.2.使用动态采样

 

当然还有另外一种方法,那就是今天要说的,使用动态采样的特性。

 

 

 

 

BEGIN

 DBMS_STATS.DELETE_TABLE_STATS(user,'tuning8_tab3');

 DBMS_STATS.LOCK_TABLE_STATS(user,'tuning8_tab3');

END;

/

 

删除统计信息,并且锁定表的统计信息

 

_dexter@DAVID> BEGIN

  2    DBMS_STATS.DELETE_TABLE_STATS(user,'tuning8_tab3');

 DBMS_STATS.LOCK_TABLE_STATS(user,'tuning8_tab3');

  4  END;

  5  /

 

PL/SQL procedure successfully completed.

 

这样优化器通常情况下都会产生较正确的查询计划。

 

_dexter@DAVID> select count(name) fromtuning8_tab3 where id=10 ;

 

COUNT(NAME)

-----------

     50001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 926892911

 

-----------------------------------------------------------------------------------

| Id  |Operation          | Name         | Rows | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |              |     1 |   37 |    70   (2)| 00:00:01 |

|   1 |  SORT AGGREGATE    |              |     1 |   37 |            |          |

|*  2 |   TABLE ACCESS FULL| TUNING8_TAB3 | 57162|  2065K|    70  (2)| 00:00:01 |

-----------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=10)

 

Note

-----

   -dynamic sampling used for this statement (level=2)

 

 

Statistics

----------------------------------------------------------

        52  recursive calls

         0  db block gets

        278  consistent gets

         0  physical reads

         0  redo size

       531  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

 

8.再次加载数据测试

就算再次加载数据。

 

 

_dexter@DAVID> insert into tuning8_tab3select 9 , 'namess' from dual connect by level

 

100000 rows created.

 

_dexter@DAVID> commit ;

 

Commit complete.

 

依然会产生最优的查询计划,保证了效率。

 

_dexter@DAVID> select count(name) fromtuning8_tab3 where id=9 ;

 

COUNT(NAME)

-----------

    100001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 926892911

 

-----------------------------------------------------------------------------------

| Id  | Operation          | Name         | Rows | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |              |     1 |   37 |   105   (2)| 00:00:02 |

|   1 |  SORT AGGREGATE    |              |     1 |   37 |            |          |

|*  2 |   TABLE ACCESS FULL|TUNING8_TAB3 |   135K|  4879K|  105   (2)| 00:00:02 |

-----------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=9)

 

Note

-----

   -dynamic sampling used for this statement (level=2)

 

 

Statistics

----------------------------------------------------------

         8  recursive calls

         1  db block gets

        498 consistent gets

         0  physical reads

       880  redo size

       531  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

可以看到,全表扫描的效率明显低于优化器选择的索引扫描的效率。

 

_dexter@DAVID> select /*+index(tuning8_tab3 idx_tuning8_tab3_id)*/ count(name) from tuning8_tab3 where id=9 ;

 

COUNT(NAME)

-----------

    100001

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 2464990924

 

----------------------------------------------------------------------------------------------------

| Id  | Operation                    | Name                | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT             |                     |     1 |   37 |   826   (0)| 00:00:10 |

|   1 |  SORT AGGREGATE              |                     |     1 |   37 |            |          |

|   2 |   TABLE ACCESS BY INDEX ROWID|TUNING8_TAB3        |   135K| 4879K|   826   (0)| 00:00:10 |

|*  3 |    INDEX RANGE SCAN          | IDX_TUNING8_TAB3_ID |   135K|      |   363   (0)| 00:00:05 |

----------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   3 -access("ID"=9)

 

Note

-----

   -dynamic sampling used for this statement (level=2)

 

 

Statistics

----------------------------------------------------------

         7  recursive calls

         0  db block gets

       972  consistent gets

         0  physical reads

     25252  redo size

       531  bytes sent via SQL*Net to client

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

当然对于一些对查询计划要求比较高的地方,不建议使用这种方法,特别是olap系统,因为动态采样只是一个折中的收集统计信息的方法,并不像使用dbms_stats包那样准确,也有可能生成错误的执行计划,就像下面的1.3示例一样。

 

 

 

1.3 表分析与动态采样

 

表分析(使用dbms_Stats)可以提供较高品质的统计信息,而动态采样则是一个折中方案,只能提供粗粒度的统计信息,所以对于一些对统计信息要求较高的查询中,因为统计信息缺失而使用动态采样是无法保证优化器选择最优的执行计划。

 

如下例所示:

 

1.初始化10w数据tuning8_tab2

 

_dexter@DAVID> create table tuning8_tab2nologging as

  2      select level as id , 'name'|| level asname

  3      from dual

  4      connect by level

 

Table created.

 

2.创建索引

 

_dexter@DAVID> create indexidx_tuning8_tab2_id on tuning8_tab2 (id) ;

 

Index created.

 

3.更新数据,总数10w,id=10的数据3w条

 

_dexter@DAVID> update tuning8_tab2 setid=10 where id > 40000 and id

 

29999 rows updated.

 

 

_dexter@DAVID> commit ;

 

Commit complete.

 

4.查询测试

默认没有统计信息,使用动态采样,此时选择的是全表扫描,consistantgets=356

但是其实最优的access path 应该是索引扫描。

 

_dexter@DAVID> select count(*) fromtuning8_tab2 where id=10 ;

 

 COUNT(*)

----------

    30000

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 2380771210

 

-----------------------------------------------------------------------------------

| Id  | Operation          | Name         | Rows | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |              |     1 |   13 |    81   (2)| 00:00:01 |

|   1 |  SORT AGGREGATE    |              |     1 |   13 |            |          |

|*  2 |   TABLE ACCESS FULL| TUNING8_TAB2 | 33120 |   420K|   81   (2)| 00:00:01 |

-----------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=10)

 

Note

-----

   - dynamic samplingused for this statement (level=2)

 

 

Statistics

----------------------------------------------------------

         7  recursive calls

         0  db block gets

        356 consistent gets

         0  physical reads

         0  redo size

       526  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

5.收集统计信息

_dexter@DAVID> @gather_tab

Enter value for tbname: tuning8_tab2

 

PL/SQL procedure successfully completed.

 

 

再次查询,此时使用的是索引快速扫描,consistent gets297

 

_dexter@DAVID> select count(*) fromtuning8_tab2 where id=10 ;

 

 COUNT(*)

----------

    30000

 

 

Execution Plan

----------------------------------------------------------

Plan hash value: 2673526969

 

---------------------------------------------------------------------------------------------

| Id  | Operation             | Name                | Rows  | Bytes | Cost (%CPU)| Time     |

---------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT      |                     |     1 |    5 |    73   (2)| 00:00:01 |

|   1 |  SORT AGGREGATE       |                     |     1 |    5 |            |          |

|*  2 |   INDEX FAST FULL SCAN|IDX_TUNING8_TAB2_ID | 29921 |  146K|    73   (2)| 00:00:01 |

---------------------------------------------------------------------------------------------

 

Predicate Information (identified by operationid):

---------------------------------------------------

 

   2 -filter("ID"=10)

 

 

Statistics

----------------------------------------------------------

         0  recursive calls

         0  db block gets

        297  consistent gets

         0  physical reads

         0  redo size

       526  bytes sent via SQL*Net toclient

       523  bytes received via SQL*Netfrom client

         2  SQL*Net roundtrips to/fromclient

         0  sorts (memory)

         0  sorts (disk)

         1  rows processed

 

 

 

上面只是一个比较粗劣的实验,查询也比较简单。对于像olap这种对查询计划要求比较高,查询计划非常复杂的数据库,尽量保持统计信息的实时性是非常有必要的。

 


声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
您如何在MySQL中创建和管理用户帐户?您如何在MySQL中创建和管理用户帐户?Apr 22, 2025 pm 06:05 PM

在MySQL中创建和管理用户账户的步骤如下:1.创建用户:使用CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';2.分配权限:使用GRANTSELECT,INSERT,UPDATEONmydatabase.TO'newuser'@'localhost';3.修正权限错误:使用REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost';然后重新分配权限;4.优化权限:使用SHOWGRA

MySQL与Oracle有何不同?MySQL与Oracle有何不同?Apr 22, 2025 pm 05:57 PM

MySQL适合快速开发和中小型应用,Oracle适合大型企业和高可用性需求。1)MySQL开源、易用,适用于Web应用和中小型企业。2)Oracle功能强大,适合大型企业和政府机构。3)MySQL支持多种存储引擎,Oracle提供丰富的企业级功能。

与其他关系数据库相比,使用MySQL的缺点是什么?与其他关系数据库相比,使用MySQL的缺点是什么?Apr 22, 2025 pm 05:49 PM

MySQL相比其他关系型数据库的劣势包括:1.性能问题:在处理大规模数据时可能遇到瓶颈,PostgreSQL在复杂查询和大数据处理上表现更优。2.扩展性:水平扩展能力不如GoogleSpanner和AmazonAurora。3.功能限制:在高级功能上不如PostgreSQL和Oracle,某些功能需要更多自定义代码和维护。

您如何在MySQL中执行加入操作?您如何在MySQL中执行加入操作?Apr 22, 2025 pm 05:41 PM

MySQL支持四种JOIN类型:INNERJOIN、LEFTJOIN、RIGHTJOIN和FULLOUTERJOIN。1.INNERJOIN用于匹配两个表中的行并返回符合条件的结果。2.LEFTJOIN返回左表的所有行,即使右表没有匹配。3.RIGHTJOIN与LEFTJOIN相反,返回右表的所有行。4.FULLOUTERJOIN返回两表中所有符合或不符合条件的行。

MySQL的性能与高负载下的其他RDBM相比如何?MySQL的性能与高负载下的其他RDBM相比如何?Apr 22, 2025 pm 05:37 PM

MySQL在高负载下的性能与其他RDBMS相比各有优劣。1)MySQL通过InnoDB引擎和优化策略如索引、查询缓存和分区表在高负载下表现良好。2)PostgreSQL通过MVCC机制提供高效并发读写,Oracle和MicrosoftSQLServer则通过各自的优化策略提升性能。通过合理的配置和优化,MySQL可以在高负载环境中表现出色。

解释InnoDB缓冲池及其对性能的重要性。解释InnoDB缓冲池及其对性能的重要性。Apr 19, 2025 am 12:24 AM

InnoDBBufferPool通过缓存数据和索引页来减少磁盘I/O,提升数据库性能。其工作原理包括:1.数据读取:从BufferPool中读取数据;2.数据写入:修改数据后写入BufferPool并定期刷新到磁盘;3.缓存管理:使用LRU算法管理缓存页;4.预读机制:提前加载相邻数据页。通过调整BufferPool大小和使用多个实例,可以优化数据库性能。

MySQL与其他编程语言:一种比较MySQL与其他编程语言:一种比较Apr 19, 2025 am 12:22 AM

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。 MySQL以其高性能、可扩展性和跨平台支持着称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

学习MySQL:新用户的分步指南学习MySQL:新用户的分步指南Apr 19, 2025 am 12:19 AM

MySQL值得学习,因为它是强大的开源数据库管理系统,适用于数据存储、管理和分析。1)MySQL是关系型数据库,使用SQL操作数据,适合结构化数据管理。2)SQL语言是与MySQL交互的关键,支持CRUD操作。3)MySQL的工作原理包括客户端/服务器架构、存储引擎和查询优化器。4)基本用法包括创建数据库和表,高级用法涉及使用JOIN连接表。5)常见错误包括语法错误和权限问题,调试技巧包括检查语法和使用EXPLAIN命令。6)性能优化涉及使用索引、优化SQL语句和定期维护数据库。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具