Note that there are some explanatory texts on larger screens.

plurals
  1. POTSQL - query | Step by Step very fast - but as one query very slow
    primarykey
    data
    text
    <p>Can someone please tell me the difference... I don't know what's the problem and don't know how to describe it in a few words to search on stackoverflow on it ,) ........</p> <p>This select on my SQL Server 2008 R2 x64 takes about <strong>1min and 16secons</strong>:</p> <pre><code>select T_MESSAGE.MSG_GUID from T_MESSAGE where T_MESSAGE.MSG_BODY like @searchpattern or T_MESSAGE.MSG_COMMENT like @searchpattern or T_MESSAGE.MSG_SEDERDISPLAYINFORMATION like @searchpattern or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_ANDROID on T_RECIPIENT_ANDROID.RAND_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_ANDROID.RAND_DEVICETOKEN like @searchpattern) &gt; 0 or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_IOS on T_RECIPIENT_IOS.RIOS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_IOS.RIOS_DEVICETOKEN like @searchpattern) &gt; 0 or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_SMS on T_RECIPIENT_SMS.RSMS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_SMS.RSMS_PHONENUMBER like @searchpattern) &gt; 0 or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_SMTP on T_RECIPIENT_SMTP.RSMTP_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_SMTP.RSMTP_ADDRESS like @searchpattern) &gt; 0 </code></pre> <p>this code takes just a <strong>few milliseconds</strong>..</p> <pre><code>select T_MESSAGE.MSG_GUID from T_MESSAGE where T_MESSAGE.MSG_BODY like @searchpattern or T_MESSAGE.MSG_COMMENT like @searchpattern or T_MESSAGE.MSG_SEDERDISPLAYINFORMATION like @searchpattern or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_ANDROID on T_RECIPIENT_ANDROID.RAND_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_ANDROID.RAND_DEVICETOKEN like @searchpattern) &gt; 0 or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_IOS on T_RECIPIENT_IOS.RIOS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_IOS.RIOS_DEVICETOKEN like @searchpattern) &gt; 0 or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_SMS on T_RECIPIENT_SMS.RSMS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_SMS.RSMS_PHONENUMBER like @searchpattern) &gt; 0 </code></pre> <p>....yep! You're right I just removed one of my 'OR blocks'... but it doesn't matter which one I remove</p> <p>If I have more than 3 (!) the query takes a very long time (btw: also if the result of a block is 0 and not only the result also the table is empty)</p> <p>And now is comes...</p> <p>This one is also very fast (<strong>less than one second</strong>) and I have included all 'OR blocks'</p> <pre><code>declare @searchpattern as varchar(MAX) set @searchpattern = 'mysearchstring' declare @guidTable table ( MSG_GUID UniqueIdentifier ) insert into @guidTable select T_MESSAGE.MSG_GUID from T_MESSAGE where T_MESSAGE.MSG_BODY like @searchpattern or T_MESSAGE.MSG_COMMENT like @searchpattern or T_MESSAGE.MSG_SENDERDISPLAYINFORMATION like @searchpattern or (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_ANDROID on T_RECIPIENT_ANDROID.RAND_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_ANDROID.RAND_DEVICETOKEN like @searchpattern) &gt; 0 insert into @guidTable select T_MESSAGE.MSG_GUID from T_MESSAGE where (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_IOS on T_RECIPIENT_IOS.RIOS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_IOS.RIOS_DEVICETOKEN like @searchpattern) &gt; 0 insert into @guidTable select T_MESSAGE.MSG_GUID from T_MESSAGE where (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_SMS on T_RECIPIENT_SMS.RSMS_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_SMS.RSMS_PHONENUMBER like @searchpattern) &gt; 0 insert into @guidTable select T_MESSAGE.MSG_GUID from T_MESSAGE where (select COUNT(*) from T_RECIPIENT join T_RECIPIENT_SMTP on T_RECIPIENT_SMTP.RSMTP_REC_GUID = T_RECIPIENT.REC_GUID where T_RECIPIENT.REC_MSG_GUID = T_MESSAGE.MSG_GUID and T_RECIPIENT_SMTP.RSMTP_ADDRESS like @searchpattern) &gt; 0 select * from @guidTable </code></pre> <p>...i just split the selects and write the results query by query into a new declared table...</p> <p>Currently I sovled this tasks by creating a function in sql - but who can tell me what could be the problem?</p> <p>(btw: the DB has currently just about 5000 entries)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload