[英]Index seek instead of index scan for is not null in condition
我有下面的查詢...
SELECT Compra_ID
FROM [Fart_Compras_dss_tracking]
WHERE [local_create_peer_timestamp] IS NOT NULL
CREATE TABLE [DataSync].[Fart_Compras_dss_tracking]
(
[COMPRA_ID] [int] NOT NULL,
[Sucursal_ID] [int] NOT NULL,
[update_scope_local_id] [int] NULL,
[scope_update_peer_key] [int] NULL,
[scope_update_peer_timestamp] [bigint] NULL,
[local_update_peer_key] [int] NOT NULL,
[local_update_peer_timestamp] [timestamp] NOT NULL,
[create_scope_local_id] [int] NULL,
[scope_create_peer_key] [int] NULL,
[scope_create_peer_timestamp] [bigint] NULL,
[local_create_peer_key] [int] NOT NULL,
[local_create_peer_timestamp] [bigint] NOT NULL,
[sync_row_is_tombstone] [int] NOT NULL,
[last_change_datetime] [datetime] NULL,
CONSTRAINT [PK_DataSync.Fart_Compras_dss_tracking]
PRIMARY KEY CLUSTERED ([COMPRA_ID] ASC, [Sucursal_ID] ASC)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [Idx_Text_4]
ON [DataSync].[Fart_Compras_dss_tracking] ([COMPRA_ID] ASC,
[Sucursal_ID] ASC,
[local_create_peer_timestamp] ASC,
[local_update_peer_timestamp] ASC)
INCLUDE ([update_scope_local_id], [scope_update_peer_key],
[scope_update_peer_timestamp], [local_update_peer_key],
[create_scope_local_id], [scope_create_peer_key],
[scope_create_peer_timestamp], [local_create_peer_key],
[sync_row_is_tombstone], [last_change_datetime])
WHERE ([local_create_peer_timestamp] IS NOT NULL)
WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
GO
執行計划可在下面的鏈接中找到...
https://www.brentozar.com/pastetheplan/?id=SkZbOe8zi
當我查看顯示 INDEX SCAN 的執行計划時,我嘗試創建不同的索引/過濾索引,但我無法看到 INDEX SEEK 甚至強制使用我的索引。
像這樣的IS NOT NULL
條件需要什么索引來提高性能?
您向我們展示的索引不適合優化您的過濾條件。 (它看起來確實比你的 PK 聚簇索引掃描得更快,但仍然需要掃描。)
該索引將有助於提高性能。
CREATE INDEX tstamp ON Fart_Compras_dss_tracking
(local_create_peer_timestamp);
您的 WHERE 過濾器可以隨機訪問它。 您仍然會看到索引范圍掃描。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.