我們正在 Oracle 資料庫 11g 上進行 SQL 調優/索引。目前沒有關于 CustomerTransaction ProductId 的索引,所以我們想添加一個來幫助 Join 調優性能。但是,DBA 注意到 CustomerTransaction 中 95% 的 ProductId 為 Null。Oracle 是否可以選擇僅對非空行進行索引?什么是索引的替代方法,或者我們應該在這個 90% 分布/統計場景中應用索引?
select ct.customerId, pr.ProductName
from dbo.CustomerTransaction ct
inner join dbo.Product pr
on ct.ProductId = pr.ProductId
CREATE TABLE [dbo].[CustomerTransaction](
[CustomerTransactionId] [int] NOT NULL, // this is the primary key
[ProductId] [int] NULL,
[SalesDate] [datetime] NOT NULL,
...
)
ProductId、Count Distribution 等示例串列
NULL,34065306
2,127444
3,103996
5,96280
6,78247
366,66744
9,58251
4,48056
10,29841
155,27353
8,22143
1052,20885
16,18298
23204,17242
21,16413
26,15084
11,15061
23205,14161
168,14086
7,14022
738,13294
115,12385
13,12119
18,11844
23208,11610
uj5u.com熱心網友回復:
對于單列 B 樹索引,Oracle 只會索引索引列不為空的行。
有時,索引讀取表的 5% 比全表掃描讀取的速度仍然較慢,這取決于這些行的分布方式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360636.html
上一篇:有條件地從資料庫中獲取表名?
