where條件順序不同、性能不同示例探討
方式1:
select a.*
from students s,
class c
where
s.id = c.id
s.id = 'xxxxxxxx'
方式2:
select a.*
from students s,
class c
where
s.id = 'xxxxxxxx'
s.id = c.id
10g中測(cè)試結(jié)果證明是一樣的。
Microsoft Windows [版本 5.2.3790]
(C) 版權(quán)所有 1985-2003 Microsoft Corp.
C:\Documents and Settings\Administrator>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期六 5月 11 17:48:55 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> alter system flush shared_pool;
系統(tǒng)已更改。
SQL> alter system flush buffer_cache;
系統(tǒng)已更改。
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
*
第 3 行出現(xiàn)錯(cuò)誤:
ORA-00942: 表或視圖不存在
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_ID
-- ---------------------------------------- ---------- ----------
REGION_NAME
-------------------------
EG Egypt 4 4
Middle East and Africa
IL Israel 4 4
Middle East and Africa
KW Kuwait 4 4
Middle East and Africa
CO COUNTRY_NAME REGION_ID REGION_ID
-- ---------------------------------------- ---------- ----------
REGION_NAME
-------------------------
NG Nigeria 4 4
Middle East and Africa
ZM Zambia 4 4
Middle East and Africa
ZW Zimbabwe 4 4
Middle East and Africa
已選擇6行。
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 4030513296
--------------------------------------------------------------------------------
----------------
| Id | Operation | Name | Rows | Bytes | Cost (%
CPU)| Time |
--------------------------------------------------------------------------------
----------------
| 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 |
--------------------------------------------------------------------------------
----------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("R"."REGION_ID"=4)
4 - filter("C"."REGION_ID"=4)
統(tǒng)計(jì)信息
----------------------------------------------------------
628 recursive calls
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 (disk)
6 rows processed
SQL>
#############
SQL> alter system flush shared_pool;
系統(tǒng)已更改。
SQL> alter system flush buffer_cache;
系統(tǒng)已更改。
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_ID
-- ---------------------------------------- ---------- ----------
REGION_NAME
-------------------------
EG Egypt 4 4
Middle East and Africa
IL Israel 4 4
Middle East and Africa
KW Kuwait 4 4
Middle East and Africa
CO COUNTRY_NAME REGION_ID REGION_ID
-- ---------------------------------------- ---------- ----------
REGION_NAME
-------------------------
NG Nigeria 4 4
Middle East and Africa
ZM Zambia 4 4
Middle East and Africa
ZW Zimbabwe 4 4
Middle East and Africa
已選擇6行。
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 4030513296
--------------------------------------------------------------------------------
----------------
| Id | Operation | Name | Rows | Bytes | Cost (%
CPU)| Time |
--------------------------------------------------------------------------------
----------------
| 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 |
--------------------------------------------------------------------------------
----------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("R"."REGION_ID"=4)
4 - filter("C"."REGION_ID"=4)
統(tǒng)計(jì)信息
----------------------------------------------------------
656 recursive calls
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 processed
SQL>
相關(guān)文章
SQL Server2019數(shù)據(jù)庫(kù)備份與還原腳本(批量備份)
本文主要介紹了SQL Server2019數(shù)據(jù)庫(kù)備份與還原腳本,數(shù)據(jù)庫(kù)可批量備份,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11SQL查詢數(shù)據(jù)是否存在的實(shí)現(xiàn)示例
在后端開(kāi)發(fā)中,經(jīng)常需要使用數(shù)據(jù)庫(kù)來(lái)存儲(chǔ)和管理數(shù)據(jù),一個(gè)常見(jiàn)的任務(wù)是檢查數(shù)據(jù)庫(kù)中是否存在數(shù)據(jù),本文主要介紹了SQL查詢數(shù)據(jù)是否存在,感興趣的可以了解一下2024-02-02SQL Server誤區(qū)30日談 第8天 有關(guān)對(duì)索引進(jìn)行在線操作的誤區(qū)
在線索引操作會(huì)在操作開(kāi)始時(shí)和操作結(jié)束時(shí)對(duì)資源上短暫的鎖。這有可能導(dǎo)致嚴(yán)重的阻塞問(wèn)題2013-01-01SQL Server 復(fù)制需要有實(shí)際的服務(wù)器名稱才能連接到服務(wù)器
今天在做sql Server 2005的實(shí)驗(yàn)的時(shí)候碰到的問(wèn)題,問(wèn)題描述很清楚,懷疑是我以前給計(jì)算機(jī)修改了名稱而導(dǎo)致的.可以用select @@servername和select serverproperty ('servername')對(duì)照一下,兩個(gè)的結(jié)果是否一樣2012-06-06SQLServer 參數(shù)化查詢經(jīng)驗(yàn)分享
本篇文章將介紹參數(shù)化查詢。我將討論如果一個(gè)查詢可以被參數(shù)化,那么SQL Server優(yōu)化器怎樣嘗試將其參數(shù)化,以及你可以怎樣建立你自己的參數(shù)化查詢。2010-05-05SQLSERVER語(yǔ)句的執(zhí)行時(shí)間顯示的統(tǒng)計(jì)結(jié)果是什么意思
在SQL語(yǔ)句調(diào)優(yōu)的時(shí)候,大部分都會(huì)查看語(yǔ)句執(zhí)行時(shí)間,究竟SQLSERVER顯示出來(lái)的統(tǒng)計(jì)結(jié)果是什么意思,接下來(lái)為您一一解釋,感興趣的朋友可以了解下2013-01-0110種Java開(kāi)發(fā)者編寫SQL語(yǔ)句時(shí)常見(jiàn)錯(cuò)誤
這篇文章主要介紹了10種Java開(kāi)發(fā)者編寫SQL語(yǔ)句時(shí)常見(jiàn)錯(cuò)誤,當(dāng)Java開(kāi)發(fā)人員編寫SQL語(yǔ)句時(shí),一切都變得不同了。SQL是一種說(shuō)明式語(yǔ)言,與面向?qū)ο笏枷牒兔钍剿枷霟o(wú)關(guān),需要的朋友可以參考下2015-08-08