SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Mistery never ending query


Mistery never ending query

Author
Message
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28544 Visits: 39977
show the real query, and you can generate an estimated execution plan without running the query at all. just highlight the query and click the button for estimated execution plan.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

ricardo_chicas
ricardo_chicas
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 694
I transformed the data so what I showed is yhe actual query
And the estimated plan never is calculated. It just keeps running for hours until I stop it
ricardo_chicas
ricardo_chicas
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 694
ChrisM@Work (6/4/2013)
ricardo_chicas (6/4/2013)
All
I can't even generate the exec plan. It never ends, and none is using that table since it is a copy of the original
And none is blocking that spod either
This is only happenning to me with that specific query


Not even an estimated plan?


Yes. Not even the estimate, and only happenning on that table.
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28544 Visits: 39977
wow that's unusual, can you check for corruption? that might explain everything:


dbcc checktable ('YourTableName') WITH ALL_ERRORMSGS

DBCC CHECKDB (<Database Name>Wink WITH NO_INFOMSGS, ALL_ERRORMSGS




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Lynn Pettis
Lynn Pettis
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40020 Visits: 38566
While this query is running in one SSMS tab, switch to another tab and run sp_who2. Is the spid running your stuck query blocked?

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16494 Visits: 19557
ricardo_chicas (6/3/2013)
if I remove field 2 from the equation it will work just fine

Any ideas?



An actual plan from the whole original query with "field 2" commented out as you describe will help immensely.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
ricardo_chicas
ricardo_chicas
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 694
I just solved the issue by adding a new index ( not necessary since I was using the clustered one)
the query started working, then I removed the new index and the issue is gone
The table was new and not corrupted, so this was indeed some kind of bug
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16494 Visits: 19557
ricardo_chicas (6/4/2013)
I just solved the issue by adding a new index ( not necessary since I was using the clustered one)
the query started working, then I removed the new index and the issue is gone
The table was new and not corrupted, so this was indeed some kind of bug


It's more likely to be stale statistics than a bug. Can you post the actual plan now please?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
ricardo_chicas
ricardo_chicas
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 694
I am 100% sure it is a bug, you can even replicate it on your side if you also have a 2012 RTM server
just create a table like this

CREATE TABLE [dbo].[temptable2](
[Field1] [varchar](23) NOT NULL,
[field2] [varchar](20) NULL,
[field3] [varchar](50) NULL,
[field4] [datetime] NULL,
[field5] [varchar](255) NULL
) ON [PRIMARY]

Create clustered index idx1 on temptable2(field1)

load it with at least 100k rows

then do this:

select field3,count(1)
from temptable2
group by field3


it will never ever ends, now that is only happening on 2012, I just test it in a 2008 R2 sp2 server and it worked fine
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28544 Visits: 39977
nope, not a valid test/way to reproduce the issue.

here's your exact code, but loaded with random data.
on my machine, with all four versions of SQL Server I have installed (2005/2008/2008R2/2012), it returned results in about 9 seconds.


CREATE TABLE [dbo].[temptable2](
[Field1] [varchar](23) NOT NULL,
[field2] [varchar](20) NULL,
[field3] [varchar](50) NULL,
[field4] [datetime] NULL,
[field5] [varchar](255) NULL
) ON [PRIMARY]

Create clustered index idx1 on temptable2(field1)

INSERT INTO temptable2
SELECT TOP 200000
LEFT(CONVERT(varchar(50),NEWID()),23), --23 chars
LEFT(CONVERT(varchar(50),NEWID()),20),--20 chars
LEFT(CONVERT(varchar(50),NEWID()),50),--50 chars
CAST(RAND(CHECKSUM(NEWID()))*3653.0+36524.0 AS DATETIME), --datetime
LEFT(CONVERT(varchar(255),NEWID()),255) --255 chars
FROM sys.columns T1 cross apply sys.columns T2

select field3,count(1)
from temptable2
group by field3



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search