title: DocumentDB: Performance impact of built-in string functions (like UPPER)
body: <p>In our .NET application we use the DocumentDB SDK to query our Azure DocumentDB. 
  We were trying to find the cause of a performance problem when we realized that the built-in string functions in queries seems to have a big impact on performance.</p>
  
  <p>I was going to paste some stats that I got from our application but I've been able to replicate the situation with the playground here:
  <a href="https://www.documentdb.com/sql/demo" rel="nofollow noreferrer">https://www.documentdb.com/sql/demo</a> (click on the sandbox tab)</p>
  
  <p>With the following query:</p>
  
  <pre><code>SELECT *
  FROM food 
  WHERE food.description="Babyfood, dessert, fruit pudding, orange, strained"
  </code></pre>
  
  <p>I get:</p>
  
  <p><a href="https://i.stack.imgur.com/m0QH0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m0QH0.png" alt="Query with no UPPER function"></a></p>
  
  <p>And with <code>UPPER</code> string function:</p>
  
  <pre><code>SELECT *
  FROM food 
  WHERE UPPER(food.description)=UPPER("Babyfood, dessert, fruit pudding, orange, strained")
  </code></pre>
  
  <p>I get:</p>
  
  <p><a href="https://i.stack.imgur.com/Ey2TJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ey2TJ.png" alt="Query with UPPER string function"></a></p>
  
  <p>The absolute numbers don't really matter here, in our application we apply <code>UPPER</code> on an email field and we see a big difference. Operation takes 1s with no <code>UPPER</code> vs 20s with it!</p>