SQL Server Query never completes when filtered by specific value











up vote
3
down vote

favorite












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)









share|improve this question
























  • Is inventory_trans a table or a view? How large is it?
    – Gordon Linoff
    Nov 8 at 21:35










  • I would drop and recreate the index.
    – Cetin Basoz
    Nov 8 at 21:38










  • It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
    – Jack
    Nov 8 at 21:38








  • 1




    I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
    – Cetin Basoz
    Nov 8 at 21:41








  • 4




    35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
    – Martin Smith
    Nov 8 at 22:02

















up vote
3
down vote

favorite












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)









share|improve this question
























  • Is inventory_trans a table or a view? How large is it?
    – Gordon Linoff
    Nov 8 at 21:35










  • I would drop and recreate the index.
    – Cetin Basoz
    Nov 8 at 21:38










  • It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
    – Jack
    Nov 8 at 21:38








  • 1




    I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
    – Cetin Basoz
    Nov 8 at 21:41








  • 4




    35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
    – Martin Smith
    Nov 8 at 22:02















up vote
3
down vote

favorite









up vote
3
down vote

favorite











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)









share|improve this question















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)






sql sql-server sql-server-2008-r2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 21:55

























asked Nov 8 at 21:33









Jack

909522




909522












  • Is inventory_trans a table or a view? How large is it?
    – Gordon Linoff
    Nov 8 at 21:35










  • I would drop and recreate the index.
    – Cetin Basoz
    Nov 8 at 21:38










  • It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
    – Jack
    Nov 8 at 21:38








  • 1




    I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
    – Cetin Basoz
    Nov 8 at 21:41








  • 4




    35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
    – Martin Smith
    Nov 8 at 22:02




















  • Is inventory_trans a table or a view? How large is it?
    – Gordon Linoff
    Nov 8 at 21:35










  • I would drop and recreate the index.
    – Cetin Basoz
    Nov 8 at 21:38










  • It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
    – Jack
    Nov 8 at 21:38








  • 1




    I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
    – Cetin Basoz
    Nov 8 at 21:41








  • 4




    35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
    – Martin Smith
    Nov 8 at 22:02


















Is inventory_trans a table or a view? How large is it?
– Gordon Linoff
Nov 8 at 21:35




Is inventory_trans a table or a view? How large is it?
– Gordon Linoff
Nov 8 at 21:35












I would drop and recreate the index.
– Cetin Basoz
Nov 8 at 21:38




I would drop and recreate the index.
– Cetin Basoz
Nov 8 at 21:38












It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
– Jack
Nov 8 at 21:38






It is a table. Data space is ~80MB, index space is ~55MB. Around 350k rows.
– Jack
Nov 8 at 21:38






1




1




I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
– Cetin Basoz
Nov 8 at 21:41






I would explicitly drop and create the index anyway. Also, did you try running the query with a recompile? "SELECT * FROM PROD.DBO.INVENTORY_TRANS WHERE WORKORDER_BASE_ID = @BASE_ID option (recompile)"
– Cetin Basoz
Nov 8 at 21:41






4




4




35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
– Martin Smith
Nov 8 at 22:02






35 mins on a 100mb table sounds like blocking. An uncomiited transaction probably has a lock on one of the rows that predicate value would need to read. Whilst it is hung look in the waiting tasks DMV to see if it is waiting for something and if so what.
– Martin Smith
Nov 8 at 22:02














1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Your query may have been blocked by another process. While running your query in SQL Server Management Studio (SSMS), check the tab title. The parenthesized number at the end is the Server Process ID (SPID):



enter image description here



While your query is still executing, execute the following command in another window to check if your query is being blocked:



/* Replace 70 with actual SPID */
SELECT * FROM sys.sysprocesses WHERE spid = 70


If the blocked column contains a positive number, this is the SPID of the process blocking your query. For more details about this process, execute the following command:



/* Replace 62 with the actual SPID of the process in question */
DBCC INPUTBUFFER(62)
SELECT * FROM sys.sysprocesses WHERE spid = 62


The EventInfo may hint you on what is being executed in this connection, while login_time, hostname, program_name and other columns could pinpoint the connected user. For example another transaction may still be active.






share|improve this answer























  • This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
    – Jack
    Nov 9 at 12:57











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216469%2fsql-server-query-never-completes-when-filtered-by-specific-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Your query may have been blocked by another process. While running your query in SQL Server Management Studio (SSMS), check the tab title. The parenthesized number at the end is the Server Process ID (SPID):



enter image description here



While your query is still executing, execute the following command in another window to check if your query is being blocked:



/* Replace 70 with actual SPID */
SELECT * FROM sys.sysprocesses WHERE spid = 70


If the blocked column contains a positive number, this is the SPID of the process blocking your query. For more details about this process, execute the following command:



/* Replace 62 with the actual SPID of the process in question */
DBCC INPUTBUFFER(62)
SELECT * FROM sys.sysprocesses WHERE spid = 62


The EventInfo may hint you on what is being executed in this connection, while login_time, hostname, program_name and other columns could pinpoint the connected user. For example another transaction may still be active.






share|improve this answer























  • This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
    – Jack
    Nov 9 at 12:57















up vote
3
down vote



accepted










Your query may have been blocked by another process. While running your query in SQL Server Management Studio (SSMS), check the tab title. The parenthesized number at the end is the Server Process ID (SPID):



enter image description here



While your query is still executing, execute the following command in another window to check if your query is being blocked:



/* Replace 70 with actual SPID */
SELECT * FROM sys.sysprocesses WHERE spid = 70


If the blocked column contains a positive number, this is the SPID of the process blocking your query. For more details about this process, execute the following command:



/* Replace 62 with the actual SPID of the process in question */
DBCC INPUTBUFFER(62)
SELECT * FROM sys.sysprocesses WHERE spid = 62


The EventInfo may hint you on what is being executed in this connection, while login_time, hostname, program_name and other columns could pinpoint the connected user. For example another transaction may still be active.






share|improve this answer























  • This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
    – Jack
    Nov 9 at 12:57













up vote
3
down vote



accepted







up vote
3
down vote



accepted






Your query may have been blocked by another process. While running your query in SQL Server Management Studio (SSMS), check the tab title. The parenthesized number at the end is the Server Process ID (SPID):



enter image description here



While your query is still executing, execute the following command in another window to check if your query is being blocked:



/* Replace 70 with actual SPID */
SELECT * FROM sys.sysprocesses WHERE spid = 70


If the blocked column contains a positive number, this is the SPID of the process blocking your query. For more details about this process, execute the following command:



/* Replace 62 with the actual SPID of the process in question */
DBCC INPUTBUFFER(62)
SELECT * FROM sys.sysprocesses WHERE spid = 62


The EventInfo may hint you on what is being executed in this connection, while login_time, hostname, program_name and other columns could pinpoint the connected user. For example another transaction may still be active.






share|improve this answer














Your query may have been blocked by another process. While running your query in SQL Server Management Studio (SSMS), check the tab title. The parenthesized number at the end is the Server Process ID (SPID):



enter image description here



While your query is still executing, execute the following command in another window to check if your query is being blocked:



/* Replace 70 with actual SPID */
SELECT * FROM sys.sysprocesses WHERE spid = 70


If the blocked column contains a positive number, this is the SPID of the process blocking your query. For more details about this process, execute the following command:



/* Replace 62 with the actual SPID of the process in question */
DBCC INPUTBUFFER(62)
SELECT * FROM sys.sysprocesses WHERE spid = 62


The EventInfo may hint you on what is being executed in this connection, while login_time, hostname, program_name and other columns could pinpoint the connected user. For example another transaction may still be active.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 9:11

























answered Nov 9 at 7:20









Andrey Nikolov

1,461139




1,461139












  • This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
    – Jack
    Nov 9 at 12:57


















  • This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
    – Jack
    Nov 9 at 12:57
















This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
– Jack
Nov 9 at 12:57




This was the issue! It was being blocked by another blocked process.... I killed the root process and everything immediately cleared up. Thank you for the clear explanation and instructions! To anyone worrying about me just killing the process, it was hung due to another issue which has been resolved, so it shouldn't happen again.
– Jack
Nov 9 at 12:57


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216469%2fsql-server-query-never-completes-when-filtered-by-specific-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Landwehr

Reims

Custom delete method in JpaRepository