Query transformation of the optimizer

Source: Internet
Author: User

1. View Merging

Sql> CREATE VIEW EMP_VM as 2 Select Empno,ename,job,sal,comm,deptno 3 from EMP 4 where deptno=30; View created.     Sql> select Empno 2 from EMP_VM 3 where empno > 150; EMPNO----------7499 7521 7654 7698 7844 79006 rows selected. Sql> select * FROM table (dbms_xplan.display_cursor (null, NULL, ' advanced ')); Plan_table_ OUTPUT------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------sql_id 997U1V1B1K5SC, child number 0---- ---------------------------------select empno from EMP_VM where empno > 150Plan hash value:169057108---------------- ----------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |--------------------------------------------------------------------------------------| 0 |        SELECT STATEMENT |       |       |     |          2 (100) | ||  * 1 | TABLE ACCESS by INDEX rowid|     EMP |    5 |     35 | 2 (0) | 00:00:01 | |   * 2 | INDEX RANGE SCAN |    Pk_emp |       14 |     | 1 (0) | 00:00:01 |--------------------------------------------------------------------------------------Query Block Name/ Object Alias (identified by Operation ID):-------------------------------------------------------------1-sel$ F5BB74E1/[email protected]$2 2-sel$f5bb74e1/[email protected]$2outline Data-------------/*+ BEGIN      _outline_data ignore_optim_embedded_hints optimizer_features_enable (' 11.2.0.4 ') db_version (' 11.2.0.4 ') All_rows outline_leaf (@ "sel$f5bb74e1") MERGE (@ "sel$2") OUTLINE (@ "sel$1") OUTLINE (@ "sel$2") INDEX _RS_ASC (@ "sel$f5bb74e1" "emp" @ "sel$2" ("EMP"). EMPNO ")) End_outline_data */predicate information (identified by Operation ID):---------------------------------------------------1-filter (" DEPTNO "=30) 2-access (" EMPNO ">150) Column Projection information (identified by Operation ID):---------------------- -------------------------------------1-"EMPNO" [number,22] 2-"EMP". ROWID[ROWID,10], "EMPNO" [number,22]49 rows selected.  Sql>

2. Predicate propulsion

The optimizer pushes the related predicate of the query block into the view query block.

A. Defining a view

Create View ALL_EMP_VW as (select Empno, ename, Job, comm, Deptno from EMP) union (select Empno, ename, Job, Comm, Deptno from Contract_workers);

B. Executing a query

Select Enamefrom all_emp_vwwhere empno = 50;

C. Predicate propulsion (SQL that the optimizer actually executes)

Select Enamefrom (select Empno, ename, Job, comm, deptno from EMP where Empno=50unionselect empno, ename, Job, Comm, Dept No from contract_workers where empno=50);

3. Non-nested subqueries: Converting subqueries to equivalent join connections

4. Using materialized views for query rewriting

Query transformation of the optimizer

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.