We have experienced what appears to be an interesting bug in SQL Server that I would like to describe to you. I am hoping to find out if it IS actually a bug, and if so where I can found out more information about it. If it is not a bug, I hope somebody can explain to me why it is not and what we have unwittingly done wrong. I can't seem to find description of a similar issue and I'm not sure if we should report to Microsoft as a bug or what. I will first describe the problem briefly and provide details after.
In short, the problem seems to be that SQL Server chokes on statements containing many joins when some (large?) portion (sorry, can't be more specific here in terms of numbers) of the tables being joined are empty. By choke, I mean that it churns and churns away at the query, never finishing, which causes SQL Server to stop responding entirely. Actually, running the query once causes the CPU to jump to 25% and stay there. Another attempt and CPU jumps to 50%. Sometimes, CPU would go to 75% or 100%, but at the 50% mark, you can't even log in to the database server any more.
The problem occurs in an application that we have that uses Hibernate (via Coldfusion ORM) and has an entity (Document) that is sub-classed into many different types of document. The SQL query in question is generated by Hibernate when we run a query on the base class Document (e.g. "FROM Document WHERE Locked=1"). This results in a very long SQL query that joins all the sub-class tables together (example below) and sometimes kills the server.
A few things of interest that I found while testing:
It ONLY happens when there are a large number of empty joined tables, which is why it was such a bear to track down - never happened when running on our dev or testing databases because they had ample data. So the same query runs instantaneously without issue in one instance and completely kills SQL server in another.
I thought at first that the large number of selected columns in the SQL query might be causing an issue so I tested the SQL query with the same joins but only selected a single column from each table so only a small amout of data was actually being selected - no improvement, still hung.
I ran the query against the DB that had little data and I started removing the joins one by one. I found I could get to a point where the query would run and run quickly. Adding a join back from this point would cause the query to run, but noticeably slower, and repeating this a few more times would eventually cause it to grind to a halt again and kill the server.
So based on the above I've surmised that there is a bug (or a known fact of which I am ignorant) in SQL Server whereby joins resulting in too many nulls cause an issue. I think it might be a bug rather than a known limitation because it does not result in an error message (like, for example, you would get if you attempted a query with more than 2100 items in an IN clause), but rather a hung server. The server goes into la-la land almost like the joins had resulted in a cartesion product, but it's the opposite - instead of huge amounts of data, I have no data.
Has anybody else ever encountered such an issue? Is there some known limit of SQL server that I am rubbing up against? I have had great difficulty googling the issue because it is hard to define.
Should I file a bug with Microsoft for this?
Any insights are greatly appreciated. If any more information is needed from me, please let me know.
Thanks.
Example query follows (I've removed most of the selected columns for brevity):
select
top 1 document0_.ID as ID715_,
document0_.CreatedOn as CreatedOn715_,
document0_.UpdatedOn as UpdatedOn715_,
document0_.DeletedOn as DeletedOn715_,
document0_.Deleted as Deleted715_,
document0_.Active as Active715_,
document0_.ActivatedOn as Activate8_715_,
document0_.DeactivatedOn as Deactiva9_715_,
document0_.Locked as Locked715_,
document0_.CompletedDate as Complet11_715_,
document0_.CreateUserID as CreateU23_715_,
document0_.UpdateUserID as UpdateU24_715_,
document0_1_.CreatedOn as CreatedOn717_,
document0_1_.UpdatedOn as UpdatedOn717_,
document0_1_.DeletedOn as DeletedOn717_,
document0_1_.Deleted as Deleted717_,
document0_1_.Active as Active717_,
document0_1_.ActivatedOn as Activate7_717_,
document0_1_.DeactivatedOn as Deactiva8_717_,
document0_1_.Locked as Locked717_,
document0_1_.DateReceived as DateRec10_717_,
document0_1_.DateIssued as DateIssued717_,
document0_1_.CreateUserID as CreateU12_717_,
document0_1_.UpdateUserID as UpdateU13_717_,
document0_2_.CreatedOn as CreatedOn733_,
document0_2_.UpdatedOn as UpdatedOn733_,
document0_2_.DeletedOn as DeletedOn733_,
document0_2_.Deleted as Deleted733_,
document0_2_.Active as Active733_,
document0_2_.ActivatedOn as Activate7_733_,
document0_2_.DeactivatedOn as Deactiva8_733_,
document0_2_.Locked as Locked733_,
document0_3_.CreatedOn as CreatedOn739_,
document0_3_.UpdatedOn as UpdatedOn739_,
document0_3_.DeletedOn as DeletedOn739_,
document0_3_.Deleted as Deleted739_,
document0_3_.Active as Active739_,
document0_3_.ActivatedOn as Activate7_739_,
document0_3_.DeactivatedOn as Deactiva8_739_,
document0_3_.Locked as Locked739_,
document0_4_.CreatedOn as CreatedOn754_,
document0_4_.UpdatedOn as UpdatedOn754_,
document0_4_.DeletedOn as DeletedOn754_,
document0_4_.Deleted as Deleted754_,
document0_4_.Active as Active754_,
document0_4_.ActivatedOn as Activate7_754_,
document0_4_.DeactivatedOn as Deactiva8_754_,
document0_4_.Locked as Locked754_,
document0_5_.CreatedOn as CreatedOn755_,
document0_5_.UpdatedOn as UpdatedOn755_,
document0_5_.DeletedOn as DeletedOn755_,
document0_5_.Deleted as Deleted755_,
document0_5_.Active as Active755_,
document0_5_.ActivatedOn as Activate7_755_,
document0_5_.DeactivatedOn as Deactiva8_755_,
document0_5_.Locked as Locked755_,
document0_6_.CreatedOn as CreatedOn759_,
document0_6_.UpdatedOn as UpdatedOn759_,
document0_6_.DeletedOn as DeletedOn759_,
document0_6_.Deleted as Deleted759_,
document0_6_.Active as Active759_,
document0_6_.ActivatedOn as Activate7_759_,
document0_6_.DeactivatedOn as Deactiva8_759_,
document0_6_.Locked as Locked759_,
document0_7_.CreatedOn as CreatedOn773_,
document0_7_.UpdatedOn as UpdatedOn773_,
document0_7_.DeletedOn as DeletedOn773_,
document0_7_.Deleted as Deleted773_,
document0_7_.Active as Active773_,
document0_7_.ActivatedOn as Activate7_773_,
document0_7_.DeactivatedOn as Deactiva8_773_,
document0_7_.Locked as Locked773_,
document0_8_.CreatedOn as CreatedOn774_,
document0_8_.UpdatedOn as UpdatedOn774_,
document0_8_.DeletedOn as DeletedOn774_,
document0_8_.Deleted as Deleted774_,
document0_8_.Active as Active774_,
document0_8_.ActivatedOn as Activate7_774_,
document0_8_.DeactivatedOn as Deactiva8_774_,
document0_8_.Locked as Locked774_,
document0_9_.CreatedOn as CreatedOn779_,
document0_9_.UpdatedOn as UpdatedOn779_,
document0_9_.DeletedOn as DeletedOn779_,
document0_9_.Deleted as Deleted779_,
document0_9_.Active as Active779_,
document0_9_.ActivatedOn as Activate7_779_,
document0_9_.DeactivatedOn as Deactiva8_779_,
document0_9_.Locked as Locked779_,
document0_10_.CreatedOn as CreatedOn780_,
document0_10_.UpdatedOn as UpdatedOn780_,
document0_10_.DeletedOn as DeletedOn780_,
document0_10_.Deleted as Deleted780_,
document0_10_.Active as Active780_,
document0_10_.ActivatedOn as Activate7_780_,
document0_10_.DeactivatedOn as Deactiva8_780_,
document0_10_.Locked as Locked780_,
document0_11_.CreatedOn as CreatedOn781_,
document0_11_.UpdatedOn as UpdatedOn781_,
document0_11_.DeletedOn as DeletedOn781_,
document0_11_.Deleted as Deleted781_,
document0_11_.Active as Active781_,
document0_11_.ActivatedOn as Activate7_781_,
document0_11_.DeactivatedOn as Deactiva8_781_,
document0_11_.Locked as Locked781_,
document0_11_.ExpiryDate as ExpiryDate781_,
document0_11_.Number as Number781_,
document0_11_.CreateUserID as CreateU12_781_,
document0_11_.UpdateUserID as UpdateU13_781_,
document0_12_.CreatedOn as CreatedOn784_,
document0_12_.UpdatedOn as UpdatedOn784_,
document0_12_.DeletedOn as DeletedOn784_,
document0_12_.Deleted as Deleted784_,
document0_12_.Active as Active784_,
document0_12_.ActivatedOn as Activate7_784_,
document0_12_.DeactivatedOn as Deactiva8_784_,
document0_12_.Locked as Locked784_,
document0_12_.CreateUserID as CreateU10_784_,
document0_12_.UpdateUserID as UpdateU11_784_,
document0_12_.SurveyID as SurveyID784_,
document0_13_.CreatedOn as CreatedOn789_,
document0_13_.UpdatedOn as UpdatedOn789_,
document0_13_.DeletedOn as DeletedOn789_,
document0_13_.Deleted as Deleted789_,
document0_13_.Active as Active789_,
document0_13_.ActivatedOn as Activate7_789_,
document0_13_.DeactivatedOn as Deactiva8_789_,
document0_13_.Locked as Locked789_,
document0_14_.CreatedOn as CreatedOn790_,
document0_14_.UpdatedOn as UpdatedOn790_,
document0_14_.DeletedOn as DeletedOn790_,
document0_14_.Deleted as Deleted790_,
document0_14_.Active as Active790_,
document0_14_.ActivatedOn as Activate7_790_,
document0_14_.DeactivatedOn as Deactiva8_790_,
document0_14_.Locked as Locked790_,
document0_14_.aboriginal as aboriginal790_,
document0_14_.disability as disability790_,
document0_14_.minority as minority790_,
document0_14_.refuse as refuse790_,
document0_14_.CreateUserID as CreateU14_790_,
document0_14_.UpdateUserID as UpdateU15_790_,
document0_15_.CreatedOn as CreatedOn791_,
document0_15_.UpdatedOn as UpdatedOn791_,
document0_15_.DeletedOn as DeletedOn791_,
document0_15_.Deleted as Deleted791_,
document0_15_.Active as Active791_,
document0_15_.ActivatedOn as Activate7_791_,
document0_15_.DeactivatedOn as Deactiva8_791_,
document0_15_.Locked as Locked791_,
document0_15_.TypeOfTraining as TypeOfT10_791_,
document0_15_.Location as Location791_,
document0_15_.TrainerName as Trainer12_791_,
document0_15_.[Result] as Result13_791_,
document0_15_.TrainingDate as Trainin14_791_,
document0_15_.ExpiryDate as ExpiryDate791_,
document0_15_.CreateUserID as CreateU16_791_,
document0_15_.UpdateUserID as UpdateU17_791_,
document0_16_.CreatedOn as CreatedOn792_,
document0_16_.UpdatedOn as UpdatedOn792_,
document0_16_.DeletedOn as DeletedOn792_,
document0_16_.Deleted as Deleted792_,
document0_16_.Active as Active792_,
document0_16_.ActivatedOn as Activate7_792_,
document0_16_.DeactivatedOn as Deactiva8_792_,
document0_16_.Locked as Locked792_,
document0_16_.CreateUserID as CreateU10_792_,
document0_16_.UpdateUserID as UpdateU11_792_,
document0_17_.CreatedOn as CreatedOn793_,
document0_17_.UpdatedOn as UpdatedOn793_,
document0_17_.DeletedOn as DeletedOn793_,
document0_17_.Deleted as Deleted793_,
document0_17_.Active as Active793_,
document0_17_.ActivatedOn as Activate7_793_,
document0_17_.DeactivatedOn as Deactiva8_793_,
document0_17_.Locked as Locked793_,
document0_17_.Content as Content793_,
document0_17_.CreateUserID as CreateU11_793_,
document0_17_.UpdateUserID as UpdateU12_793_,
document0_18_.CreatedOn as CreatedOn795_,
document0_18_.UpdatedOn as UpdatedOn795_,
document0_18_.DeletedOn as DeletedOn795_,
document0_18_.Deleted as Deleted795_,
document0_18_.Active as Active795_,
document0_18_.ActivatedOn as Activate7_795_,
document0_18_.DeactivatedOn as Deactiva8_795_,
document0_18_.Locked as Locked795_,
document0_19_.CreatedOn as CreatedOn800_,
document0_19_.UpdatedOn as UpdatedOn800_,
document0_19_.DeletedOn as DeletedOn800_,
document0_19_.Deleted as Deleted800_,
document0_19_.Active as Active800_,
document0_19_.ActivatedOn as Activate7_800_,
document0_19_.DeactivatedOn as Deactiva8_800_,
document0_19_.Locked as Locked800_,
document0_20_.CreatedOn as CreatedOn802_,
document0_20_.UpdatedOn as UpdatedOn802_,
document0_20_.DeletedOn as DeletedOn802_,
document0_20_.Deleted as Deleted802_,
document0_20_.Active as Active802_,
document0_20_.ActivatedOn as Activate7_802_,
document0_20_.DeactivatedOn as Deactiva8_802_,
document0_20_.Locked as Locked802_,
document0_20_.StartDate as StartDate802_,
document0_20_.EndDate as EndDate802_,
document0_21_.CreatedOn as CreatedOn807_,
document0_21_.UpdatedOn as UpdatedOn807_,
document0_21_.DeletedOn as DeletedOn807_,
document0_21_.Deleted as Deleted807_,
document0_21_.Active as Active807_,
document0_21_.ActivatedOn as Activate7_807_,
document0_21_.DeactivatedOn as Deactiva8_807_,
document0_21_.Locked as Locked807_,
document0_21_.CreateUserID as CreateU18_807_,
document0_21_.UpdateUserID as UpdateU19_807_,
document0_21_.EducationLevelTypeID as Educati21_807_,
document0_22_.CreatedOn as CreatedOn808_,
document0_22_.UpdatedOn as UpdatedOn808_,
document0_22_.DeletedOn as DeletedOn808_,
document0_22_.Deleted as Deleted808_,
document0_22_.Active as Active808_,
document0_22_.ActivatedOn as Activate7_808_,
document0_22_.DeactivatedOn as Deactiva8_808_,
document0_22_.Locked as Locked808_,
document0_22_.CreateUserID as CreateU10_808_,
document0_22_.UpdateUserID as UpdateU11_808_,
document0_23_.CreatedOn as CreatedOn809_,
document0_23_.UpdatedOn as UpdatedOn809_,
document0_23_.DeletedOn as DeletedOn809_,
document0_23_.Deleted as Deleted809_,
document0_23_.Active as Active809_,
document0_23_.ActivatedOn as Activate7_809_,
document0_23_.DeactivatedOn as Deactiva8_809_,
document0_23_.Locked as Locked809_,
document0_24_.CreatedOn as CreatedOn810_,
document0_24_.UpdatedOn as UpdatedOn810_,
document0_24_.DeletedOn as DeletedOn810_,
document0_24_.Deleted as Deleted810_,
document0_24_.Active as Active810_,
document0_24_.ActivatedOn as Activate7_810_,
document0_24_.DeactivatedOn as Deactiva8_810_,
document0_24_.Locked as Locked810_,
document0_24_.CreateUserID as CreateU10_810_,
document0_24_.UpdateUserID as UpdateU11_810_,
document0_25_.CreatedOn as CreatedOn811_,
document0_25_.UpdatedOn as UpdatedOn811_,
document0_25_.DeletedOn as DeletedOn811_,
document0_25_.Deleted as Deleted811_,
document0_25_.Active as Active811_,
document0_25_.ActivatedOn as Activate7_811_,
document0_25_.DeactivatedOn as Deactiva8_811_,
document0_25_.Locked as Locked811_,
document0_26_.CreatedOn as CreatedOn815_,
document0_26_.UpdatedOn as UpdatedOn815_,
document0_26_.DeletedOn as DeletedOn815_,
document0_26_.Deleted as Deleted815_,
document0_26_.Active as Active815_,
document0_26_.ActivatedOn as Activate7_815_,
document0_26_.DeactivatedOn as Deactiva8_815_,
document0_26_.Locked as Locked815_,
document0_27_.CreatedOn as CreatedOn816_,
document0_27_.UpdatedOn as UpdatedOn816_,
document0_27_.DeletedOn as DeletedOn816_,
document0_27_.Deleted as Deleted816_,
document0_27_.Active as Active816_,
document0_27_.ActivatedOn as Activate7_816_,
document0_27_.DeactivatedOn as Deactiva8_816_,
document0_27_.Locked as Locked816_,
document0_27_.DateReceived as DateRec10_816_,
document0_27_.DateIssued as DateIssued816_,
document0_27_.CreateUserID as CreateU12_816_,
document0_27_.UpdateUserID as UpdateU13_816_,
document0_28_.CreatedOn as CreatedOn819_,
document0_28_.UpdatedOn as UpdatedOn819_,
document0_28_.DeletedOn as DeletedOn819_,
document0_28_.Deleted as Deleted819_,
document0_28_.Active as Active819_,
document0_28_.ActivatedOn as Activate7_819_,
document0_28_.DeactivatedOn as Deactiva8_819_,
document0_28_.Locked as Locked819_,
document0_28_.LicenceDocumentNumber as Licence10_819_,
document0_28_.DemeritPoints as Demerit11_819_,
document0_28_.MeritPoints as MeritPo12_819_,
document0_28_.ExpiryDate as ExpiryDate819_,
document0_28_.CreateUserID as CreateU14_819_,
document0_28_.UpdateUserID as UpdateU15_819_,
document0_28_.LicenceDocumentStatusTypeID as Licence16_819_,
document0_28_.StateProvinceID as StatePr17_819_,
document0_29_.CreatedOn as CreatedOn820_,
document0_29_.UpdatedOn as UpdatedOn820_,
document0_29_.DeletedOn as DeletedOn820_,
document0_29_.Deleted as Deleted820_,
document0_29_.Active as Active820_,
document0_29_.ActivatedOn as Activate7_820_,
document0_29_.DeactivatedOn as Deactiva8_820_,
document0_29_.Locked as Locked820_,
document0_29_.CreateUserID as CreateU10_820_,
document0_29_.UpdateUserID as UpdateU11_820_,
document0_30_.CreatedOn as CreatedOn821_,
document0_30_.UpdatedOn as UpdatedOn821_,
document0_30_.DeletedOn as DeletedOn821_,
document0_30_.Deleted as Deleted821_,
document0_30_.Active as Active821_,
document0_30_.ActivatedOn as Activate7_821_,
document0_30_.DeactivatedOn as Deactiva8_821_,
document0_30_.Locked as Locked821_,
document0_30_.ExpiryDate as ExpiryDate821_,
document0_30_.LicenceNumber as Licence11_821_,
document0_30_.CreateUserID as CreateU12_821_,
document0_30_.UpdateUserID as UpdateU13_821_,
document0_30_.StateProvinceID as StatePr14_821_,
document0_31_.CreatedOn as CreatedOn822_,
document0_31_.UpdatedOn as UpdatedOn822_,
document0_31_.DeletedOn as DeletedOn822_,
document0_31_.Deleted as Deleted822_,
document0_31_.Active as Active822_,
document0_31_.ActivatedOn as Activate7_822_,
document0_31_.DeactivatedOn as Deactiva8_822_,
document0_31_.Locked as Locked822_,
document0_32_.CreatedOn as CreatedOn823_,
document0_32_.UpdatedOn as UpdatedOn823_,
document0_32_.DeletedOn as DeletedOn823_,
document0_32_.Deleted as Deleted823_,
document0_32_.Active as Active823_,
document0_32_.ActivatedOn as Activate7_823_,
document0_32_.DeactivatedOn as Deactiva8_823_,
document0_32_.Locked as Locked823_,
document0_33_.CreatedOn as CreatedOn824_,
document0_33_.UpdatedOn as UpdatedOn824_,
document0_33_.DeletedOn as DeletedOn824_,
document0_33_.Deleted as Deleted824_,
document0_33_.Active as Active824_,
document0_33_.ActivatedOn as Activate7_824_,
document0_33_.DeactivatedOn as Deactiva8_824_,
document0_33_.Locked as Locked824_,
document0_33_.CreateUserID as CreateU10_824_,
document0_33_.UpdateUserID as UpdateU11_824_,
document0_34_.CreatedOn as CreatedOn825_,
document0_34_.UpdatedOn as UpdatedOn825_,
document0_34_.DeletedOn as DeletedOn825_,
document0_34_.Deleted as Deleted825_,
document0_34_.Active as Active825_,
document0_34_.ActivatedOn as Activate7_825_,
document0_34_.DeactivatedOn as Deactiva8_825_,
document0_34_.Locked as Locked825_,
document0_35_.CreatedOn as CreatedOn826_,
document0_35_.UpdatedOn as UpdatedOn826_,
document0_35_.DeletedOn as DeletedOn826_,
document0_35_.Deleted as Deleted826_,
document0_35_.Active as Active826_,
document0_35_.ActivatedOn as Activate7_826_,
document0_35_.DeactivatedOn as Deactiva8_826_,
document0_35_.Locked as Locked826_,
document0_35_.ExpiryDate as ExpiryDate826_,
document0_35_.CreateUserID as CreateU11_826_,
document0_35_.UpdateUserID as UpdateU12_826_,
document0_36_.CreatedOn as CreatedOn827_,
document0_36_.UpdatedOn as UpdatedOn827_,
document0_36_.DeletedOn as DeletedOn827_,
document0_36_.Deleted as Deleted827_,
document0_36_.Active as Active827_,
document0_36_.ActivatedOn as Activate7_827_,
document0_36_.DeactivatedOn as Deactiva8_827_,
document0_36_.Locked as Locked827_,
document0_36_.ExpiryDate as ExpiryDate827_,
document0_36_.CreateUserID as CreateU11_827_,
document0_36_.UpdateUserID as UpdateU12_827_,
document0_37_.CreatedOn as CreatedOn829_,
document0_37_.UpdatedOn as UpdatedOn829_,
document0_37_.DeletedOn as DeletedOn829_,
document0_37_.Deleted as Deleted829_,
document0_37_.Active as Active829_,
document0_37_.ActivatedOn as Activate7_829_,
document0_37_.DeactivatedOn as Deactiva8_829_,
document0_37_.Locked as Locked829_,
document0_37_.CheckDate as CheckDate829_,
document0_37_.CreateUserID as CreateU11_829_,
document0_37_.UpdateUserID as UpdateU12_829_,
document0_38_.CreatedOn as CreatedOn830_,
document0_38_.UpdatedOn as UpdatedOn830_,
document0_38_.DeletedOn as DeletedOn830_,
document0_38_.Deleted as Deleted830_,
document0_38_.Active as Active830_,
document0_38_.ActivatedOn as Activate7_830_,
document0_38_.DeactivatedOn as Deactiva8_830_,
document0_38_.Locked as Locked830_,
document0_39_.CreatedOn as CreatedOn831_,
document0_39_.UpdatedOn as UpdatedOn831_,
document0_39_.DeletedOn as DeletedOn831_,
document0_39_.Deleted as Deleted831_,
document0_39_.Active as Active831_,
document0_39_.ActivatedOn as Activate7_831_,
document0_39_.DeactivatedOn as Deactiva8_831_,
document0_39_.Locked as Locked831_,
document0_40_.CreatedOn as CreatedOn832_,
document0_40_.UpdatedOn as UpdatedOn832_,
document0_40_.DeletedOn as DeletedOn832_,
document0_40_.Deleted as Deleted832_,
document0_40_.Active as Active832_,
document0_40_.ActivatedOn as Activate7_832_,
document0_40_.DeactivatedOn as Deactiva8_832_,
document0_40_.Locked as Locked832_,
document0_41_.CreatedOn as CreatedOn833_,
document0_41_.UpdatedOn as UpdatedOn833_,
document0_41_.DeletedOn as DeletedOn833_,
document0_41_.Deleted as Deleted833_,
document0_41_.Active as Active833_,
document0_41_.ActivatedOn as Activate7_833_,
document0_41_.DeactivatedOn as Deactiva8_833_,
document0_41_.Locked as Locked833_,
document0_41_.CreateUserID as CreateU10_833_,
document0_41_.UpdateUserID as UpdateU11_833_,
document0_.Subtype as Subtype715_
from
Document document0_
left outer join
CustomDocument1 document0_1_
on document0_.ID=document0_1_.DocumentID
left outer join
CustomDocument2 document0_2_
on document0_.ID=document0_2_.DocumentID
left outer join
CustomDocument3 document0_3_
on document0_.ID=document0_3_.DocumentID
left outer join
CustomDocument4 document0_4_
on document0_.ID=document0_4_.DocumentID
left outer join
CustomDocument5 document0_5_
on document0_.ID=document0_5_.DocumentID
left outer join
CustomDocument6 document0_6_
on document0_.ID=document0_6_.DocumentID
left outer join
CustomDocument7 document0_7_
on document0_.ID=document0_7_.DocumentID
left outer join
CustomDocument8 document0_8_
on document0_.ID=document0_8_.DocumentID
left outer join
CustomDocument9 document0_9_
on document0_.ID=document0_9_.DocumentID
left outer join
CustomDocument10 document0_10_
on document0_.ID=document0_10_.DocumentID
left outer join
CustomDocument11 document0_11_
on document0_.ID=document0_11_.DocumentID
left outer join
CustomDocument12 document0_12_
on document0_.ID=document0_12_.DocumentID
left outer join
CustomDocument13 document0_13_
on document0_.ID=document0_13_.DocumentID
left outer join
CustomDocument14 document0_14_
on document0_.ID=document0_14_.DocumentID
left outer join
CustomDocument15 document0_15_
on document0_.ID=document0_15_.DocumentID
left outer join
CustomDocument16 document0_16_
on document0_.ID=document0_16_.DocumentID
left outer join
CustomDocument17 document0_17_
on document0_.ID=document0_17_.DocumentID
left outer join
CustomDocument18 document0_18_
on document0_.ID=document0_18_.DocumentID
left outer join
CustomDocument19 document0_19_
on document0_.ID=document0_19_.DocumentID
left outer join
CustomDocument20 document0_20_
on document0_.ID=document0_20_.DocumentID
left outer join
CustomDocument21 document0_21_
on document0_.ID=document0_21_.DocumentID
left outer join
CustomDocument22 document0_22_
on document0_.ID=document0_22_.DocumentID
left outer join
CustomDocument23 document0_23_
on document0_.ID=document0_23_.DocumentID
left outer join
CustomDocument24 document0_24_
on document0_.ID=document0_24_.DocumentID
left outer join
CustomDocument25 document0_25_
on document0_.ID=document0_25_.DocumentID
left outer join
CustomDocument26 document0_26_
on document0_.ID=document0_26_.DocumentID
left outer join
CustomDocument27 document0_27_
on document0_.ID=document0_27_.DocumentID
left outer join
CustomDocument28 document0_28_
on document0_.ID=document0_28_.DocumentID
left outer join
CustomDocument29 document0_29_
on document0_.ID=document0_29_.DocumentID
left outer join
CustomDocument30 document0_30_
on document0_.ID=document0_30_.DocumentID
left outer join
CustomDocument31 document0_31_
on document0_.ID=document0_31_.DocumentID
left outer join
CustomDocument32 document0_32_
on document0_.ID=document0_32_.DocumentID
left outer join
CustomDocument33 document0_33_
on document0_.ID=document0_33_.DocumentID
left outer join
CustomDocument34 document0_34_
on document0_.ID=document0_34_.DocumentID
left outer join
CustomDocument35 document0_35_
on document0_.ID=document0_35_.DocumentID
left outer join
CustomDocument36 document0_36_
on document0_.ID=document0_36_.DocumentID
left outer join
CustomDocument37 document0_37_
on document0_.ID=document0_37_.DocumentID
left outer join
CustomDocument38 document0_38_
on document0_.ID=document0_38_.DocumentID
left outer join
CustomDocument39 document0_39_
on document0_.ID=document0_39_.DocumentID
left outer join
CustomDocument40 document0_40_
on document0_.ID=document0_40_.DocumentID
left outer join
CustomDocument41 document0_41_
on document0_.ID=document0_41_.DocumentID
where
document0_.DocumentTypeID=?
and document0_.Locked=?
Thanks to #TabAlleman, #Ionic et al. The comments helped me realize that it is the calculation of the execution plan that is sucking up so many resources. This understanding led me to find this SO question asking about execution plans taking a long time to generate in SQL Server 2014.
I should have mentioned that we are using SQL Server 2014 as it turns out this version introduced an aggressive new query optimizer that has trouble with the query in question. If I set the database compatibility to SQL Server 2012, the execution plan is generated immediately.
I may still log a bug in SQL Connect as this query may represent an edge case that needs looking into.
Thanks all.
We have trouble with the solr Spatial queries some polygon queries just don´t work, we don´t know why. If you have a field of type solr.SpatialRecursivePrefixTreeFieldType
<!-- fieldType to store a location in the new format of Solr Version 4 -->
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees"/>
and make a Query on the field with the following filter-query:
fq=fieldname:"IsWithin(POLYGON((10.949260925162957 50.687958071020525, 10.963822885556231 50.68239399969996, 10.964563833856873 50.68427156144517, 10.96703711832961 50.68658303201778, 10.971062408240995 50.68545999328907, 10.973908368601569 50.68537639297307, 10.977245419297885 50.683455151899885, 10.987904529571237 50.68294282194555, 10.991325387038 50.67963515860285, 10.994120583977482 50.67953326334638, 10.99521208549133 50.6789077661364, 11.001058877152785 50.678738633565445, 11.001548604905265 50.67818764634437, 11.001856364353715 50.677835397891904, 11.00558285688531 50.67803512409588, 11.0081512617408 50.67851875352985, 11.006105355255587 50.6765931916203, 11.007343317894337 50.675840952835756, 11.00508803742539 50.67549090681522, 11.003645117340879 50.67430948629124, 11.005941540214492 50.67061936637505, 11.006219536083469 50.67014126679768, 11.001299804762878 50.67083752214686, 11.001290248726937 50.66994678133127, 11.001266698032165 50.66775142007361, 10.994310850026004 50.6686811276132, 10.99361484218618 50.66578680941357, 10.995238751284973 50.66272061868265, 10.991757060004929 50.66144878694344, 10.98564228736983 50.656057950464636, 10.972933054968484 50.65619159367484, 10.966916033500995 50.654632430958905, 10.96636369345939 50.64608677373722, 10.962270574823638 50.645743297249716, 10.960072993917557 50.646759811319946, 10.959183606001607 50.64697929266767, 10.953790500283061 50.64683862129752, 10.950513303019612 50.645987649473184, 10.94433093410472 50.64467990104971, 10.944139287321171 50.64387083905674, 10.938406478377123 50.64367676951595, 10.936564706423367 50.64344079815689, 10.935796834794198 50.64303879575035, 10.934872743703187 50.64257439164639, 10.93427419432756 50.64211775581536, 10.933160359264956 50.641024208099076, 10.930818579187104 50.638720535539385, 10.930731698801951 50.63850491325951, 10.930573248685782 50.63819957997579, 10.930514584183914 50.63797485471301, 10.930483968228721 50.63772303174961, 10.930509448204717 50.637417013430884, 10.930559495850991 50.63670600493446, 10.930609790537858 50.636021988733695, 10.93062319254464 50.635940959080145, 10.930918118427178 50.63346819840206, 10.929554613720612 50.63173063011565, 10.928233196678372 50.63073800085285, 10.927700297053727 50.630337678088054, 10.928523643504606 50.62943775333723, 10.92872309691077 50.62921974159881, 10.928265672945901 50.62878750906588, 10.927639188094208 50.628566694106404, 10.926255509527108 50.62951454513081, 10.92251019209241 50.62758567817641, 10.922638213078281 50.62684244467462, 10.920936313471174 50.62702387937161, 10.92057977557142 50.62670125843647, 10.920152680177981 50.62639688838215, 10.918545217179695 50.62538597524043, 10.917792182353438 50.62501079438114, 10.911101933460412 50.62182259063344, 10.910534063522139 50.62158167018572, 10.910220857740773 50.62134884112989, 10.909963518297891 50.62103483348087, 10.907487776980194 50.61609483529123, 10.907185632204035 50.61550204988257, 10.907056244585032 50.61525956691028, 10.906628481384871 50.61485617486339, 10.895152937829938 50.610730036478415, 10.896242368859731 50.61247186463941, 10.896470601420656 50.61270502268978, 10.89663156493272 50.61334330885494, 10.896634921258965 50.613739197264394, 10.896609690263567 50.61409919288572, 10.896528427773802 50.6145223648505, 10.896432183751319 50.61484661316548, 10.896045213866357 50.61590967155394, 10.89592075624567 50.616243013829695, 10.895851037118929 50.616360223083014, 10.89585240754103 50.616522177442015, 10.896067734815928 50.61689934415773, 10.896183689961353 50.61723186255236, 10.896260192619177 50.6179154274055, 10.896263393697025 50.61829332089865, 10.896237700111788 50.618599331654885, 10.896016371366 50.619184942393495, 10.895837465600053 50.61977040740378, 10.895659620811532 50.62048183664009, 10.89552077688743 50.62078823450612, 10.89543827592144 50.62106744627099, 10.89541440081784 50.62158939599526, 10.895417747434317 50.621985284440285, 10.895419953189784 50.62224621091522, 10.895535536566323 50.62253374263596, 10.895650816938675 50.62278528438301, 10.895907993767457 50.623090326427935, 10.89702205813367 50.62436418220272, 10.897394394709464 50.624902766276065, 10.897581866399983 50.62532501473681, 10.897627895017118 50.625747749544246, 10.897615356639628 50.62593674492591, 10.89758943824656 50.626215763590146, 10.897451201612462 50.62659414347733, 10.897157596764943 50.62700005028155, 10.896204881347344 50.62808304669058, 10.895980612498475 50.62832675371888, 10.895770334536648 50.628552416954996, 10.89550476578125 50.62893123030415, 10.895365743634875 50.629219633049715, 10.895298437344238 50.62962476083249, 10.895301175148079 50.629948669556875, 10.895818784010213 50.63130826952094, 10.896231728685844 50.63233529670317, 10.896329308521908 50.63324913379934, 10.896471808085538 50.634162815888054, 10.896387784931676 50.63484873155491, 10.895853362204946 50.63539335124816, 10.895409731359035 50.636051929955904, 10.894831087434723 50.63668239938101, 10.89384501665182 50.63694287338006, 10.89321877746772 50.63725925036571, 10.89295453697872 50.63788864146319, 10.892601884032173 50.638689738782595, 10.892158656701907 50.639405438006676, 10.89142586330462 50.64018326820631, 10.891249605392286 50.64110163233304, 10.891209792351503 50.64141668728772, 10.891144841137194 50.64210973155851, 10.891149583241901 50.64267657195861, 10.891137616301116 50.64293754635428, 10.891225677492942 50.64331515274541, 10.891298535787737 50.64356684242054, 10.891485499888212 50.643926118463014, 10.891671788482595 50.644204417006435, 10.891786196727102 50.6443479929879, 10.892544546820737 50.64534416832987, 10.893174209281039 50.6461788173941, 10.89351799460153 50.646672522785806, 10.893705215492075 50.64705878762453, 10.894882157433013 50.650689855006604, 10.89496919918023 50.65094149403119, 10.894994089923097 50.65100770424872, 10.894997994355002 50.65101034884133, 10.89526819691057 50.651193363455, 10.896169293366368 50.651475958949085, 10.897116063005601 50.65184409397104, 10.897793725703924 50.652270282727144, 10.89865162997703 50.652752981995214, 10.89955326530773 50.65309268499627, 10.900497891510984 50.65320368900172, 10.901396850557482 50.65322914045231, 10.902342714743133 50.653482964947386, 10.903109828708763 50.6538516751205, 10.903877201611301 50.65424894803099, 10.904724676108554 50.65470480867649, 10.905207763672205 50.654919062782206, 10.905577393216744 50.65510671959086, 10.90571963130609 50.65518720031583, 10.906032572458294 50.65536605678589, 10.906360295427413 50.65561684232866, 10.908203641750418 50.65761684566244, 10.908460620376147 50.65786787497885, 10.908759750304794 50.65808276386111, 10.90914317979857 50.65822537198042, 10.9096827055135 50.65841241475139, 10.910052143839932 50.65857306489363, 10.910322344422498 50.65871607046202, 10.910593099948478 50.658922057564695, 10.911461366599966 50.65946783407124, 10.913411561596815 50.66070256810259, 10.913667868428533 50.6608726087896, 10.914080443553491 50.66110507379473, 10.914449918280287 50.66126570988579, 10.91479092498766 50.661408451414985, 10.915358821001677 50.661595366186866, 10.915898410493476 50.66178237995819, 10.916565404597831 50.66196893251853, 10.918197483579679 50.66243092630801, 10.918680067924226 50.66257314454925, 10.918978548993268 50.662707029974975, 10.919547769889176 50.6630378833151, 10.9202031483812 50.66350338704778, 10.923424641120155 50.66438241716476, 10.92520056514587 50.66507772742578, 10.928643442713414 50.66691855773872, 10.931248634299681 50.668474484061434, 10.931482632159552 50.66928340878597, 10.93237915166098 50.66977493796525, 10.934586015828625 50.671098336511534, 10.935184017704177 50.671455998806955, 10.935810765428391 50.67185853851997, 10.9360388137638 50.67201963882665, 10.936252537002147 50.67216279720219, 10.93640887044287 50.6722251919134, 10.93797214347626 50.672840129973565, 10.93838469191684 50.6730455159511, 10.938683803183944 50.673233335093705, 10.938870320684071 50.6734935625849, 10.938944158876946 50.67381720153802, 10.938904808606113 50.67415026758631, 10.938906837075631 50.674366205911554, 10.93906453424018 50.67457255591528, 10.939249959577586 50.67471581619838, 10.940034490045216 50.675324682544115, 10.940291821850632 50.67558463848537, 10.940622161521706 50.676078257435236, 10.94075248591146 50.67638368467924, 10.940783437202692 50.67666249709234, 10.943222552787118 50.678524713221, 10.944035691536161 50.67915143877554, 10.944773250404303 50.679274574957105, 10.945325950398017 50.67931743817247, 10.945708292314846 50.67931596622919, 10.946768093608876 50.68189437491155, 10.94729335869263 50.68482498983269, 10.947961248322919 50.68588856337425, 10.949260925162957 50.687958071020525)))"
(even if the index is empty) solr hangs and loads forever without error logging or showing results. This happens to a lot of queries / polygons that we try to query. What are we doing wrong, or is the polygon search not yet usable in solr 4.5?
I found the answer here: http://wiki.apache.org/solr/SolrTomcat#Enabling_Longer_Query_Requests
Enabling Longer Query Requests
If you try to submit too long a GET query to Solr, then Tomcat will reject your HTTP request on the grounds that the HTTP header is too large; symptoms may include an HTTP 400 Bad Request error or (if you execute the query in a web browser) a blank browser window.
If you need to enable longer queries, you can set the maxHttpHeaderSize attribute on the HTTP Connector element in your server.xml file. The default value is 4K. (See http://tomcat.apache.org/tomcat-5.5-doc/config/http.html)
The polygons where just too long to submit to solr via GET-request. We changed the Tomcat settings now everything works fine.