SOLR - How to handle inner Query - solr

How would we query this clause in the SOLR
and (Jobseeker.eid not in (select eid from jobseeker_emailresume where cid = #usecid# and datesent >= #createodbcdate(emaileddate)# ))
To do it in SOLR i am creating list of inner query result and then i am doing like this
-eid: (5210 OR 5357)
It works PERFECT with small data but for large data it generates Error. Like
-eid: (5210 OR 5357 OR 5405 OR 5408 OR 5492 OR 5575 OR 5700 OR 5817 OR 7179 OR 9054 OR 9358 OR 9947 OR 9948 OR 9953 OR 9999 OR 10086 OR 10290 OR 10430 OR 10492 OR 10835 OR 11022 OR 11144 OR 11250 OR 11289 OR 11417 OR 11459 OR 11571 OR 11885 OR 12033 OR 12322 OR 13130 OR 13511 OR 13712 OR 14237 OR 15103 OR 17193 OR 17929 OR 17930 OR 19110 OR 19111 OR 19979 OR 20165 OR 20182 OR 20653 OR 20754 OR 20813 OR 21878 OR 22049 OR 22057 OR 22262 OR 22298 OR 22506 OR 23372 OR 24114 OR 24617 OR 24897 OR 24986 OR 25252 OR 25842 OR 25924 OR 26202 OR 26225 OR 26230 OR 26937 OR 27239 OR 27511 OR 27903 OR 27904 OR 28113 OR 28153 OR 28280 OR 28342 OR 28459 OR 28611 OR 28635 OR 28726 OR 28806 OR 28842 OR 28852 OR 28921 OR 29033 OR 29034 OR 29313 OR 29415 OR 29502 OR 29742 OR 30633 OR 31149 OR 31406 OR 31545 OR 31653 OR 31822 OR 32585 OR 32678 OR 32784 OR 33239 OR 33291 OR 33778 OR 33875 OR 33966 OR 34153 OR 34249 OR 34549 OR 34559 OR 34598 OR 34873 OR 35084 OR 35183 OR 35230 OR 35268 OR 37163 OR 37226 OR 37920 OR 38503 OR 39127 OR 39311 OR 39428 OR 39838 OR 39976 OR 39977 OR 40094 OR 40226 OR 40804 OR 41591 OR 41592 OR 41593 OR 42967 OR 42968 OR 42969 OR 42970 OR 43984 OR 44102 OR 44391 OR 44441 OR 44442 OR 44443 OR 44906 OR 46454 OR 47307 OR 47308 OR 50076 OR 50800 OR 52786 OR 52865 OR 54051 OR 54713 OR 54795 OR 55244 OR 55347 OR 57156 OR 57519 OR 57530 OR 57935 OR 58160 OR 58715 OR 59089 OR 62793 OR 65067 OR 66103 OR 66755 OR 66879 OR 66895 OR 67307 OR 67557 OR 67558 OR 67559 OR 67929 OR 68328 OR 69549 OR 69949 OR 69950 OR 70374 OR 70397 OR 71441 OR 71442 OR 72188 OR 72227 OR 72850 OR 73268 OR 73572 OR 73573 OR 73574 OR 75603 OR 76204 OR 77218 OR 77965 OR 78594 OR 81761 OR 81785 OR 81958 OR 82557 OR 83013 OR 83610 OR 83748 OR 83805 OR 84204 OR 84392 OR 85277 OR 85611 OR 85687 OR 85771 OR 85940 OR 86147 OR 86419 OR 86503 OR 86526 OR 86773 OR 86807 OR 86825 OR 87212 OR 87524 OR 87586 OR 87599 OR 87601 OR 87836 OR 87843 OR 87891 OR 88043 OR 88065 OR 88080 OR 88171 OR 88282 OR 88345 OR 88541 OR 88565 OR 88571 OR 88610 OR 88932 OR 88980 OR 88998 OR 89253 OR 89334 OR 89534 OR 89775 OR 89903 OR 90201 OR 90721 OR 90780 OR 90786 OR 90973 OR 91167 OR 91235 OR 91356 OR 91436 OR 91469 OR 92098 OR 92319 OR 92358 OR 92379 OR 92407 OR 92933 OR 92974 OR 93844 OR 93857 OR 93859 OR 94165 OR 94332 OR 94400 OR 94543 OR 94590 OR 94608 OR 94764 OR 95006 OR 95185 OR 95186 OR 95200 OR 95372 OR 95516 OR 95535 OR 95691 OR 95844 OR 95858 OR 95890 OR 96032 OR 96127 OR 96333 OR 96402 OR 96411 OR 96516 OR 96642 OR 96717 OR 96746 OR 98073 OR 98192 OR 100637 OR 100778 OR 100801 OR 101278 OR 102111 OR 102901 OR 105136 OR 105324 OR 105361 OR 105423 OR 105953 OR 106042 OR 106307 OR 107282 OR 107554 OR 107682 OR 107909 OR 109035 OR 109866 OR 110052 OR 110239 OR 110482 OR 110582 OR 110614 OR 110905 OR 110910 OR 110918 OR 110940 OR 110982 OR 111103 OR 111214 OR 111555 OR 111559 OR 111588 OR 111671 OR 111694 OR 111994 OR 112156 OR 112201 OR 112289 OR 112533 OR 112543 OR 112723 OR 112764 OR 112767 OR 112931 OR 113229 OR 113380 OR 113912 OR 114591 OR 116450 OR 116479 OR 116602 OR 116914 OR 117119 OR 117439 OR 117591 OR 118100 OR 118277 OR 119008 OR 119150 OR 119936 OR 119988 OR 120225 OR 120394 OR 121408 OR 121604 OR 121652 OR 122078 OR 122229 OR 122338 OR 122460 OR 122548 OR 122691 OR 122887 OR 122954 OR 123121 OR 123334 OR 123617 OR 123773 OR 124005 OR 124116 OR 124488 OR 125024 OR 125768 OR 126244 OR 126255 OR 126408 OR 127314 OR 127333 OR 127524 OR 127835 OR 129178 OR 129751 OR 129866 OR 130052 OR 131160 OR 131324 OR 132218 OR 132774 OR 132821 OR 133195 OR 134343 OR 134467 OR 134881 OR 134944 OR 135164 OR 135237 OR 135401 OR 135798 OR 135841 OR 136082 OR 136302 OR 136448 OR 136534 OR 137779 OR 137975 OR 139485 OR 139756 OR 140653 OR 140863 OR 141163 OR 141299 OR 141688 OR 141990 OR 142498 OR 142906 OR 142949 OR 143705 OR 143746 OR 143824 OR 143871 OR 145840 OR 146122 OR 146942 OR 147171 OR 147294 OR 147561 OR 148267 OR 148440 OR 148745 OR 148828 OR 148893 OR 149351 OR 149689 OR 150281 OR 150460 OR 151143 OR 151317 OR 151400 OR 152527 OR 153523 OR 153674 OR 153682 OR 154264 OR 154726 OR 155019 OR 155271 OR 156261 OR 156734 OR 157062 OR 157532 OR 157787 OR 157989 OR 159032 OR 160365 OR 160686 OR 161064 OR 161199 OR 162974 OR 162976 OR 163037 OR 163041 OR 163083 OR 164013 OR 164308 OR 165056 OR 166001 OR 167875 OR 168324 OR 168465 OR 168476 OR 168481 OR 168805 OR 168971 OR 169667 OR 169781 OR 169791 OR 169799 OR 169823 OR 169839 OR 169856 OR 169861 OR 169906 OR 170054 OR 171688 OR 171918 OR 173448 OR 173693 OR 174269 OR 174759 OR 174912 OR 175261 OR 175456 OR 176489 OR 176530 OR 176817 OR 177421 OR 177718 OR 178016 OR 178568 OR 178658 OR 178784 OR 179218 OR 179502 OR 180755 OR 181379 OR 181444 OR 182098 OR 182188 OR 182239 OR 182353 OR 182844 OR 182881 OR 183303 OR 183916 OR 183988 OR 184592 OR 184650 OR 184748 OR 184929 OR 185504 OR 187055 OR 187957 OR 188624 OR 188742 OR 190526 OR 190629 OR 191002 OR 191788 OR 192750 OR 192986 OR 195237 OR 196425 OR 196724 OR 196854 OR 197644 OR 198748 OR 198779 OR 198854 OR 199987 OR 200263 OR 201314 OR 201554 OR 202916 OR 203482 OR 203692 OR 204459 OR 206788 OR 206899 OR 207005 OR 208235 OR 208911 OR 209473 OR 209556 OR 210399 OR 211285 OR 212181 OR 213541 OR 213964 OR 214121 OR 216028 OR 216099 OR 216350 OR 216671 OR 216993 OR 217188 OR 217370 OR 217908 OR 218010 OR 219557 OR 219577 OR 220999 OR 221478 OR 222383 OR 222859 OR 224069 OR 224193 OR 227344 OR 227755 OR 229869 OR 230524 OR 232757 OR 280657 OR 280778 OR 281397 OR 281457 OR 281579 OR 281696 OR 281869 OR 282037 OR 282428 OR 282833 OR 282847 OR 282863 OR 283643 OR 283900 OR 286425 OR 286669 OR 290646 OR 290652 OR 291032 OR 291627 OR 291690 OR 291937 OR 291988 OR 292571 OR 292954 OR 293107 OR 293140 OR 293770 OR 300440 OR 300676 OR 364729 OR 396076 OR 399672 OR 401771 OR 404663 OR 407833 OR 408291 OR 408417 OR 409144 OR 409869 OR 409932 OR 409972 OR 413848 OR 417121 OR 417175 OR 417271 OR 417731 OR 420873 OR 421311 OR 423860 OR 427704 OR 429494 OR 431623 OR 434445 OR 434770 OR 435192 OR 435272 OR 435691 OR 435789 OR 435806 OR 439094 OR 440242 OR 440775 OR 442692 OR 444563 OR 446094 OR 446317 OR 446329 OR 446613 OR 448782 OR 449934 OR 450137 OR 450291 OR 451289 OR 451378 OR 451449 OR 451533 OR 451539 OR 453204 OR 454019 OR 454117 OR 454225 OR 454289 OR 454626 OR 454645 OR 455264 OR 455290 OR 456226 OR 458453 OR 460800 OR 469149 OR 471859 OR 472154 OR 472344 OR 472484 OR 478639 OR 478899 OR 479693 OR 481099 OR 482096 OR 482188 OR 482669 OR 482737 OR 483798 OR 483997 OR 484034 OR 484194 OR 484829 OR 485099 OR 486072 OR 486118 OR 486292 OR 486360 OR 491205 OR 491275 OR 491565 OR 491723 OR 491864 OR 492085 OR 492101 OR 492146 OR 492157 OR 492317 OR 492331 OR 493187 OR 493320 OR 493335 OR 493450 OR 493493 OR 494028 OR 494134 OR 494246 OR 494443 OR 494509 OR 495028 OR 496430 OR 496731 OR 496783 OR 497485 OR 497815 OR 498808 OR 500728 OR 500930 OR 501121 OR 501373 OR 501870 OR 502361 OR 502952 OR 503053 OR 503147 OR 503379 OR 503964 OR 504193 OR 504603 OR 505969 OR 506023 OR 507031 OR 507783 OR 507798 OR 508141 OR 508318 OR 509092 OR 509641 OR 510189 OR 510448 OR 510532 OR 510999 OR 511803 OR 511959 OR 512096 OR 512487 OR 513490 OR 514019 OR 514020 OR 514223 OR 514481 OR 514539 OR 515171 OR 515184 OR 515492 OR 515564 OR 515723 OR 515750 OR 516834 OR 517032 OR 517070 OR 517179 OR 517956 OR 517959 OR 518742 OR 519145 OR 519156 OR 519317 OR 519474 OR 519615 OR 519648 OR 521519 OR 521556 OR 524181 OR 524972 OR 525103 OR 525163)

You need to make sure that your inner query does not exceed the maximum number of allowed boolean clauses. This maximum number can be configured in the configuration script.

Without knowing your domain logic a bit better, you may want to try to denormalize the logic in that subquery into your Solr search query. You have a subquery that's testing values that could themselves be indexed into Solr, allowing you to still do the bulk of your querying from Solr, and saving you from having to pass in a huge list of 'approved' IDs.
Solr by default has a limit of 1,024 OR clauses. If you bump into this limit, you're probably doing something that's not really a good fit for Solr.

Related

MS SQl show empty results

Below query is matching if the partner code below is having asset code, but if no match its not showing it.
i need even if the partner_code is not having asset code to show any result null or 0
select Asset_code, partner_code from Asset
where PARTNER_CODE in ('28800330',
'28800332',
'28800014',
'41900139',
'28800210',
'29200298',
'29200149',
'29200259',
'29200086',
'29400280',
'29000314',
'29000224',
'29600306',
'29100045',
'29800530',
'29800543',
'29900474',
'29700298',
'27400112',
'27400648',
'27400668',
'85400058',
'27300472',
'53200002',
'27800221',
'27800039',
'27200013')

SQL Server hangs when running query with multiple joins on empty tables

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.

SQL Server : geography data type: GeomFromGml

I have troubles to load data into a geography data type:
DECLARE #g geography;
DECLARE #x xml;
SET #x = '<gml:MultiSurface gml:id="HVO.20584" srsName="urn:ogc:def:crs:EPSG::5514" srsDimension="2" xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:surfaceMember>
<gml:Polygon gml:id="HVO.20584.1">
<gml:exterior>
<gml:LinearRing>
<gml:posList>-747267.00 -1056204.00 -747226.00 -1056232.00 -747239.00 -1056253.00 -747251.00 -1056278.00 -747267.00 -1056315.00 -747291.00 -1056365.00 -747337.00 -1056470.00 -747311.00 -1056474.00 -747244.00 -1056475.00 -747155.00 -1056467.00 -747077.00 -1056501.00 -747112.00 -1057366.00 -747263.00 -1057857.00 -747263.20 -1057857.05 -747263.30 -1057856.60 -747272.50 -1057858.50 -747276.10 -1057850.21 -747285.47 -1057849.89 -747295.34 -1057849.55 -747308.73 -1057848.34 -747320.38 -1057847.28 -747346.97 -1057857.70 -747358.66 -1057860.00 -747374.12 -1057860.55 -747386.06 -1057860.19 -747407.98 -1057859.54 -747444.60 -1057874.26 -747447.75 -1057879.52 -747454.57 -1057890.92 -747674.02 -1057865.46 -747851.54 -1057841.44 -747855.78 -1057838.67 -747871.68 -1057851.47 -747902.20 -1057870.55 -747916.06 -1057881.32 -747934.07 -1057891.87 -747960.03 -1057915.53 -747985.14 -1057954.40 -748001.13 -1057977.02 -748021.22 -1058003.59 -748088.58 -1058092.68 -748104.73 -1058095.49 -748166.00 -1058032.60 -748193.50 -1058002.40 -748214.40 -1057982.20 -748216.40 -1057988.60 -748293.20 -1058053.20 -748297.14 -1058050.03 -748302.55 -1058045.67 -748306.53 -1058042.47 -748311.89 -1058038.15 -748316.50 -1058034.44 -748320.83 -1058030.95 -748330.04 -1058023.54 -748332.15 -1058021.83 -748337.10 -1058017.85 -748341.39 -1058014.39 -748353.30 -1058004.80 -748347.67 -1057996.70 -748338.28 -1057981.31 -748335.70 -1057977.29 -748332.12 -1057971.71 -748330.30 -1057968.92 -748325.55 -1057961.32 -748317.05 -1057947.55 -748310.89 -1057935.02 -748307.10 -1057924.52 -748302.70 -1057912.35 -748298.54 -1057900.12 -748295.48 -1057891.13 -748286.20 -1057862.27 -748278.37 -1057838.25 -748276.55 -1057834.04 -748267.49 -1057808.20 -748264.92 -1057798.33 -748262.21 -1057787.93 -748254.57 -1057761.59 -748251.89 -1057752.13 -748247.59 -1057736.93 -748240.11 -1057716.13 -748237.47 -1057685.67 -748234.93 -1057657.42 -748234.51 -1057652.51 -748234.98 -1057625.54 -748234.51 -1057622.46 -748231.40 -1057602.21 -748233.13 -1057596.29 -748234.13 -1057592.87 -748237.61 -1057582.60 -748238.48 -1057580.02 -748249.72 -1057571.70 -748250.10 -1057571.42 -748252.39 -1057569.73 -748256.83 -1057563.57 -748258.55 -1057540.99 -748250.24 -1057535.67 -748250.94 -1057526.41 -748243.01 -1057522.35 -748236.51 -1057522.75 -748234.73 -1057522.86 -748230.54 -1057518.95 -748211.65 -1057501.36 -748199.48 -1057493.59 -748189.98 -1057489.26 -748179.90 -1057484.66 -748168.54 -1057470.65 -748168.29 -1057470.34 -748165.98 -1057467.49 -748157.92 -1057458.13 -748147.31 -1057450.99 -748146.04 -1057423.54 -748145.40 -1057410.42 -748144.91 -1057400.47 -748144.08 -1057372.43 -748142.62 -1057348.91 -748142.48 -1057347.16 -748141.05 -1057329.37 -748142.26 -1057321.94 -748146.21 -1057304.13 -748148.14 -1057295.42 -748146.30 -1057289.44 -748144.73 -1057284.34 -748141.64 -1057275.31 -748144.63 -1057272.64 -748154.01 -1057247.80 -748151.29 -1057246.55 -748127.50 -1057235.56 -748110.70 -1057228.23 -748082.39 -1057214.75 -748057.48 -1057203.76 -748041.82 -1057196.01 -748029.14 -1057189.74 -748010.10 -1057178.36 -747979.25 -1057161.25 -747957.25 -1057147.63 -747943.14 -1057138.66 -747937.35 -1057131.26 -747926.97 -1057121.60 -747909.48 -1057109.13 -747904.01 -1057106.36 -747895.25 -1057106.99 -747873.33 -1057094.64 -747869.74 -1057093.00 -747851.77 -1057082.31 -747869.79 -1057044.54 -747836.92 -1057032.09 -747795.65 -1057016.73 -747793.70 -1057009.93 -747787.82 -1056992.87 -747781.28 -1056974.44 -747776.81 -1056960.35 -747768.14 -1056933.57 -747762.16 -1056911.71 -747757.80 -1056895.21 -747753.30 -1056877.50 -747749.17 -1056859.18 -747744.25 -1056838.69 -747741.79 -1056821.91 -747739.99 -1056803.90 -747737.12 -1056781.92 -747735.82 -1056761.48 -747735.01 -1056740.42 -747736.57 -1056718.66 -747738.55 -1056694.68 -747741.17 -1056669.07 -747744.02 -1056634.01 -747745.17 -1056623.46 -747748.09 -1056596.69 -747755.37 -1056564.46 -747759.01 -1056547.20 -747761.29 -1056536.38 -747761.56 -1056535.10 -747772.54 -1056491.85 -747774.05 -1056485.90 -747786.35 -1056435.41 -747786.99 -1056433.22 -747796.41 -1056400.93 -747799.01 -1056392.00 -747799.01 -1056392.00 -747799.00 -1056392.00 -747723.00 -1056390.00 -747615.00 -1056374.00 -747596.00 -1056372.00 -747564.00 -1056375.00 -747539.00 -1056382.00 -747513.00 -1056389.00 -747487.00 -1056344.00 -747472.00 -1056316.00 -747458.00 -1056290.00 -747455.00 -1056283.00 -747445.00 -1056265.00 -747433.00 -1056243.00 -747424.00 -1056225.00 -747420.00 -1056218.00 -747412.00 -1056205.00 -747399.00 -1056188.00 -747388.00 -1056173.00 -747383.00 -1056167.00 -747371.00 -1056154.00 -747370.00 -1056153.00 -747362.00 -1056145.00 -747356.00 -1056141.00 -747356.00 -1056140.00 -747334.00 -1056160.00 -747267.00 -1056204.00</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
</gml:MultiSurface>';
SET #g = geography::GeomFromGml(#x, 4326);
I get this exception:
A .NET Framework error occurred during execution of user-defined
routine or aggregate "geography": System.FormatException: 24129: The
given XML instance is not valid because the top-level tag is
gml:MultiSurface. The top-level element of the input Geographic Markup
Language (GML) must contain a Point, LineString, Polygon, MultiPoint,
MultiGeometry, MultiCurve, MultiSurface, Arc, ArcString,
CompositeCurve, PolygonPatch or FullGlobe (geography Data Type only)
object.
What do I need to change in the #x variable to get it working?
Thanks
Note, the answer here refers to the question of dealing with the coordinates above, that are not geodesic, as raised in the comments, and not with the original question of parsing the XML, which was answered in the comments.
After a bit of digging, it seems that the Czech Republic's projection is now known as http://spatialreference.org/ref/sr-org/czech-s-jtsk-gis-esri102067/. If you look at that page you will see that the coordinates are in meters, and are negative, just as in your XML above. This WKT representation gives you information about the datum, spheroid and other characteristics of the projection.
SQL Server does not currently support projecting from one coordinate system to another, so you have two options.
1). Load it as is, but as a geometry not a geography datatype, so your last line above would become
SET #g = geometry::GeomFromGml(#x, 5514);
where 9819 appears to be the SRID code in the above link (although it is all a bit unclear). This actually doesn't matter that much, as you can't convert from one spatial reference system to another, but you will be able to perform any geometry functions on your geometries, such as STIntersects, STContains, STBuffer, etc.
2). Convert it to lat/lon (4326) outside of SQL Server and then import as a geography data type, if that it what you really want. There is as tool called gdaltransform which does this, eg,
gdaltransform -s_srs "+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=0 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +units=m +no_defs" -t_srs EPSG:4326
-747267.00 -1056204.00
24.8307791587916 50.4239544736181 32.0127759873867
14.3847700978484 49.9644982150517 45.4088854994625
where you enter the first line, with the projection info, hit Return, then enter the coordinates and then you get the answer. From this you can see that it is giving a lat/lon 14.38, 49.96, which is in Prague, so definitely the Czech Republic.
This approach isn't very scalable, so you would probably want to look at something like Proj4j which is a Java library for doing coordinate transforms.

Solr Polygon Search issues

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.

GAE ndb.query.filter() not working

I have a Story model that inherits from ndb.Model, with an IntegerProperty wordCount. I'm trying to query Story objects that have a specific word count range, but the query seems to return the same results, regardless of the filter properties.
For this code:
q = Story.query()
q.filter(Story.wordCount > 900)
for s in q.fetch(5):
print s.title / s.wordCount
I get this result:
If only ... / 884
Timed release / 953
Grandfather paradox / 822
Harnessing the brane-deer / 1618
Quantum erat demonstrandum / 908
Here's the story declaration:
class Story(ndb.Model):
title = ndb.StringProperty(required=True)
wordCount = ndb.IntegerProperty('wc')
I would expect to only get stories that have 900 words exactly--or none. Inequalities and sorting are also broken. I tried deploying to GAE, and I'm seeing the same broken results.
Any ideas on what would be causing this?
NDB queries are immutable, and when you call q.filter(Story.wordCount > 900) you're creating a new query, and not assigning it to anything. Re-assigning to your q variable should work for you:
q = Story.query()
q = q.filter(Story.wordCount > 900)
for s in q.fetch(5):
print s.title / s.wordCount

Resources