[英]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.