I have a table named inventory_transaction in a SQL Server 2008 R2 production environment. The table and indexes, as well as the maintenance package to maintain them, were developed by a professional vendor. We have had no problems for almost 10 years since implementing the program that uses this table, and there is no fragmentation above 8% on any of the indexes for the table.
However, I am having some trouble now. When I try to filter this table by one specific value, the query will not complete. Any other value will make the query execute in < 1 sec.
Here is the specific query that will not complete:
DECLARE @BASE_ID VARCHAR(30) = 'W46873'
SELECT *
FROM PROD.DBO.INVENTORY_TRANS
WHERE WORKORDER_BASE_ID = @BASE_ID
I let it run for 35 minutes before cancelling it. I never receive an error message. If I put literally any other value in @BASE_ID, it will execute in <1 sec. If I change the equal operator on WORKORDER_BASE_ID to use LIKE and change @BASE_ID to @BASE_ID = 'W4687%', it will work. All values in this column are the same format (W + 5 numbers).
The data type for @BASE_ID is the same as the column WORKORDER_BASE_ID on the table. There is a nonclustered index that includes this column which is being used by in other query plans that are completing for other values. Since this one won't complete, I'm not sure what the actual execution plan it is using is.
Any ideas what could be causing this or what I could do to fix it? I can provide more information as needed. This issue is causing timeouts within the program, which creates a lot of problems.
EDIT1: Running the query with OPTION(RECOMPILE) doesn't help.
DECLARE @BASE_ID VARCHAR(30) = 'W46873'
SELECT *
FROM VMFGTEST.DBO.INVENTORY_TRANS
WHERE WORKORDER_BASE_ID = @BASE_ID
OPTION (RECOMPILE)
