Watch my live session: When Partitioning Indexes Hurts Performance (and How to Fix It)
I’m very that my session on table partitioning from the 2017 SQL PASS Summit is being featured as one of the “Best of Summit” …
Read MoreBy Kendra Little on • 2 min read
This question came up in a webcast recently: if a filtered index is causing data modifications to fail, does disabling the filtered index fix the problem?
I wasn’t 100% sure – I couldn’t remember the last time I’d tried, if I ever had. So….
First, let’s reproduce the problem: we’ll create a filtered index on a table, then set up a session who can’t read from it due to an ANSI_SETTINGS conflict. (A list of required SET OPTIONS for filtered indexes is documented here.)
I created this in the WideWorldImporters sample database.
CREATE INDEX
ix_SalesOrders_filtered_IsUndersupplyBackordered_OrderDate_INCLUDES
ON Sales.Orders
(
OrderDate
)
INCLUDE
(
OrderID,
CustomerID,
SalespersonPersonID,
PickedByPersonID,
ContactPersonID,
BackorderOrderID,
ExpectedDeliveryDate,
CustomerPurchaseOrderNumber,
IsUndersupplyBackordered,
Comments,
DeliveryInstructions,
InternalComments,
PickingCompletedWhen,
LastEditedBy,
LastEditedWhen
)
WHERE
(IsUndersupplyBackordered = 0);
GO
All I have to do to make an insert fail is violate one of those required ANSI settings in my session.
Here we go!
SET ANSI_NULLS OFF;
GO
BEGIN TRANSACTION
INSERT INTO Sales.Orders
(
CustomerID,
SalespersonPersonID,
PickedByPersonID,
ContactPersonID,
BackorderOrderID,
OrderDate,
ExpectedDeliveryDate,
CustomerPurchaseOrderNumber,
IsUndersupplyBackordered,
Comments,
DeliveryInstructions,
InternalComments,
PickingCompletedWhen,
LastEditedBy,
LastEditedWhen
)
SELECT TOP (1)
o.CustomerID,
o.SalespersonPersonID,
o.PickedByPersonID,
o.ContactPersonID,
o.BackorderOrderID,
o.OrderDate,
o.ExpectedDeliveryDate,
o.CustomerPurchaseOrderNumber,
o.IsUndersupplyBackordered,
o.Comments,
o.DeliveryInstructions,
o.InternalComments,
o.PickingCompletedWhen,
o.LastEditedBy,
o.LastEditedWhen
FROM Sales.Orders AS o;
GO
Msg 1934, Level 16, State 1, Line 25 INSERT failed because the following SET options have incorrect settings: ‘ANSI_NULLS’. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.
I suck all the pages out of the filtered index, leaving only the metadata behind:
ALTER INDEX
ix_SalesOrders_filtered_IsUndersupplyBackordered_OrderDate_INCLUDES
ON Sales.Orders
DISABLE;
GO
And now, when I retry my insert….
(1 row affected)
It worked! As long as this filtered index is disabled, the insert works again for the session with the incompatible ANSI_NULLS setting.
Rebuilding the filtered index will cause this problem to happen again – until all sessions modifying the table have the required se ssion settings in place.
So to prevent actual rebuilds, I’d rather drop the index until everything is in order for the index to be recreated.
Copyright (c) 2025, Catalyze SQL, LLC; all rights reserved. Opinions expressed on this site are solely those of Kendra Little of Catalyze SQL, LLC. Content policy: Short excerpts of blog posts (3 sentences) may be republished, but longer excerpts and artwork cannot be shared without explicit permission.