Improve order by desc Performance Using inverted index

Source: Internet
Author: User

Using Reverse indexes to Improve the Performance of order by desc using reverse indexes (index desc) can greatly improve the performance of SQL statements with order by desc clauses. I. Scenario 1. Table Name: test_t, with a field name: object_id2, total data volume: 580000 rows, segment_size: 72MB3, Where condition (Owner = 'sys 'and Object_id> 50000) rows: 32472 rows 4. SQL statement: select * from test_t where owner = 'sys 'and object_id> 50000 order by object_id desc5, improve the Performance of order by object_id desc 2. Comparison between B * tree inverted index (DESC) and B * tree index (ASC Ascending by default) performance Improvement comparison 1. Adopt B * tree inverted INDEX (DESC) and COST: 4. Execute the INDEX RANGE SCANSQL statement as planned: select * from test_t where owner = 'sys 'and object_id> 50000 order by object_id desc index Mode create index idx_test_t_id_DESC on test_t (owner, object_id desc) COST and execution plan DescriptionObject ownerObject STATEMENT, GOAL = FIRST_ROWS 4942989806992 table access by index ROWIDSYSTEST_T4942989806992 index range SCANSYSIDX_TEST_T_ID_DESC31 2. Use B * tree INDEX (ASC BY default), COST: 94103, create INDEX idx_test_t_id_DESC on test_t (owner, object_id) COST and DescriptionObject ownerObject nameCostCardinalityBytesSELECT STATEMENT, GOAL = FIRST_ROWS 94103937929097824 table access by index rowidsystest_t9410394259097824 index range scan Summary: INDEX Method COST Execution Plan (owner, object_id desc) 4 index range scan (owner, object_id) 94103 index range scan desending iii. SQL statement in the actual test process: select * from test_t where owner = 'sys 'and object_id> 50000 order by object_id desc1. Test process and result (1) Using B * tree inverted index (DESC) create SQL> create index idx_test_t_id_DESC on test_t (OWNER, OBJECT_ID DESC) (2) re-collect statistics SQL> execdbms_stats.gather_table_stats (ownname => 'sys ', tabname => 'test _ t', estimate_percent => 20, cascade => TRUE); (3) SQL Execution Plan and COST DescriptionObject ownerObject nameCostCardinalityBytesSELECT STATEMENT, GOAL = FIRST_ROWS 4942989806992 table access by index partition index range SCANSYSIDX_TEST_T_ID_DESC31 2. B * tree INDEX (ASC Ascending BY default) test procedure and Result (1) create (OWNER + OBJECT_ID) Common ASC index SQL> create index idx_test_t_id_ASC on test_t (owner, object_id) (2) re-collect statistics SQL> execdbms_stats.gather_table_stats (ownname => 'sys ', tabname => 'test _ t', estimate_percent => 20, cascade => TRUE); (3) SQL Execution Plan and COST DescriptionObject ownerObject nameCostCardinalityBytesSELECT STATEMENT, GOAL = FIRST_ROWS 94103937929097824 TABLE ACCESS BY INDEX ROWIDSYSTEST_T94103937929097824 INDEX SCAN RANGE limit

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.