Improve Performance by Avoiding Null Values

In your SOQL and SOSL queries, explicitly filtering out null values in the WHERE clause allows Salesforce to improve query performance. In the following example, any records where the Thread__c value is null are eliminated from the search.
1global with sharing class TagWS {
2
3/* getThreadTags
4*
5* a quick method to pull tags not in the existing list
6*
7*/
8   webservice static List<String> 
9   getThreadTags(String threadId, List<String> tags) {
10
11      System.debug(LoggingLevel.Debug,tags);
12
13      List<String> retVals = new List<String>();
14      Set<String> tagSet = new Set<String>();
15      Set<String> origTagSet = new Set<String>();
16      origTagSet.addAll(tags);
17
18// Note WHERE clause optimizes search where Thread__c is not null
19
20      for(CSO_CaseThread_Tag__c t : 
21         [SELECT Name FROM CSO_CaseThread_Tag__c 
22         WHERE Thread__c = :threadId AND
23         Thread__c != null 
24         WITH USER_MODE]) 
25
26      {
27         tagSet.add(t.Name);
28      }
29      for(String x : origTagSet) { 
30   // return a minus version of it so the UI knows to clear it
31         if(!tagSet.contains(x)) retVals.add('-' + x);
32      }
33      for(String x : tagSet) { 
34   // return a plus version so the UI knows it's new
35         if(!origTagSet.contains(x)) retvals.add('+' + x);
36      }
37
38      return retVals;
39   }
40}