CBO the consequences of a wrong index selection

Source: Internet
Author: User
Tags execution sorts

In the query for the 2 billion record large table, it was found that Oracle's execution plan selection was not stable, of course, this is the normal behavior of the CBO, but when the choice is different, the result is huge.

In the following query, the query quickly draws results using the specified index, but this depends on the hints mandatory designation:

Sql> Select/*+ Index (SMSMG idx_smsmg_dest_mdn) */COUNT (*)

2 from SMSMG where msg_to_dest_mdn= ' 861318888888 ' and service_id= ' 54 ';

COUNT (*)

----------

1

elapsed:00:00:00.00

Execution Plan

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

Plan Hash value:1659057974

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

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

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

| 0 |                          SELECT STATEMENT |     |    1 |    18 | 98 (0) |       00:00:02 |       | |

|  1 |                          SORT AGGREGATE |     |    1 |            18 |          |       |       | |

|* 2 | TABLE ACCESS by GLOBAL INDEX rowid|     SMSMG |    1 |    18 | 98 (0) | 00:00:02 | ROWID | ROWID |

|* 3 | INDEX RANGE SCAN |   IDX_SMSMG_MSG_TO_DES_MDN |       106 |     | 4 (0) |       00:00:01 |       | |

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

predicate information (identified by Operation ID):

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

2-filter ("service_id" = ' 54 ')

3-access ("msg_to_dest_mdn" = ' 861318888888 ')

Statistics

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

0 Recursive calls

0 db Block gets

Consistent gets

0 physical Reads

0 Redo Size

515 Bytes sent via sql*net to client

469 bytes received via sql*net from client

2 sql*net roundtrips To/from Client

0 Sorts (memory)

0 Sorts (disk)

1 rows processed

If you do not add hints, the query is temporarily unable to produce results:

Sql> Select COUNT (*) from SMSMG where msg_to_dest_mdn= ' 861318888888 ' and service_id= ' 54 ';

Select COUNT (*) from SMSMG where msg_to_dest_mdn= ' 861318888888 ' and service_id= ' 54 '

*

ERROR at line 1:

Ora-01013:user requested cancel of current operation

elapsed:00:04:27.88

Its execution plan shows that this default execution led to the wrong index selection:

Sql> set Autotrace Trace explain

Sql> Select COUNT (*) from SMSMG where msg_to_dest_mdn= ' 861318888888 ' and service_id= ' 54 ';

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.