I am experiencing a weird behavior using select query IN clause with a collection (I am using MSSQL on Azure).
I have the following code:
final Query query = em.createNativeQuery("select p.id as productId, p.external_id as externalId from products p where p.id in (:ids)");
// the ids list is of size 750
query.setParameter("ids", ids);
query.getResultList();
This code takes about 4 minutes to run, however running the query directly from the MSSQL client, it takes 1-2 seconds.
I was suspecting the in clause and I modified the code:
final String queryString = "select p.id as productId, p.external_id as externalId from products p where p.id in (%s)";
String inClause = ...; // generate a string of type 'id1', 'id2',...'id750'
final Query query = em.createNativeQuery(String.format(queryString, inClause));
query.getResultList();
The second version takes only 10 seconds to run.
Do you know any specific known problem running in clause queries? Can you suggest any solution how to get this working?
UPDATE:
I found out that the problem is actually happening with parameterized query, I tried to use a jdbc template and use my own wrapper to iterate over the results set. I iterated over the results set only printed the index, I could see that after about 590 results the results set hangs for about 3-4 minutes and then continues and finishes.
UPDATE: the id column which is the PK, is a char[36] column
I can see the query generated on Azure MSSSQL:
(#P749 nvarchar(4000),#P748 nvarchar(4000),#P747 nvarchar(4000),#P746 nvarchar(4000),#P745 nvarchar(4000),#P744 nvarchar(4000),#P743 nvarchar(4000),#P742 nvarchar(4000),#P741 nvarchar(4000),#P740 nvarchar(4000),#P739 nvarchar(4000),#P738 nvarchar(4000),#P737 nvarchar(4000),#P736 nvarchar(4000),#P735 nvarchar(4000),#P734 nvarchar(4000),#P733 nvarchar(4000),#P732 nvarchar(4000),#P731 nvarchar(4000),#P730 nvarchar(4000),#P729 nvarchar(4000),#P728 nvarchar(4000),#P727 nvarchar(4000),#P726 nvarchar(4000),#P725 nvarchar(4000),#P724 nvarchar(4000),#P723 nvarchar(4000),#P722 nvarchar(4000),#P721 nvarchar(4000),#P720 nvarchar(4000),#P719 nvarchar(4000),#P718 nvarchar(4000),#P717 nvarchar(4000),#P716 nvarchar(4000),#P715 nvarchar(4000),#P714 nvarchar(4000),#P713 nvarchar(4000),#P712 nvarchar(4000),#P711 nvarchar(4000),#P710 nvarchar(4000),#P709 nvarchar(4000),#P708 nvarchar(4000),#P707 nvarchar(4000),#P706 nvarchar(4000),#P705 nvarchar(4000),#P704 nvarchar(4000),#P703 nvarchar(4000),#P702 nvarchar(4000),#P701 nvarchar(4000),#P700 nvarchar(4000),#P699 nvarchar(4000),#P698 nvarchar(4000),#P697 nvarchar(4000),#P696 nvarchar(4000),#P695 nvarchar(4000),#P694 nvarchar(4000),#P693 nvarchar(4000),#P692 nvarchar(4000),#P691 nvarchar(4000),#P690 nvarchar(4000),#P689 nvarchar(4000),#P688 nvarchar(4000),#P687 nvarchar(4000),#P686 nvarchar(4000),#P685 nvarchar(4000),#P684 nvarchar(4000),#P683 nvarchar(4000),#P682 nvarchar(4000),#P681 nvarchar(4000),#P680 nvarchar(4000),#P679 nvarchar(4000),#P678 nvarchar(4000),#P677 nvarchar(4000),#P676 nvarchar(4000),#P675 nvarchar(4000),#P674 nvarchar(4000),#P673 nvarchar(4000),#P672 nvarchar(4000),#P671 nvarchar(4000),#P670 nvarchar(4000),#P669 nvarchar(4000),#P668 nvarchar(4000),#P667 nvarchar(4000),#P666 nvarchar(4000),#P665 nvarchar(4000),#P664 nvarchar(4000),#P663 nvarchar(4000),#P662 nvarchar(4000),#P661 nvarchar(4000),#P660 nvarchar(4000),#P659 nvarchar(4000),#P658 nvarchar(4000),#P657 nvarchar(4000),#P656 nvarchar(4000),#P655 nvarchar(4000),#P654 nvarchar(4000),#P653 nvarchar(4000),#P652 nvarchar(4000),#P651 nvarchar(4000),#P650 nvarchar(4000),#P649 nvarchar(4000),#P648 nvarchar(4000),#P647 nvarchar(4000),#P646 nvarchar(4000),#P645 nvarchar(4000),#P644 nvarchar(4000),#P643 nvarchar(4000),#P642 nvarchar(4000),#P641 nvarchar(4000),#P640 nvarchar(4000),#P639 nvarchar(4000),#P638 nvarchar(4000),#P637 nvarchar(4000),#P636 nvarchar(4000),#P635 nvarchar(4000),#P634 nvarchar(4000),#P633 nvarchar(4000),#P632 nvarchar(4000),#P631 nvarchar(4000),#P630 nvarchar(4000),#P629 nvarchar(4000),#P628 nvarchar(4000),#P627 nvarchar(4000),#P626 nvarchar(4000),#P625 nvarchar(4000),#P624 nvarchar(4000),#P623 nvarchar(4000),#P622 nvarchar(4000),#P621 nvarchar(4000),#P620 nvarchar(4000),#P619 nvarchar(4000),#P618 nvarchar(4000),#P617 nvarchar(4000),#P616 nvarchar(4000),#P615 nvarchar(4000),#P614 nvarchar(4000),#P613 nvarchar(4000),#P612 nvarchar(4000),#P611 nvarchar(4000),#P610 nvarchar(4000),#P609 nvarchar(4000),#P608 nvarchar(4000),#P607 nvarchar(4000),#P606 nvarchar(4000),#P605 nvarchar(4000),#P604 nvarchar(4000),#P603 nvarchar(4000),#P602 nvarchar(4000),#P601 nvarchar(4000),#P600 nvarchar(4000),#P599 nvarchar(4000),#P598 nvarchar(4000),#P597 nvarchar(4000),#P596 nvarchar(4000),#P595 nvarchar(4000),#P594 nvarchar(4000),#P593 nvarchar(4000),#P592 nvarchar(4000),#P591 nvarchar(4000),#P590 nvarchar(4000),#P589 nvarchar(4000),#P588 nvarchar(4000),#P587 nvarchar(4000),#P586 nvarchar(4000),#P585 nvarchar(4000),#P584 nvarchar(4000),#P583 nvarchar(4000),#P582 nvarchar(4000),#P581 nvarchar(4000),#P580 nvarchar(4000),#P579 nvarchar(4000),#P578 nvarchar(4000),#P577 nvarchar(4000),#P576 nvarchar(4000),#P575 nvarchar(4000),#P574 nvarchar(4000),#P573 nvarchar(4000),#P572 nvarchar(4000),#P571 nvarchar(4000),#P570 nvarchar(4000),#P569 nvarchar(4000),#P568 nvarchar(4000),#P567 nvarchar(4000),#P566 nvarchar(4000),#P565 nvarchar(4000),#P564 nvarchar(4000),#P563 nvarchar(4000),#P562 nvarchar(4000),#P561 nvarchar(4000),#P560 nvarchar(4000),#P559 nvarchar(4000),#P558 nvarchar(4000),#P557 nvarchar(4000),#P556 nvarchar(4000),#P555 nvarchar(4000),#P554 nvarchar(4000),#P553 nvarchar(4000),#P552 nvarchar(4000),#P551 nvarchar(4000),#P550 nvarchar(4000),#P549 nvarchar(4000),#P548 nvarchar(4000),#P547 nvarchar(4000),#P546 nvarchar(4000),#P545 nvarchar(4000),#P544 nvarchar(4000),#P543 nvarchar(4000),#P542 nvarchar(4000),#P541 nvarchar(4000),#P540 nvarchar(4000),#P539 nvarchar(4000),#P538 nvarchar(4000),#P537 nvarchar(4000),#P536 nvarchar(4000),#P535 nvarchar(4000),#P534 nvarchar(4000),#P533 nvarchar(4000),#P532 nvarchar(4000),#P531 nvarchar(4000),#P530 nvarchar(4000),#P529 nvarchar(4000),#P528 nvarchar(4000),#P527 nvarchar(4000),#P526 nvarchar(4000),#P525 nvarchar(4000),#P524 nvarchar(4000),#P523 nvarchar(4000),#P522 nvarchar(4000),#P521 nvarchar(4000),#P520 nvarchar(4000),#P519 nvarchar(4000),#P518 nvarchar(4000),#P517 nvarchar(4000),#P516 nvarchar(4000),#P515 nvarchar(4000),#P514 nvarchar(4000),#P513 nvarchar(4000),#P512 nvarchar(4000),#P511 nvarchar(4000),#P510 nvarchar(4000),#P509 nvarchar(4000),#P508 nvarchar(4000),#P507 nvarchar(4000),#P506 nvarchar(4000),#P505 nvarchar(4000),#P504 nvarchar(4000),#P503 nvarchar(4000),#P502 nvarchar(4000),#P501 nvarchar(4000),#P500 nvarchar(4000),#P499 nvarchar(4000),#P498 nvarchar(4000),#P497 nvarchar(4000),#P496 nvarchar(4000),#P495 nvarchar(4000),#P494 nvarchar(4000),#P493 nvarchar(4000),#P492 nvarchar(4000),#P491 nvarchar(4000),#P490 nvarchar(4000),#P489 nvarchar(4000),#P488 nvarchar(4000),#P487 nvarchar(4000),#P486 nvarchar(4000),#P485 nvarchar(4000),#P484 nvarchar(4000),#P483 nvarchar(4000),#P482 nvarchar(4000),#P481 nvarchar(4000),#P480 nvarchar(4000),#P479 nvarchar(4000),#P478 nvarchar(4000),#P477 nvarchar(4000),#P476 nvarchar(4000),#P475 nvarchar(4000),#P474 nvarchar(4000),#P473 nvarchar(4000),#P472 nvarchar(4000),#P471 nvarchar(4000),#P470 nvarchar(4000),#P469 nvarchar(4000),#P468 nvarchar(4000),#P467 nvarchar(4000),#P466 nvarchar(4000),#P465 nvarchar(4000),#P464 nvarchar(4000),#P463 nvarchar(4000),#P462 nvarchar(4000),#P461 nvarchar(4000),#P460 nvarchar(4000),#P459 nvarchar(4000),#P458 nvarchar(4000),#P457 nvarchar(4000),#P456 nvarchar(4000),#P455 nvarchar(4000),#P454 nvarchar(4000),#P453 nvarchar(4000),#P452 nvarchar(4000),#P451 nvarchar(4000),#P450 nvarchar(4000),#P449 nvarchar(4000),#P448 nvarchar(4000),#P447 nvarchar(4000),#P446 nvarchar(4000),#P445 nvarchar(4000),#P444 nvarchar(4000),#P443 nvarchar(4000),#P442 nvarchar(4000),#P441 nvarchar(4000),#P440 nvarchar(4000),#P439 nvarchar(4000),#P438 nvarchar(4000),#P437 nvarchar(4000),#P436 nvarchar(4000),#P435 nvarchar(4000),#P434 nvarchar(4000),#P433 nvarchar(4000),#P432 nvarchar(4000),#P431 nvarchar(4000),#P430 nvarchar(4000),#P429 nvarchar(4000),#P428 nvarchar(4000),#P427 nvarchar(4000),#P426 nvarchar(4000),#P425 nvarchar(4000),#P424 nvarchar(4000),#P423 nvarchar(4000),#P422 nvarchar(4000),#P421 nvarchar(4000),#P420 nvarchar(4000),#P419 nvarchar(4000),#P418 nvarchar(4000),#P417 nvarchar(4000),#P416 nvarchar(4000),#P415 nvarchar(4000),#P414 nvarchar(4000),#P413 nvarchar(4000),#P412 nvarchar(4000),#P411 nvarchar(4000),#P410 nvarchar(4000),#P409 nvarchar(4000),#P408 nvarchar(4000),#P407 nvarchar(4000),#P406 nvarchar(4000),#P405 nvarchar(4000),#P404 nvarchar(4000),#P403 nvarchar(4000),#P402 nvarchar(4000),#P401 nvarchar(4000),#P400 nvarchar(4000),#P399 nvarchar(4000),#P398 nvarchar(4000),#P397 nvarchar(4000),#P396 nvarchar(4000),#P395 nvarchar(4000),#P394 nvarchar(4000),#P393 nvarchar(4000),#P392 nvarchar(4000),#P391 nvarchar(4000),#P390 nvarchar(4000),#P389 nvarchar(4000),#P388 nvarchar(4000),#P387 nvarchar(4000),#P386 nvarchar(4000),#P385 nvarchar(4000),#P384 nvarchar(4000),#P383 nvarchar(4000),#P382 nvarchar(4000),#P381 nvarchar(4000),#P380 nvarchar(4000),#P379 nvarchar(4000),#P378 nvarchar(4000),#P377 nvarchar(4000),#P376 nvarchar(4000),#P375 nvarchar(4000),#P374 nvarchar(4000),#P373 nvarchar(4000),#P372 nvarchar(4000),#P371 nvarchar(4000),#P370 nvarchar(4000),#P369 nvarchar(4000),#P368 nvarchar(4000),#P367 nvarchar(4000),#P366 nvarchar(4000),#P365 nvarchar(4000),#P364 nvarchar(4000),#P363 nvarchar(4000),#P362 nvarchar(4000),#P361 nvarchar(4000),#P360 nvarchar(4000),#P359 nvarchar(4000),#P358 nvarchar(4000),#P357 nvarchar(4000),#P356 nvarchar(4000),#P355 nvarchar(4000),#P354 nvarchar(4000),#P353 nvarchar(4000),#P352 nvarchar(4000),#P351 nvarchar(4000),#P350 nvarchar(4000),#P349 nvarchar(4000),#P348 nvarchar(4000),#P347 nvarchar(4000),#P346 nvarchar(4000),#P345 nvarchar(4000),#P344 nvarchar(4000),#P343 nvarchar(4000),#P342 nvarchar(4000),#P341 nvarchar(4000),#P340 nvarchar(4000),#P339 nvarchar(4000),#P338 nvarchar(4000),#P337 nvarchar(4000),#P336 nvarchar(4000),#P335 nvarchar(4000),#P334 nvarchar(4000),#P333 nvarchar(4000),#P332 nvarchar(4000),#P331 nvarchar(4000),#P330 nvarchar(4000),#P329 nvarchar(4000),#P328 nvarchar(4000),#P327 nvarchar(4000),#P326 nvarchar(4000),#P325 nvarchar(4000),#P324 nvarchar(4000),#P323 nvarchar(4000),#P322 nvarchar(4000),#P321 nvarchar(4000),#P320 nvarchar(4000),#P319 nvarchar(4000),#P318 nvarchar(4000),#P317 nvarchar(4000),#P316 nvarchar(4000),#P315 nvarchar(4000),#P314 nvarchar(4000),#P313 nvarchar(4000),#P312 nvarchar(4000),#P311 nvarchar(4000),#P310 nvarchar(4000),#P309 nvarchar(4000),#P308 nvarchar(4000),#P307 nvarchar(4000),#P306 nvarchar(4000),#P305 nvarchar(4000),#P304 nvarchar(4000),#P303 nvarchar(4000),#P302 nvarchar(4000),#P301 nvarchar(4000),#P300 nvarchar(4000),#P299 nvarchar(4000),#P298 nvarchar(4000),#P297 nvarchar(4000),#P296 nvarchar(4000),#P295 nvarchar(4000),#P294 nvarchar(4000),#P293 nvarchar(4000),#P292 nvarchar(4000),#P291 nvarchar(4000),#P290 nvarchar(4000),#P289 nvarchar(4000),#P288 nvarchar(4000),#P287 nvarchar(4000),#P286 nvarchar(4000),#P285 nvarchar(4000),#P284 nvarchar(4000),#P283 nvarchar(4000),#P282 nvarchar(4000),#P281 nvarchar(4000),#P280 nvarchar(4000),#P279 nvarchar(4000),#P278 nvarchar(4000),#P277 nvarchar(4000),#P276 nvarchar(4000),#P275 nvarchar(4000),#P274 nvarchar(4000),#P273 nvarchar(4000),#P272 nvarchar(4000),#P271 nvarchar(4000),#P270 nvarchar(4000),#P269 nvarchar(4000),#P268 nvarchar(4000),#P267 nvarchar(4000),#P266 nvarchar(4000),#P265 nvarchar(4000),#P264 nvarchar(4000),#P263 nvarchar(4000),#P262 nvarchar(4000),#P261 nvarchar(4000),#P260 nvarchar(4000),#P259 nvarchar(4000),#P258 nvarchar(4000),#P257 nvarchar(4000),#P256 nvarchar(4000),#P255 nvarchar(4000),#P254 nvarchar(4000),#P253 nvarchar(4000),#P252 nvarchar(4000),#P251 nvarchar(4000),#P250 nvarchar(4000),#P249 nvarchar(4000),#P248 nvarchar(4000),#P247 nvarchar(4000),#P246 nvarchar(4000),#P245 nvarchar(4000),#P244 nvarchar(4000),#P243 nvarchar(4000),#P242 nvarchar(4000),#P241 nvarchar(4000),#P240 nvarchar(4000),#P239 nvarchar(4000),#P238 nvarchar(4000),#P237 nvarchar(4000),#P236 nvarchar(4000),#P235 nvarchar(4000),#P234 nvarchar(4000),#P233 nvarchar(4000),#P232 nvarchar(4000),#P231 nvarchar(4000),#P230 nvarchar(4000),#P229 nvarchar(4000),#P228 nvarchar(4000),#P227 nvarchar(4000),#P226 nvarchar(4000),#P225 nvarchar(4000),#P224 nvarchar(4000),#P223 nvarchar(4000),#P222 nvarchar(4000),#P221 nvarchar(4000),#P220 nvarchar(4000),#P219 nvarchar(4000),#P218 nvarchar(4000),#P217 nvarchar(4000),#P216 nvarchar(4000),#P215 nvarchar(4000),#P214 nvarchar(4000),#P213 nvarchar(4000),#P212 nvarchar(4000),#P211 nvarchar(4000),#P210 nvarchar(4000),#P209 nvarchar(4000),#P208 nvarchar(4000),#P207 nvarchar(4000),#P206 nvarchar(4000),#P205 nvarchar(4000),#P204 nvarchar(4000),#P203 nvarchar(4000),#P202 nvarchar(4000),#P201 nvarchar(4000),#P200 nvarchar(4000),#P199 nvarchar(4000),#P198 nvarchar(4000),#P197 nvarchar(4000),#P196 nvarchar(4000),#P195 nvarchar(4000),#P194 nvarchar(4000),#P193 nvarchar(4000),#P192 nvarchar(4000),#P191 nvarchar(4000),#P190 nvarchar(4000),#P189 nvarchar(4000),#P188 nvarchar(4000),#P187 nvarchar(4000),#P186 nvarchar(4000),#P185 nvarchar(4000),#P184 nvarchar(4000),#P183 nvarchar(4000),#P182 nvarchar(4000),#P181 nvarchar(4000),#P180 nvarchar(4000),#P179 nvarchar(4000),#P178 nvarchar(4000),#P177 nvarchar(4000),#P176 nvarchar(4000),#P175 nvarchar(4000),#P174 nvarchar(4000),#P173 nvarchar(4000),#P172 nvarchar(4000),#P171 nvarchar(4000),#P170 nvarchar(4000),#P169 nvarchar(4000),#P168 nvarchar(4000),#P167 nvarchar(4000),#P166 nvarchar(4000),#P165 nvarchar(4000),#P164 nvarchar(4000),#P163 nvarchar(4000),#P162 nvarchar(4000),#P161 nvarchar(4000),#P160 nvarchar(4000),#P159 nvarchar(4000),#P158 nvarchar(4000),#P157 nvarchar(4000),#P156 nvarchar(4000),#P155 nvarchar(4000),#P154 nvarchar(4000),#P153 nvarchar(4000),#P152 nvarchar(4000),#P151 nvarchar(4000),#P150 nvarchar(4000),#P149 nvarchar(4000),#P148 nvarchar(4000),#P147 nvarchar(4000),#P146 nvarchar(4000),#P145 nvarchar(4000),#P144 nvarchar(4000),#P143 nvarchar(4000),#P142 nvarchar(4000),#P141 nvarchar(4000),#P140 nvarchar(4000),#P139 nvarchar(4000),#P138 nvarchar(4000),#P137 nvarchar(4000),#P136 nvarchar(4000),#P135 nvarchar(4000),#P134 nvarchar(4000),#P133 nvarchar(4000),#P132 nvarchar(4000),#P131 nvarchar(4000),#P130 nvarchar(4000),#P129 nvarchar(4000),#P128 nvarchar(4000),#P127 nvarchar(4000),#P126 nvarchar(4000),#P125 nvarchar(4000),#P124 nvarchar(4000),#P123 nvarchar(4000),#P122 nvarchar(4000),#P121 nvarchar(4000),#P120 nvarchar(4000),#P119 nvarchar(4000),#P118 nvarchar(4000),#P117 nvarchar(4000),#P116 nvarchar(4000),#P115 nvarchar(4000),#P114 nvarchar(4000),#P113 nvarchar(4000),#P112 nvarchar(4000),#P111 nvarchar(4000),#P110 nvarchar(4000),#P109 nvarchar(4000),#P108 nvarchar(4000),#P107 nvarchar(4000),#P106 nvarchar(4000),#P105 nvarchar(4000),#P104 nvarchar(4000),#P103 nvarchar(4000),#P102 nvarchar(4000),#P101 nvarchar(4000),#P100 nvarchar(4000),#P99 nvarchar(4000),#P98 nvarchar(4000),#P97 nvarchar(4000),#P96 nvarchar(4000),#P95 nvarchar(4000),#P94 nvarchar(4000),#P93 nvarchar(4000),#P92 nvarchar(4000),#P91 nvarchar(4000),#P90 nvarchar(4000),#P89 nvarchar(4000),#P88 nvarchar(4000),#P87 nvarchar(4000),#P86 nvarchar(4000),#P85 nvarchar(4000),#P84 nvarchar(4000),#P83 nvarchar(4000),#P82 nvarchar(4000),#P81 nvarchar(4000),#P80 nvarchar(4000),#P79 nvarchar(4000),#P78 nvarchar(4000),#P77 nvarchar(4000),#P76 nvarchar(4000),#P75 nvarchar(4000),#P74 nvarchar(4000),#P73 nvarchar(4000),#P72 nvarchar(4000),#P71 nvarchar(4000),#P70 nvarchar(4000),#P69 nvarchar(4000),#P68 nvarchar(4000),#P67 nvarchar(4000),#P66 nvarchar(4000),#P65 nvarchar(4000),#P64 nvarchar(4000),#P63 nvarchar(4000),#P62 nvarchar(4000),#P61 nvarchar(4000),#P60 nvarchar(4000),#P59 nvarchar(4000),#P58 nvarchar(4000),#P57 nvarchar(4000),#P56 nvarchar(4000),#P55 nvarchar(4000),#P54 nvarchar(4000),#P53 nvarchar(4000),#P52 nvarchar(4000),#P51 nvarchar(4000),#P50 nvarchar(4000),#P49 nvarchar(4000),#P48 nvarchar(4000),#P47 nvarchar(4000),#P46 nvarchar(4000),#P45 nvarchar(4000),#P44 nvarchar(4000),#P43 nvarchar(4000),#P42 nvarchar(4000),#P41 nvarchar(4000),#P40 nvarchar(4000),#P39 nvarchar(4000),#P38 nvarchar(4000),#P37 nvarchar(4000),#P36 nvarchar(4000),#P35 nvarchar(4000),#P34 nvarchar(4000),#P33 nvarchar(4000),#P32 nvarchar(4000),#P31 nvarchar(4000),#P30 nvarchar(4000),#P29 nvarchar(4000),#P28 nvarchar(4000),#P27 nvarchar(4000),#P26 nvarchar(4000),#P25 nvarchar(4000),#P24 nvarchar(4000),#P23 nvarchar(4000),#P22 nvarchar(4000),#P21 nvarchar(4000),#P20 nvarchar(4000),#P19 nvarchar(4000),#P18 nvarchar(4000),#P17 nvarchar(4000),#P16 nvarchar(4000),#P15 nvarchar(4000),#P14 nvarchar(4000),#P13 nvarchar(4000),#P12 nvarchar(4000),#P11 nvarchar(4000),#P10 nvarchar(4000),#P9 nvarchar(4000),#P8 nvarchar(4000),#P7 nvarchar(4000),#P6 nvarchar(4000),#P5 nvarchar(4000),#P4 nvarchar(4000),#P3 nvarchar(4000),#P2 nvarchar(4000),#P1 nvarchar(4000),#P0 nvarchar(4000))select p.id as productId, p.external_id as externalId from products p where p.id in (#P0, #P1, #P2, #P3, #P4, #P5, #P6, #P7, #P8, #P9, #P10, #P11, #P12, #P13, #P14, #P15, #P16, #P17, #P18, #P19, #P20, #P21, #P22, #P23, #P24, #P25, #P26, #P27, #P28, #P29, #P30, #P31, #P32, #P33, #P34, #P35, #P36, #P37, #P38, #P39, #P40, #P41, #P42, #P43, #P44, #P45, #P46, #P47, #P48, #P49, #P50, #P51, #P52, #P53, #P54, #P55, #P56, #P57, #P58, #P59, #P60, #P61, #P62, #P63, #P64, #P65, #P66, #P67, #P68, #P69, #P70, #P71, #P72, #P73, #P74, #P75, #P76, #P77, #P78, #P79, #P80, #P81, #P82, #P83, #P84, #P85, #P86, #P87, #P88, #P89, #P90, #P91, #P92, #P93, #P94, #P95, #P96, #P97, #P98, #P99, #P100, #P101, #P102, #P103, #P104, #P105, #P106, #P107, #P108, #P109, #P110, #P111, #P112, #P113, #P114, #P115, #P116, #P117, #P118, #P119, #P120, #P121, #P122, #P123, #P124, #P125, #P126, #P127, #P128, #P129, #P130, #P131, #P132, #P133, #P134, #P135, #P136, #P137, #P138, #P139, #P140, #P141, #P142, #P143, #P144, #P145, #P146, #P147, #P148, #P149, #P150, #P151, #P152, #P153, #P154, #P155, #P156, #P157, #P158, #P159, #P160, #P161, #P162, #P163, #P164, #P165, #P166, #P167, #P168, #P169, #P170, #P171, #P172, #P173, #P174, #P175, #P176, #P177, #P178, #P179, #P180, #P181, #P182, #P183, #P184, #P185, #P186, #P187, #P188, #P189, #P190, #P191, #P192, #P193, #P194, #P195, #P196, #P197, #P198, #P199, #P200, #P201, #P202, #P203, #P204, #P205, #P206, #P207, #P208, #P209, #P210, #P211, #P212, #P213, #P214, #P215, #P216, #P217, #P218, #P219, #P220, #P221, #P222, #P223, #P224, #P225, #P226, #P227, #P228, #P229, #P230, #P231, #P232, #P233, #P234, #P235, #P236, #P237, #P238, #P239, #P240, #P241, #P242, #P243, #P244, #P245, #P246, #P247, #P248, #P249, #P250, #P251, #P252, #P253, #P254, #P255, #P256, #P257, #P258, #P259, #P260, #P261, #P262, #P263, #P264, #P265, #P266, #P267, #P268, #P269, #P270, #P271, #P272, #P273, #P274, #P275, #P276, #P277, #P278, #P279, #P280, #P281, #P282, #P283, #P284, #P285, #P286, #P287, #P288, #P289, #P290, #P291, #P292, #P293, #P294, #P295, #P296, #P297, #P298, #P299, #P300, #P301, #P302, #P303, #P304, #P305, #P306, #P307, #P308, #P309, #P310, #P311, #P312, #P313, #P314, #P315, #P316, #P317, #P318, #P319, #P320, #P321, #P322, #P323, #P324, #P325, #P326, #P327, #P328, #P329, #P330, #P331, #P332, #P333, #P334, #P335, #P336, #P337, #P338, #P339, #P340, #P341, #P342, #P343, #P344, #P345, #P346, #P347, #P348, #P349, #P350, #P351, #P352, #P353, #P354, #P355, #P356, #P357, #P358, #P359, #P360, #P361, #P362, #P363, #P364, #P365, #P366, #P367, #P368, #P369, #P370, #P371, #P372, #P373, #P374, #P375, #P376, #P377, #P378, #P379, #P380, #P381, #P382, #P383, #P384, #P385, #P386, #P387, #P388, #P389, #P390, #P391, #P392, #P393, #P394, #P395, #P396, #P397, #P398, #P399, #P400, #P401, #P402, #P403, #P404, #P405, #P406, #P407, #P408, #P409, #P410, #P411, #P412, #P413, #P414, #P415, #P416, #P417, #P418, #P419, #P420, #P421, #P422, #P423, #P424, #P425, #P426, #P427, #P428, #P429, #P430, #P431, #P432, #P433, #P434, #P435, #P436, #P437, #P438, #P439, #P440, #P441, #P442, #P443, #P444, #P445, #P446, #P447, #P448, #P449, #P450, #P451, #P452, #P453, #P454, #P455, #P456, #P457, #P458, #P459, #P460, #P461, #P462, #P463, #P464, #P465, #P466, #P467, #P468, #P469, #P470, #P471, #P472, #P473, #P474, #P475, #P476, #P477, #P478, #P479, #P480, #P481, #P482, #P483, #P484, #P485, #P486, #P487, #P488, #P489, #P490, #P491, #P492, #P493, #P494, #P495, #P496, #P497, #P498, #P499, #P500, #P501, #P502, #P503, #P504, #P505, #P506, #P507, #P508, #P509, #P510, #P511, #P512, #P513, #P514, #P515, #P516, #P517, #P518, #P519, #P520, #P521, #P522, #P523, #P524, #P525, #P526, #P527, #P528, #P529, #P530, #P531, #P532, #P533, #P534, #P535, #P536, #P537, #P538, #P539, #P540, #P541, #P542, #P543, #P544, #P545, #P546, #P547, #P548, #P549, #P550, #P551, #P552, #P553, #P554, #P555, #P556, #P557, #P558, #P559, #P560, #P561, #P562, #P563, #P564, #P565, #P566, #P567, #P568, #P569, #P570, #P571, #P572, #P573, #P574, #P575, #P576, #P577, #P578, #P579, #P580, #P581, #P582, #P583, #P584, #P585, #P586, #P587, #P588, #P589, #P590, #P591, #P592, #P593, #P594, #P595, #P596, #P597, #P598, #P599, #P600, #P601, #P602, #P603, #P604, #P605, #P606, #P607, #P608, #P609, #P610, #P611, #P612, #P613, #P614, #P615, #P616, #P617, #P618, #P619, #P620, #P621, #P622, #P623, #P624, #P625, #P626, #P627, #P628, #P629, #P630, #P631, #P632, #P633, #P634, #P635, #P636, #P637, #P638, #P639, #P640, #P641, #P642, #P643, #P644, #P645, #P646, #P647, #P648, #P649, #P650, #P651, #P652, #P653, #P654, #P655, #P656, #P657, #P658, #P659, #P660, #P661, #P662, #P663, #P664, #P665, #P666, #P667, #P668, #P669, #P670, #P671, #P672, #P673, #P674, #P675, #P676, #P677, #P678, #P679, #P680, #P681, #P682, #P683, #P684, #P685, #P686, #P687, #P688, #P689, #P690, #P691, #P692, #P693, #P694, #P695, #P696, #P697, #P698, #P699, #P700, #P701, #P702, #P703, #P704, #P705, #P706, #P707, #P708, #P709, #P710, #P711, #P712, #P713, #P714, #P715, #P716, #P717, #P718, #P719, #P720, #P721, #P722, #P723, #P724, #P725, #P726, #P727, #P728, #P729, #P730, #P731, #P732, #P733, #P734, #P735, #P736, #P737, #P738, #P739, #P740, #P741, #P742, #P743, #P744, #P745, #P746, #P747, #P748, #P749)
I was trying to contact Azure's support and they recommended to add a FORCESEEK hint to the query - Do you know how to add this query hint to the springdata repository?
Thank you.
The problem in this case is that the parameters are handles as Unicode (nvarchar) and my indexes where Ascii [char(36)]. Due to that reason it seems the searches are not executed using the indexes which make is very small. It seems like a normal behavior since Java strings are Unicode and there is no real way for the DB to down convert Unicode to Ascii.
After modifying my id columns (PK and FK) from char(36) to nchar(36) the parameterized queries run as expected and running a search with IN clause of 2,000 ids takes about 400msec instead of almost 10 minutes.
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.