RAW資料型別可以建立索引,但是不走索引測試(轉)
在逛ITubd的時候看見一列做記錄:
情況描述:
業務sql:
select count(*)
from px_apply t
where t.SITE_ID = '2C9146A12760F52A01276124EFB90016'
and t.CLASS_ID = '93E7EDF83B13CA6FE040007F01005BD5'
and t.IS_RESERVED = 0
and t.STATUS in (3, 4, 5)
作業系統資訊:
LSB Version: :core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
Distributor ID: RedHatEnterpriseAS
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
Release: 4
Codename: NahantUpdate5
資料庫資訊:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
其中一個測試:
索引建立:
create index ix_px_apply_SITE_ID on hz_bsp.px_apply(SITE_ID) tablespace XXX;
具體sql:
select count(*)
from px_apply t
where t.SITE_ID = '2C9146A12760F52A01276124EFB90016'
執行計劃:
SQL> set linesize 1000
SQL> set autotrace traceonly
SQL> set timing on
SQL> select count(*)
2 from px_apply t
3 where t.SITE_ID = '2C9146A12760F52A01276124EFB90016';
已用時間: 00: 00: 00.31
執行計劃
----------------------------------------------------------
Plan hash value: 1051324080
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 17 | 2361 (2)| 00:00:29 |
| 1 | SORT AGGREGATE | | 1 | 17 | | |
|* 2 | TABLE ACCESS FULL| PX_APPLY | 398K| 6608K| 2361 (2)| 00:00:29 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(RAWTOHEX("T"."SITE_ID")='2C9146A12760F52A01276124EFB90016'
)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
10620 consistent gets
0 physical reads
0 redo size
410 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
今天遇到一個資料庫裡面有很很多RAW(16)欄位。目前資料庫cpu佔用率很高,透過作業系統物理程式找到相關問題sql,sql裡面有三個RAW欄位,並且三個RAW欄位是查詢條件。
我的解決辦法:
1、a、期望在3列欄位建立複合索引
b、dbms_stats.gather_table_stats
結果:全表掃描
2、a、分別在三個RAW建立index
b、dbms_stats.gather_table_stats
結果:全表掃描
問題:google很多下,說Long Raw不可以建立索引,RAW可以建立索引,但是為什麼不走索引呢。
有兄弟遇到過類似的問題嗎?給我一些資訊。萬分感謝。
注:Oracle? Database PL/SQL User's Guide and Reference
10g Release 2 (10.2)
RAW Datatype
You use the RAW datatype to store binary data or byte strings. For example, a RAW variable might store a sequence of graphics characters or a digitized picture. Raw data is like VARCHAR2 data, except that PL/SQL does not interpret raw data. Likewise, Oracle Net does no character set conversions when you transmit raw data from one system to another.
The RAW datatype takes a required parameter that lets you specify a maximum size up to 32767 bytes. The syntax follows:
RAW(maximum_size)
You cannot use a symbolic constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.
You cannot insert RAW values longer than 2000 bytes into a RAW column. You can insert any RAW value into a LONG RAW database column because the maximum width of a LONG RAW column is 2147483648 bytes or two gigabytes. However, you cannot retrieve a value longer than 32767 bytes from a LONG RAW column into a RAW variable. Note that the LONG RAW datatype is supported only for backward compatibility; see "LONG and LONG RAW Datatypes" for more information.
解決方案:
情況描述:
業務sql:
select count(*)
from px_apply t
where t.SITE_ID = '2C9146A12760F52A01276124EFB90016'
and t.CLASS_ID = '93E7EDF83B13CA6FE040007F01005BD5'
and t.IS_RESERVED = 0
and t.STATUS in (3, 4, 5)
作業系統資訊:
LSB Version: :core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
Distributor ID: RedHatEnterpriseAS
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
Release: 4
Codename: NahantUpdate5
資料庫資訊:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
其中一個測試:
索引建立:
create index ix_px_apply_SITE_ID on hz_bsp.px_apply(SITE_ID) tablespace XXX;
具體sql:
select count(*)
from px_apply t
where t.SITE_ID = '2C9146A12760F52A01276124EFB90016'
執行計劃:
SQL> set linesize 1000
SQL> set autotrace traceonly
SQL> set timing on
SQL> select count(*)
2 from px_apply t
3 where t.SITE_ID = '2C9146A12760F52A01276124EFB90016';
已用時間: 00: 00: 00.31
執行計劃
----------------------------------------------------------
Plan hash value: 1051324080
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 17 | 2361 (2)| 00:00:29 |
| 1 | SORT AGGREGATE | | 1 | 17 | | |
|* 2 | TABLE ACCESS FULL| PX_APPLY | 398K| 6608K| 2361 (2)| 00:00:29 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(RAWTOHEX("T"."SITE_ID")='2C9146A12760F52A01276124EFB90016'
)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
10620 consistent gets
0 physical reads
0 redo size
410 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
今天遇到一個資料庫裡面有很很多RAW(16)欄位。目前資料庫cpu佔用率很高,透過作業系統物理程式找到相關問題sql,sql裡面有三個RAW欄位,並且三個RAW欄位是查詢條件。
我的解決辦法:
1、a、期望在3列欄位建立複合索引
b、dbms_stats.gather_table_stats
結果:全表掃描
2、a、分別在三個RAW建立index
b、dbms_stats.gather_table_stats
結果:全表掃描
問題:google很多下,說Long Raw不可以建立索引,RAW可以建立索引,但是為什麼不走索引呢。
有兄弟遇到過類似的問題嗎?給我一些資訊。萬分感謝。
注:Oracle? Database PL/SQL User's Guide and Reference
10g Release 2 (10.2)
RAW Datatype
You use the RAW datatype to store binary data or byte strings. For example, a RAW variable might store a sequence of graphics characters or a digitized picture. Raw data is like VARCHAR2 data, except that PL/SQL does not interpret raw data. Likewise, Oracle Net does no character set conversions when you transmit raw data from one system to another.
The RAW datatype takes a required parameter that lets you specify a maximum size up to 32767 bytes. The syntax follows:
RAW(maximum_size)
You cannot use a symbolic constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.
You cannot insert RAW values longer than 2000 bytes into a RAW column. You can insert any RAW value into a LONG RAW database column because the maximum width of a LONG RAW column is 2147483648 bytes or two gigabytes. However, you cannot retrieve a value longer than 32767 bytes from a LONG RAW column into a RAW variable. Note that the LONG RAW datatype is supported only for backward compatibility; see "LONG and LONG RAW Datatypes" for more information.
解決方案:
多半是隱式的資料型別轉換 試下在常量那邊加HEXTORAW SQL> select count(*) 2 from px_apply t 3 where t.SITE_ID = RAWTOHEX('2C9146A12760F52A01276124EFB90016'); 已用時間: 00: 00: 00.23 執行計劃 ---------------------------------------------------------- Plan hash value: 1051324080 ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 17 | 2361 (2)| 00:00:29 | | 1 | SORT AGGREGATE | | 1 | 17 | | | |* 2 | TABLE ACCESS FULL| PX_APPLY | 398K| 6608K| 2361 (2)| 00:00:29 | ------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(RAWTOHEX("T"."SITE_ID")='324339313436413132373630463532413 0313237363132344546423930303136') 統計資訊 ---------------------------------------------------------- 0 recursive calls 0 db block gets 10620 consistent gets 0 physical reads 0 redo size 407 bytes sent via SQL*Net to client 385 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed
|
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26764973/viewspace-1423023/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mysql】資料庫索引,百萬資料測試索引效果MySql資料庫索引
- mysql資料庫索引的建立以及效能測試MySql資料庫索引
- 為資料庫建立索引(轉)資料庫索引
- 測試建立基於函式的索引函式索引
- 資料型別與函式索引-PostgreSQL篇資料型別函式索引SQL
- 資料型別與函式索引-MySQL篇資料型別函式索引MySql
- 資料型別與函式索引-Oracle篇資料型別函式索引Oracle
- 資料庫索引型別及實現方式資料庫索引型別
- 資料庫之建立索引資料庫索引
- TypeScript 索引型別TypeScript索引型別
- 索引的型別索引型別
- MySQL 的索引型別及如何建立維護MySql索引型別
- Oracle的raw資料型別Oracle資料型別
- mongodb資料庫如何建立索引?MongoDB資料庫索引
- 索引失效系列——隱式型別轉換索引型別
- MySQL索引的型別MySql索引型別
- 掌握4種SQL索引型別,剖析索引原理SQL索引型別
- MySQL索引效能測試MySql索引
- 資料庫索引原理-轉資料庫索引
- 玩轉資料庫索引資料庫索引
- 資料庫建立索引的原則資料庫索引
- oracle 測試 清除分割槽資料,索引釋放空間Oracle索引
- TypeScript 可索引型別介面TypeScript索引型別
- MySQL 因資料型別轉換導致執行計劃使用低效索引MySql資料型別索引
- 關係型資料庫之索引資料庫索引
- mongodb 重複建立索引不報錯MongoDB索引
- Oracle資料庫索引使用及索引失效總結 轉Oracle資料庫索引
- [轉]聚集索引和非聚集索引的區別索引
- Oracle隱式型別轉換導致索引失效Oracle型別索引
- postgreSQL 索引(二)型別介紹SQL索引型別
- 移動LOB型別的索引型別索引
- 分割槽表 全域性索引與本地索引失效測試索引
- Oracle基本資料型別儲存格式淺析——RAW型別Oracle資料型別
- [轉]Mysql資料庫相關資料索引MySql資料庫索引
- Mysql索引型別建立錯誤導致SQL查詢緩慢MySql索引型別
- MySQL 聯合索引測試3MySql索引
- mongodb建立索引和刪除索引和背景索引backgroundMongoDB索引
- Oracle 對某列的部分資料建立索引Oracle索引