Oracle Indexing Join on Not Null
Oracle Indexing Join on Not Null
我们正在 Oracle 数据库 11g 上进行 SQL Tuning/Indexing。目前 CustomerTransaction ProductId 上没有索引,因此我们想添加一个索引以帮助 Join 调优性能。但是,DBA 注意到 CustomerTransaction 中 95% 的 ProductId 为 Null。 Oracle 是否可以选择仅在非空行上建立索引?索引的替代方法是什么,或者我们应该在这个 90% distribution/statistics 场景中应用索引?
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,计数分布
等样本列表
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
对于单列B树索引,Oracle只会索引索引列不为空的行。
table 的 table 的 5% 有时仍然比通过完整 table 扫描更慢地读取索引,这将取决于这些行的分布方式。
我们正在 Oracle 数据库 11g 上进行 SQL Tuning/Indexing。目前 CustomerTransaction ProductId 上没有索引,因此我们想添加一个索引以帮助 Join 调优性能。但是,DBA 注意到 CustomerTransaction 中 95% 的 ProductId 为 Null。 Oracle 是否可以选择仅在非空行上建立索引?索引的替代方法是什么,或者我们应该在这个 90% distribution/statistics 场景中应用索引?
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,计数分布 等样本列表
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
对于单列B树索引,Oracle只会索引索引列不为空的行。
table 的 table 的 5% 有时仍然比通过完整 table 扫描更慢地读取索引,这将取决于这些行的分布方式。