where條件順序不同、性能不同示例探討_Mssql數(shù)據(jù)庫教程
推薦:如何將sql執(zhí)行的錯(cuò)誤消息記錄到本地文件中實(shí)現(xiàn)過程sql語句的錯(cuò)誤信息都可以在sys.messages表里面找到,下面與大家分享下將sql 執(zhí)行的錯(cuò)誤消息記錄到本地文件中,不會(huì)的朋友可以參考下哈
昨天在書上看到SQL語句優(yōu)化時(shí),where條件順序不同,性能不同,這個(gè)建議在Oracle11G版本還合適嗎?方式1優(yōu)于方式2?方式1:
復(fù)制代碼 代碼如下:www.hl5o.cn
select a.*
from students s,
class c
where
s.id = c.id
s.id = 'xxxxxxxx'
方式2:
復(fù)制代碼 代碼如下:www.hl5o.cn
select a.*
from students s,
class c
where
s.id = 'xxxxxxxx'
s.id = c.id
10g中測試結(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>
分享:sql server 2008中的apply運(yùn)算符使用方法sql server 2008中的apply運(yùn)算符使用方法,需要的朋友可以參考一下
相關(guān)Mssql數(shù)據(jù)庫教程:
- sql 語句練習(xí)與答案
- 深入C++ string.find()函數(shù)的用法總結(jié)
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個(gè)方法
- sql刪除重復(fù)數(shù)據(jù)的詳細(xì)方法
- SQL SERVER 2000安裝教程圖文詳解
- 使用sql server management studio 2008 無法查看數(shù)據(jù)庫,提示 無法為該請求檢索數(shù)據(jù) 錯(cuò)誤916解決方法
- SQLServer日志清空語句(sql2000,sql2005,sql2008)
- Sql Server 2008完全卸載方法(其他版本類似)
- sql server 2008 不允許保存更改,您所做的更改要求刪除并重新創(chuàng)建以下表
- SQL Server 2008 清空刪除日志文件(瞬間日志變幾M)
- Win7系統(tǒng)安裝MySQL5.5.21圖解教程
- 將DataTable作為存儲過程參數(shù)的用法實(shí)例詳解
Mssql數(shù)據(jù)庫教程Rss訂閱編程教程搜索
Mssql數(shù)據(jù)庫教程推薦
- 如何在SAN上創(chuàng)建SQL Server群集
- SQL Server儲過程加密和解密原理深入分析
- 解決SQL Server無法打開用戶默認(rèn)數(shù)據(jù)庫的問題
- 怎樣讓SQL Server加速運(yùn)行
- 如何快速生成100萬不重復(fù)的8位編號
- mssql2005數(shù)據(jù)庫鏡像搭建教程
- 在SQL Server數(shù)據(jù)庫中批量導(dǎo)入數(shù)據(jù)的四種方法
- CMD命令操作MSSQL2005數(shù)據(jù)庫(命令整理)
- SQL Server2008 數(shù)據(jù)庫誤刪除數(shù)據(jù)的恢復(fù)方法分享
- 解讀SQL Server與Oracle數(shù)據(jù)庫在安全性上的異同
猜你也喜歡看這些
- DBA應(yīng)該知道的一些關(guān)于SQL Server跟蹤標(biāo)記的使用
- jdbc調(diào)用mysql存儲過程實(shí)現(xiàn)代碼
- MYSQL SET類型字段的SQL操作知識介紹
- MySQL——修改root密碼的4種方法(以windows為例)
- mysql 數(shù)據(jù)庫 (基礎(chǔ)) 筆記
- mysql手動(dòng)刪除BINLOG的方法
- 基于一致性hash算法(consistent hashing)的使用詳解
- MySQL筆記之系統(tǒng)信息函數(shù)詳解
- mysql重裝后出現(xiàn)亂碼設(shè)置為utf8可解決
- Mysql中“Insert into xxx on duplicate key update”問題
- 相關(guān)鏈接:
- 教程說明:
Mssql數(shù)據(jù)庫教程-where條件順序不同、性能不同示例探討
。