title: Avoid heavy calculations in a view
body: <p>I work with large table (5 billions rows). So, I have a view. It's a simple view but with a lot of column. Looks like:</p>
  <pre><code>Select
         Column1,
         Column2,
         Column3,
         ...
         Column40
  From 
       Table1 INNER JOIN Table2
       ...
       Table7 INNER JOIN Table8
  </code></pre>
  <p>One of the columns(Lets's say Column3) has a heavy string series operations. View looks like:</p>
  <pre><code>Select
         Column1,
         Column2,
                      COALESCE(...
                   , ( SUBSTRING
                         ( LTRIM(RTRIM(....)))
                         , PatIndex('%[^0]%', LTRIM(RTRIM(...))
                         , PatIndex('%[^1]%', LTRIM(RTRIM(...))
                         , PatIndex('%[^2]%', LTRIM(RTRIM(...))
                         , PatIndex('%[^3]%', LTRIM(RTRIM(...))))
                         , len(LTRIM(RTRIM(...))))
                         , len(LTRIM(RTRIM(...))
                         , len(LTRIM(RTRIM(...))
                         )
                   )) Column3,
         ...
         Column40
  From 
       Table1 INNER JOIN Table2
       ...
       Table7 INNER JOIN Table8
  </code></pre>
  <p>So, when someone trying to select data from this view, it take a long time (like forever). This issues appears only when someone add Column3 in filter.</p>
  <p>I want to avoid this situation. So, I wanna ask you about ideas...My thoughts on this are to create a trigger and calculate this value at the time of insertion. Maybe there's another options?</p>