Whether the where condition has different order and performance problems

Source: Internet
Author: User

The where condition order is different, and the performance is also different. When I saw SQL statement optimization in the book yesterday, the where condition order is different, and the performance is different. Is this recommended for Oracle11G ??? Method 1 is better than method 2 ???????? Method 1: select. * from students s, class cwhere s. id = c. id s. id = 'xxxxxxxx' Method 2: select. * from students s, class cwhere s. id = 'xxxxxxxx' s. id = c. the test results in id 10g prove to be the same. Microsoft Windows [version 5.2.3790] (C) Copyright: 1985-2003 Microsoft Corp. c: \ Documents ents and Settings \ Administrator> sqlplus/as sysdbaSQL * Plus: Release 10.2.0.1.0-Production on Saturday May 11 17:48:55 2013 Copyright (c) 1982,200 5, Oracle. all rights reserved. connect to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-ProductionWith the Partitioning, OLAP and Data Mining optionsSQL> alter system flush shar Ed_pool; the system has been changed. SQL> alter system flush buffer_cache; the system has changed. SQL> set autotrace on; SQL> select * 2 from COUNTRIES c, 3 REGIONS r 4 where c. REGION_ID = r. REGION_ID and c. REGION_ID = '4'; REGIONS r * 3rd row error: ORA-00942: Table or view does not exist SQL> select * 2 from hr. COUNTRIES c, 3 hr. REGIONS r 4 where c. REGION_ID = r. REGION_ID and c. REGION_ID = '4'; CO COUNTRY_NAME REGION_ID -- ---------------------------------------- ---------- REGION_NAME-------------------------E G Egypt 4 4 4 Middle East and region Israel 4 4 Middle East and region Kuwait 4 4 Middle East and Africa CO COUNTRY_NAME REGION_ID -- region ---------- REGION_NAME-------------------------NG nieria 4 4 Middle East and region Zambia 4 4 Middle East and AfricaZW Zimbabwe 4 4 Middle East and Africa have selected 6 rows. Execution Plan -------------------------------------------------------- Plan hash value: 4030513296 Bytes | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | minute | 0 | select statement | 6 | 168 | 2 (0) | 00:00:01 | 1 | Nested loops | 6 | 168 | 2 (0) | 00:00:01 | 2 | table access by index rowid | REGIONS | 1 | 14 | 1 (0) | 00:00:01 | * 3 | index unique scan | REG_ID_PK | 1 | 0 (0) | 00:00:01 | * 4 | index full scan | COUNTRY_C_ID_PK | 6 | 84 | 1 (0) | 00:00:01 | identified Predicate Information (identified by operation id ):----- -------------------------------------------- 3-access ("R ". "REGION_ID" = 4) 4-filter ("C ". "REGION_ID" = 4) statistics 628 recursive cballs 0 db block gets 127 consistent gets 20 physical reads 0 redo size 825 bytes sent via SQL * Net to client 385 bytes received via SQL * Net from client 2 SQL * net roundtrips to/from client 13 sorts (memory) 0 sorts (d Isk) 6 rows processedSQL ############# SQL> alter system flush shared_pool; the system has been changed. SQL> alter system flush buffer_cache; the system has changed. Select * from hr. COUNTRIES c, hr. REGIONS r where c. REGION_ID = '4' 6 and c. REGION_ID = r. REGION_ID; CO COUNTRY_NAME REGION_ID -- region ---------- REGION_NAME-------------------------EG Egypt 4 4 Middle East and region Israel 4 4 Middle East and region Kuwait 4 4 Middle East and Africa CO COUNTRY_NAME REGION_ID region -- Region --------------------------- --------------- ---------- REGION_NAME-------------------------NG nieria 4 4 Middle East and AfricaZM Zambia 4 4 Middle East and AfricaZW Zimbabwe 4 4 Middle East and Africa has selected 6 rows. Execution Plan -------------------------------------------------------- Plan hash value: 4030513296 Bytes | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | minute | 0 | select statement | 6 | 168 | 2 (0) | 00:00:01 | 1 | nested loops | 6 | 168 | 2 (0) | 00:00:01 | 2 | table access by index rowid | REGIONS | 1 | 14 | 1 (0) | 00:00:01 | * 3 | index unique scan | REG_ID_PK | 1 | 0 (0) | 00:00:01 | * 4 | index full scan | COUNTRY_C_ID_PK | 6 | 84 | 1 (0) | 00:00:01 | identified Predicate Information (identified by operation id ): ------------------------------------------------- 3-access ("R ". "REGION_ID" = 4) 4-filter ("C ". "REGION_ID" = 4) statistics 656 recursive cballs 0 db block gets 131 consistent gets 22 physical reads 0 redo size 825 bytes sent via SQL * Net to client 385 bytes received via SQL * Net from client 2 SQL * net roundtrips to/from client 13 sorts (memory) 0 sorts (disk) 6 rows processedSQL>

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.