Oracle CBO evaluates the amount of like data

Source: Internet
Author: User

In the case of like, there are two forms of writing that are based on a 5% assessment of the total data.

sql> drop table test purge;

sql> CREATE TABLE test as SELECT * from Dba_objects;
sql> exec dbms_stats.gather_table_stats (user, ' test ');
Sql> Select COUNT (1) from test;
COUNT (1)
----------

79747

Sql> Select COUNT (1) from the test where object_name like ' test% ';
COUNT (1)
----------
0
Sql> Select COUNT (1) from the test where object_name like '%test% ';
COUNT (1)
----------
12
Sql> Select COUNT (1) from the test where object_name like '%test ';
COUNT (1)
----------
2

sql> Set Autotrace trace exp

--79747*0.05=3987.35
Sql> SELECT * FROM test where object_name like '%test% ';
Execution plan
----------------------------------------------------------
Plan Hash value:1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
--------------------------------------------------------------------------
| 0 |      SELECT STATEMENT |  |   3987 |   389k| 224 (1) | 00:00:04 |
|* 1 | TABLE ACCESS full|  TEST |   3987 |   389k| 224 (1) | 00:00:04 |
--------------------------------------------------------------------------
predicate information (identified by Operation ID):
---------------------------------------------------
1-filter ("object_name" like '%test% ' and "object_name" are not NULL)
--79747*0.05=3987.35
Sql> SELECT * FROM test where object_name like '%test ';
Execution plan
----------------------------------------------------------
Plan Hash value:1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
--------------------------------------------------------------------------
| 0 |      SELECT STATEMENT |  |   3987 |   389k| 224 (1) | 00:00:04 |
|* 1 | TABLE ACCESS full|  TEST |   3987 |   389k| 224 (1) | 00:00:04 |
--------------------------------------------------------------------------
predicate information (identified by Operation ID):
---------------------------------------------------

1-filter ("object_name" like '%test ' and "object_name" are not NULL)

--If the percent sign is written in the back, you cannot follow the 5%

sql> select * from test where object_name like ' test% ';
Execution Plan
----------------------------------------------------------
Plan hash value:1357081020
-------- ------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU) | Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     2 |   200 |   224   (1) | 00:00:04 |
|*  1 |  table ACCESS full| TEST |     2 |   200 |   224   (1) | 00:00:04 |
--------------------------------------------------------------------------
Predicate information ( identified by Operation ID):
---------------------------------------------------
   1-filter (" object_name "like ' test% ')

Sql> SELECT * FROM test where object_name like ' t% ';
Execution plan
----------------------------------------------------------
Plan Hash value:1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
--------------------------------------------------------------------------
| 0 |      SELECT STATEMENT |  |   1079 |   105k| 224 (1) | 00:00:04 |
|* 1 | TABLE ACCESS full|  TEST |   1079 |   105k| 224 (1) | 00:00:04 |
--------------------------------------------------------------------------
predicate information (identified by Operation ID):
---------------------------------------------------
1-filter ("object_name" like ' t% ')

Oracle CBO evaluates the amount of like data

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.